static void gimp_floating_sel_undo_pop (GimpUndo *undo, GimpUndoMode undo_mode, GimpUndoAccumulator *accum) { GimpFloatingSelUndo *floating_sel_undo = GIMP_FLOATING_SEL_UNDO (undo); GimpLayer *floating_layer = GIMP_LAYER (GIMP_ITEM_UNDO (undo)->item); GIMP_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum); switch (undo->undo_type) { case GIMP_UNDO_FS_TO_LAYER: if (undo_mode == GIMP_UNDO_MODE_UNDO) { /* Update the preview for the floating sel */ gimp_viewable_invalidate_preview (GIMP_VIEWABLE (floating_layer)); gimp_layer_set_floating_sel_drawable (floating_layer, floating_sel_undo->drawable); gimp_image_set_active_layer (undo->image, floating_layer); gimp_drawable_attach_floating_sel (gimp_layer_get_floating_sel_drawable (floating_layer), floating_layer); } else { gimp_drawable_detach_floating_sel (gimp_layer_get_floating_sel_drawable (floating_layer)); gimp_layer_set_floating_sel_drawable (floating_layer, NULL); } /* When the floating selection is converted to/from a normal * layer it does something resembling a name change, so emit the * "name-changed" signal */ gimp_object_name_changed (GIMP_OBJECT (floating_layer)); gimp_drawable_update (GIMP_DRAWABLE (floating_layer), 0, 0, gimp_item_get_width (GIMP_ITEM (floating_layer)), gimp_item_get_height (GIMP_ITEM (floating_layer))); break; default: g_assert_not_reached (); } }
gboolean floating_sel_to_layer (GimpLayer *layer, GError **error) { GimpItem *item; GimpImage *image; g_return_val_if_fail (GIMP_IS_LAYER (layer), FALSE); g_return_val_if_fail (gimp_layer_is_floating_sel (layer), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); item = GIMP_ITEM (layer); image = gimp_item_get_image (item); /* Check if the floating layer belongs to a channel */ if (GIMP_IS_CHANNEL (gimp_layer_get_floating_sel_drawable (layer))) { g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED, _("Cannot create a new layer from the floating " "selection because it belongs to a layer mask " "or channel.")); return FALSE; } gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_FS_TO_LAYER, C_("undo-type", "Floating Selection to Layer")); gimp_image_undo_push_fs_to_layer (image, NULL, layer); gimp_drawable_detach_floating_sel (gimp_layer_get_floating_sel_drawable (layer)); gimp_layer_set_floating_sel_drawable (layer, NULL); gimp_item_set_visible (item, TRUE, TRUE); gimp_layer_set_lock_alpha (layer, FALSE, TRUE); gimp_image_undo_group_end (image); /* When the floating selection is converted to/from a normal layer * it does something resembling a name change, so emit the * "name-changed" signal */ gimp_object_name_changed (GIMP_OBJECT (layer)); gimp_drawable_update (GIMP_DRAWABLE (layer), 0, 0, gimp_item_get_width (item), gimp_item_get_height (item)); return TRUE; }
void floating_sel_attach (GimpLayer *layer, GimpDrawable *drawable) { GimpImage *image; GimpLayer *floating_sel; g_return_if_fail (GIMP_IS_LAYER (layer)); g_return_if_fail (GIMP_IS_DRAWABLE (drawable)); g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable))); g_return_if_fail (drawable != GIMP_DRAWABLE (layer)); g_return_if_fail (gimp_item_get_image (GIMP_ITEM (layer)) == gimp_item_get_image (GIMP_ITEM (drawable))); image = gimp_item_get_image (GIMP_ITEM (drawable)); floating_sel = gimp_image_get_floating_selection (image); /* If there is already a floating selection, anchor it */ if (floating_sel) { floating_sel_anchor (floating_sel); /* if we were pasting to the old floating selection, paste now * to the drawable */ if (drawable == (GimpDrawable *) floating_sel) drawable = gimp_image_get_active_drawable (image); } gimp_layer_set_lock_alpha (layer, TRUE, FALSE); gimp_layer_set_floating_sel_drawable (layer, drawable); gimp_image_add_layer (image, layer, NULL, 0, TRUE); }