app, libgimp, pdb, plug-ins: allow pasting multiple full layers.

When a selection exists, we are copying then pasting the selection
contents. In particular, with multi-layer selection, it means pasting a
merged result of the selected layers (like a sample merged but limited
to selected layers).

Yet when no selection exists, with a single layer selected, a cut in
particular would remove the layer fully, then a paste would copy it
elsewhere (in the same image or even on a different image). This was
still working, but not with multiple layers. This is now fixed and we
can now copy/cut then paste several layers (without merge), which is
sometimes a very practical way to move layers (sometimes simpler than
drag'n drop, especially between images).

As a consequence, the PDB function gimp_edit_paste() now also returns an
array of layers (not a single layer).
This commit is contained in:
Jehan 2021-04-24 22:45:09 +02:00
parent 11e1f6ea5e
commit ef2402bf8e
10 changed files with 384 additions and 254 deletions

View File

@ -90,10 +90,10 @@ buffers_paste_cmd_callback (GimpAction *action,
{
GList *drawables = gimp_image_get_selected_drawables (image);
gimp_edit_paste (image,
g_list_length (drawables) == 1 ? drawables->data : NULL,
GIMP_OBJECT (buffer), paste_type,
x, y, width, height);
g_list_free (gimp_edit_paste (image,
g_list_length (drawables) == 1 ? drawables->data : NULL,
GIMP_OBJECT (buffer), paste_type,
x, y, width, height));
gimp_image_flush (image);
g_list_free (drawables);

View File

@ -236,11 +236,22 @@ edit_cut_cmd_callback (GimpAction *action,
GimpDisplay *display = action_data_get_display (data);
if (display)
gimp_message_literal (image->gimp,
G_OBJECT (display), GIMP_MESSAGE_INFO,
GIMP_IS_IMAGE (cut) ?
_("Cut layer to the clipboard.") :
_("Cut pixels to the clipboard."));
{
gchar *msg;
if (GIMP_IS_IMAGE (cut))
msg = g_strdup_printf (ngettext ("Cut layer to the clipboard.",
"Cut %d layers to the clipboard.",
g_list_length (drawables)),
g_list_length (drawables));
else
msg = g_strdup (_("Cut pixels to the clipboard."));
gimp_message_literal (image->gimp,
G_OBJECT (display), GIMP_MESSAGE_INFO,
msg);
g_free (msg);
}
gimp_image_flush (image);
}
@ -614,6 +625,7 @@ edit_paste (GimpDisplay *display,
GimpDisplayShell *shell = gimp_display_get_shell (display);
GList *drawables = gimp_image_get_selected_drawables (image);
GimpDrawable *drawable = NULL;
GList *pasted_layers;
gint x, y;
gint width, height;
@ -654,9 +666,11 @@ edit_paste (GimpDisplay *display,
! gimp_display_shell_get_infinite_canvas (shell),
&x, &y, &width, &height);
if (gimp_edit_paste (image, drawable, paste,
paste_type, x, y, width, height))
if ((pasted_layers = gimp_edit_paste (image, drawable, paste,
paste_type, x, y, width, height)))
{
gimp_image_set_selected_layers (image, pasted_layers);
g_list_free (pasted_layers);
gimp_image_flush (image);
}

View File

@ -61,35 +61,79 @@ gimp_edit_cut (GimpImage *image,
GimpContext *context,
GError **error)
{
GList *iter;
gboolean cut_layers = FALSE;
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
if (g_list_length (drawables) == 1 &&
GIMP_IS_LAYER (drawables->data) &&
gimp_channel_is_empty (gimp_image_get_mask (image)))
if (gimp_channel_is_empty (gimp_image_get_mask (image)))
{
cut_layers = TRUE;
for (iter = drawables; iter; iter = iter->next)
if (! GIMP_IS_LAYER (iter->data))
{
cut_layers = FALSE;
break;
}
}
if (cut_layers)
{
GList *remove = NULL;
GimpImage *clip_image;
gint off_x, off_y;
gchar *undo_label;
gimp_item_get_offset (GIMP_ITEM (drawables->data), &off_x, &off_y);
/* Let's work on a copy because we will edit the list to remove
* layers whose ancestor is also cut.
*/
drawables = g_list_copy (drawables);
for (iter = drawables; iter; iter = iter->next)
{
GList *iter2;
clip_image = gimp_image_new_from_drawable (image->gimp, drawables->data);
g_object_set_data (G_OBJECT (clip_image), "offset-x",
GINT_TO_POINTER (off_x));
g_object_set_data (G_OBJECT (clip_image), "offset-y",
GINT_TO_POINTER (off_y));
for (iter2 = drawables; iter2; iter2 = iter2->next)
{
if (iter2 == iter)
continue;
if (gimp_viewable_is_ancestor (iter2->data, iter->data))
{
/* When cutting a layer group, all its children come
* with anyway.
*/
remove = g_list_prepend (remove, iter);
break;
}
}
}
for (iter = remove; iter; iter = iter->next)
drawables = g_list_delete_link (drawables, iter->data);
g_list_free (remove);
/* Now copy all layers into the clipboard image. */
clip_image = gimp_image_new_from_drawables (image->gimp, drawables, FALSE);
gimp_container_remove (image->gimp->images, GIMP_OBJECT (clip_image));
gimp_set_clipboard_image (image->gimp, clip_image);
g_object_unref (clip_image);
undo_label = g_strdup_printf (ngettext ("Cut Layer", "Cut %d Layers",
g_list_length (drawables)),
g_list_length (drawables));
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_EDIT_CUT,
C_("undo-type", "Cut Layer"));
undo_label);
g_free (undo_label);
gimp_image_remove_layer (image, GIMP_LAYER (drawables->data),
TRUE, NULL);
/* Remove layers from source image. */
for (iter = drawables; iter; iter = iter->next)
gimp_image_remove_layer (image, GIMP_LAYER (iter->data),
TRUE, NULL);
gimp_image_undo_group_end (image);
g_list_free (drawables);
return GIMP_OBJECT (gimp_get_clipboard_image (image->gimp));
}
@ -138,23 +182,15 @@ gimp_edit_copy (GimpImage *image,
g_return_val_if_fail (g_list_length (drawables) == 1 || drawables_are_layers, NULL);
if (drawables_are_layers &&
gimp_channel_is_empty (gimp_image_get_mask (image)) &&
g_list_length (drawables) == 1)
gimp_channel_is_empty (gimp_image_get_mask (image)))
{
/* Special-casing the 1 layer with no selection case.
* It allows us to save the whole layer with all pixels as stored,
* not the rendered version of it.
*/
GimpImage *clip_image;
gint off_x, off_y;
gimp_item_get_offset (GIMP_ITEM (drawables->data), &off_x, &off_y);
clip_image = gimp_image_new_from_drawable (image->gimp, drawables->data);
g_object_set_data (G_OBJECT (clip_image), "offset-x",
GINT_TO_POINTER (off_x));
g_object_set_data (G_OBJECT (clip_image), "offset-y",
GINT_TO_POINTER (off_y));
clip_image = gimp_image_new_from_drawables (image->gimp, drawables, FALSE);
gimp_container_remove (image->gimp->images, GIMP_OBJECT (clip_image));
gimp_set_clipboard_image (image->gimp, clip_image);
g_object_unref (clip_image);
@ -260,13 +296,13 @@ gimp_edit_paste_is_floating (GimpPasteType paste_type)
g_return_val_if_reached (FALSE);
}
static GimpLayer *
gimp_edit_paste_get_layer (GimpImage *image,
GimpDrawable *drawable,
GimpObject *paste,
GimpPasteType *paste_type)
static GList *
gimp_edit_paste_get_layers (GimpImage *image,
GimpDrawable *drawable,
GimpObject *paste,
GimpPasteType *paste_type)
{
GimpLayer *layer = NULL;
GList *layers = NULL;
const Babl *floating_format;
/* change paste type to NEW_LAYER for cases where we can't attach a
@ -292,84 +328,101 @@ gimp_edit_paste_get_layer (GimpImage *image,
if (GIMP_IS_IMAGE (paste))
{
GType layer_type;
GList *iter;
layer = gimp_image_get_layer_iter (GIMP_IMAGE (paste))->data;
layers = g_list_copy (gimp_image_get_layer_iter (GIMP_IMAGE (paste)));
switch (*paste_type)
if (g_list_length (layers) > 1)
{
case GIMP_PASTE_TYPE_FLOATING:
case GIMP_PASTE_TYPE_FLOATING_IN_PLACE:
case GIMP_PASTE_TYPE_FLOATING_INTO:
case GIMP_PASTE_TYPE_FLOATING_INTO_IN_PLACE:
/* when pasting as floating make sure gimp_item_convert()
* will turn group layers into normal layers, otherwise use
* the same layer type so e.g. text information gets
* preserved. See issue #2667.
*/
if (GIMP_IS_GROUP_LAYER (layer))
layer_type = GIMP_TYPE_LAYER;
if (gimp_edit_paste_is_in_place (*paste_type))
*paste_type = GIMP_PASTE_TYPE_NEW_LAYER_IN_PLACE;
else
layer_type = G_TYPE_FROM_INSTANCE (layer);
break;
case GIMP_PASTE_TYPE_NEW_LAYER:
case GIMP_PASTE_TYPE_NEW_LAYER_IN_PLACE:
layer_type = G_TYPE_FROM_INSTANCE (layer);
break;
default:
g_return_val_if_reached (NULL);
*paste_type = GIMP_PASTE_TYPE_NEW_LAYER;
}
layer = GIMP_LAYER (gimp_item_convert (GIMP_ITEM (layer),
image, layer_type));
switch (*paste_type)
for (iter = layers; iter; iter = iter->next)
{
case GIMP_PASTE_TYPE_FLOATING:
case GIMP_PASTE_TYPE_FLOATING_IN_PLACE:
case GIMP_PASTE_TYPE_FLOATING_INTO:
case GIMP_PASTE_TYPE_FLOATING_INTO_IN_PLACE:
/* when pasting as floating selection, get rid of the layer mask,
* and make sure the layer has the right format
*/
if (gimp_layer_get_mask (layer))
gimp_layer_apply_mask (layer, GIMP_MASK_DISCARD, FALSE);
GType layer_type;
if (gimp_drawable_get_format (GIMP_DRAWABLE (layer)) !=
floating_format)
switch (*paste_type)
{
gimp_drawable_convert_type (GIMP_DRAWABLE (layer), image,
gimp_drawable_get_base_type (drawable),
gimp_drawable_get_precision (drawable),
TRUE,
NULL, NULL,
GEGL_DITHER_NONE, GEGL_DITHER_NONE,
FALSE, NULL);
}
break;
case GIMP_PASTE_TYPE_FLOATING:
case GIMP_PASTE_TYPE_FLOATING_IN_PLACE:
case GIMP_PASTE_TYPE_FLOATING_INTO:
case GIMP_PASTE_TYPE_FLOATING_INTO_IN_PLACE:
/* when pasting as floating make sure gimp_item_convert()
* will turn group layers into normal layers, otherwise use
* the same layer type so e.g. text information gets
* preserved. See issue #2667.
*/
if (GIMP_IS_GROUP_LAYER (iter->data))
layer_type = GIMP_TYPE_LAYER;
else
layer_type = G_TYPE_FROM_INSTANCE (iter->data);
break;
default:
break;
case GIMP_PASTE_TYPE_NEW_LAYER:
case GIMP_PASTE_TYPE_NEW_LAYER_IN_PLACE:
layer_type = G_TYPE_FROM_INSTANCE (iter->data);
break;
default:
g_return_val_if_reached (NULL);
}
iter->data = GIMP_LAYER (gimp_item_convert (GIMP_ITEM (iter->data),
image, layer_type));
switch (*paste_type)
{
case GIMP_PASTE_TYPE_FLOATING:
case GIMP_PASTE_TYPE_FLOATING_IN_PLACE:
case GIMP_PASTE_TYPE_FLOATING_INTO:
case GIMP_PASTE_TYPE_FLOATING_INTO_IN_PLACE:
/* when pasting as floating selection, get rid of the layer mask,
* and make sure the layer has the right format
*/
if (gimp_layer_get_mask (iter->data))
gimp_layer_apply_mask (iter->data, GIMP_MASK_DISCARD, FALSE);
if (gimp_drawable_get_format (GIMP_DRAWABLE (iter->data)) !=
floating_format)
{
gimp_drawable_convert_type (GIMP_DRAWABLE (iter->data), image,
gimp_drawable_get_base_type (drawable),
gimp_drawable_get_precision (drawable),
TRUE,
NULL, NULL,
GEGL_DITHER_NONE, GEGL_DITHER_NONE,
FALSE, NULL);
}
break;
default:
break;
}
}
}
else if (GIMP_IS_BUFFER (paste))
{
GimpLayer *layer;
layer = gimp_layer_new_from_buffer (GIMP_BUFFER (paste), image,
floating_format,
_("Pasted Layer"),
GIMP_OPACITY_OPAQUE,
gimp_image_get_default_new_layer_mode (image));
layers = g_list_prepend (layers, layer);
}
return layer;
return layers;
}
static void
gimp_edit_paste_get_viewport_offset (GimpImage *image,
GimpDrawable *drawable,
GimpObject *paste,
GList *pasted_layers,
gint viewport_x,
gint viewport_y,
gint viewport_width,
@ -377,24 +430,35 @@ gimp_edit_paste_get_viewport_offset (GimpImage *image,
gint *offset_x,
gint *offset_y)
{
GList *iter;
gint image_width;
gint image_height;
gint width;
gint height;
gint width = 0;
gint height = 0;
gboolean clamp_to_image = TRUE;
g_return_if_fail (GIMP_IS_IMAGE (image));
g_return_if_fail (drawable == NULL || GIMP_IS_DRAWABLE (drawable));
g_return_if_fail (drawable == NULL ||
gimp_item_is_attached (GIMP_ITEM (drawable)));
g_return_if_fail (GIMP_IS_VIEWABLE (paste));
g_return_if_fail (pasted_layers != NULL);
g_return_if_fail (offset_x != NULL);
g_return_if_fail (offset_y != NULL);
image_width = gimp_image_get_width (image);
image_height = gimp_image_get_height (image);
gimp_viewable_get_size (GIMP_VIEWABLE (paste), &width, &height);
for (iter = pasted_layers; iter; iter = iter->next)
{
gint layer_width;
gint layer_height;
g_return_if_fail (GIMP_IS_VIEWABLE (iter->data));
gimp_viewable_get_size (iter->data, &layer_width, &layer_height);
width = MAX (width, layer_width);
height = MAX (height, layer_height);
}
if (viewport_width == image_width &&
viewport_height == image_height)
@ -504,94 +568,71 @@ gimp_edit_paste_get_viewport_offset (GimpImage *image,
}
}
static void
gimp_edit_paste_get_paste_offset (GimpImage *image,
GimpDrawable *drawable,
GimpObject *paste,
gint *offset_x,
gint *offset_y)
{
g_return_if_fail (GIMP_IS_IMAGE (image));
g_return_if_fail (drawable == NULL || GIMP_IS_DRAWABLE (drawable));
g_return_if_fail (drawable == NULL ||
gimp_item_is_attached (GIMP_ITEM (drawable)));
g_return_if_fail (GIMP_IS_VIEWABLE (paste));
g_return_if_fail (offset_x != NULL);
g_return_if_fail (offset_y != NULL);
if (GIMP_IS_IMAGE (paste))
{
*offset_x = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (paste),
"offset-x"));
*offset_y = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (paste),
"offset-y"));
}
else if (GIMP_IS_BUFFER (paste))
{
GimpBuffer *buffer = GIMP_BUFFER (paste);
*offset_x = buffer->offset_x;
*offset_y = buffer->offset_y;
}
}
static GimpLayer *
static GList *
gimp_edit_paste_paste (GimpImage *image,
GimpDrawable *drawable,
GimpLayer *layer,
GList *layers,
GimpPasteType paste_type,
gboolean use_offset,
gint offset_x,
gint offset_y)
{
gimp_item_translate (GIMP_ITEM (layer), offset_x, offset_y, FALSE);
GList *iter;
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_EDIT_PASTE,
C_("undo-type", "Paste"));
switch (paste_type)
for (iter = layers; iter; iter = iter->next)
{
case GIMP_PASTE_TYPE_FLOATING:
case GIMP_PASTE_TYPE_FLOATING_IN_PLACE:
/* if there is a selection mask clear it - this might not
* always be desired, but in general, it seems like the correct
* behavior
*/
if (! gimp_channel_is_empty (gimp_image_get_mask (image)))
gimp_channel_clear (gimp_image_get_mask (image), NULL, TRUE);
/* Layers for in-place paste are already translated. */
if (use_offset)
gimp_item_translate (GIMP_ITEM (iter->data), offset_x, offset_y, FALSE);
/* fall thru */
switch (paste_type)
{
case GIMP_PASTE_TYPE_FLOATING:
case GIMP_PASTE_TYPE_FLOATING_IN_PLACE:
/* if there is a selection mask clear it - this might not
* always be desired, but in general, it seems like the correct
* behavior
*/
if (! gimp_channel_is_empty (gimp_image_get_mask (image)))
gimp_channel_clear (gimp_image_get_mask (image), NULL, TRUE);
case GIMP_PASTE_TYPE_FLOATING_INTO:
case GIMP_PASTE_TYPE_FLOATING_INTO_IN_PLACE:
floating_sel_attach (layer, drawable);
break;
/* fall thru */
case GIMP_PASTE_TYPE_NEW_LAYER:
case GIMP_PASTE_TYPE_NEW_LAYER_IN_PLACE:
{
GimpLayer *parent = NULL;
gint position = 0;
case GIMP_PASTE_TYPE_FLOATING_INTO:
case GIMP_PASTE_TYPE_FLOATING_INTO_IN_PLACE:
floating_sel_attach (iter->data, drawable);
break;
/* always add on top of a passed layer, where we would attach
* a floating selection
*/
if (GIMP_IS_LAYER (drawable))
{
parent = gimp_layer_get_parent (GIMP_LAYER (drawable));
position = gimp_item_get_index (GIMP_ITEM (drawable));
}
case GIMP_PASTE_TYPE_NEW_LAYER:
case GIMP_PASTE_TYPE_NEW_LAYER_IN_PLACE:
{
GimpLayer *parent = NULL;
gint position = 0;
gimp_image_add_layer (image, layer, parent, position, TRUE);
}
break;
/* always add on top of a passed layer, where we would attach
* a floating selection
*/
if (GIMP_IS_LAYER (drawable))
{
parent = gimp_layer_get_parent (GIMP_LAYER (drawable));
position = gimp_item_get_index (GIMP_ITEM (drawable));
}
gimp_image_add_layer (image, iter->data, parent, position, TRUE);
}
break;
}
}
gimp_image_undo_group_end (image);
return layer;
return layers;
}
GimpLayer *
GList *
gimp_edit_paste (GimpImage *image,
GimpDrawable *drawable,
GimpObject *paste,
@ -601,9 +642,10 @@ gimp_edit_paste (GimpImage *image,
gint viewport_width,
gint viewport_height)
{
GimpLayer *layer;
gint offset_x = 0;
gint offset_y = 0;
GList *layers;
gboolean use_offset = FALSE;
gint offset_x = 0;
gint offset_y = 0;
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
g_return_val_if_fail (drawable == NULL || GIMP_IS_DRAWABLE (drawable), NULL);
@ -611,20 +653,26 @@ gimp_edit_paste (GimpImage *image,
gimp_item_is_attached (GIMP_ITEM (drawable)), NULL);
g_return_val_if_fail (GIMP_IS_IMAGE (paste) || GIMP_IS_BUFFER (paste), NULL);
layer = gimp_edit_paste_get_layer (image, drawable, paste, &paste_type);
layers = gimp_edit_paste_get_layers (image, drawable, paste, &paste_type);
if (! layer)
if (! layers)
return NULL;
if (gimp_edit_paste_is_in_place (paste_type))
{
gimp_edit_paste_get_paste_offset (image, drawable, paste,
&offset_x,
&offset_y);
if (GIMP_IS_BUFFER (paste))
{
GimpBuffer *buffer = GIMP_BUFFER (paste);
use_offset = TRUE;
offset_x = buffer->offset_x;
offset_y = buffer->offset_y;
}
}
else
{
gimp_edit_paste_get_viewport_offset (image, drawable, GIMP_OBJECT (layer),
use_offset = TRUE;
gimp_edit_paste_get_viewport_offset (image, drawable, layers,
viewport_x,
viewport_y,
viewport_width,
@ -633,8 +681,8 @@ gimp_edit_paste (GimpImage *image,
&offset_y);
}
return gimp_edit_paste_paste (image, drawable, layer, paste_type,
offset_x, offset_y);
return gimp_edit_paste_paste (image, drawable, layers, paste_type,
use_offset, offset_x, offset_y);
}
GimpImage *

View File

@ -31,7 +31,7 @@ GimpBuffer * gimp_edit_copy_visible (GimpImage *image,
GimpContext *context,
GError **error);
GimpLayer * gimp_edit_paste (GimpImage *image,
GList * gimp_edit_paste (GimpImage *image,
GimpDrawable *drawable,
GimpObject *paste,
GimpPasteType paste_type,

View File

@ -517,8 +517,8 @@ gimp_display_shell_drop_buffer (GtkWidget *widget,
/* FIXME: popup a menu for selecting "Paste Into" */
gimp_edit_paste (image, drawable, GIMP_OBJECT (buffer),
paste_type, x, y, width, height);
g_list_free (gimp_edit_paste (image, drawable, GIMP_OBJECT (buffer),
paste_type, x, y, width, height));
gimp_display_shell_dnd_flush (shell, image);
}

View File

@ -249,7 +249,8 @@ edit_paste_invoker (GimpProcedure *procedure,
GimpValueArray *return_vals;
GimpDrawable *drawable;
gboolean paste_into;
GimpLayer *floating_sel = NULL;
gint num_layers = 0;
GimpLayer **layers = NULL;
drawable = g_value_get_object (gimp_value_array_index (args, 0));
paste_into = g_value_get_boolean (gimp_value_array_index (args, 1));
@ -263,15 +264,26 @@ edit_paste_invoker (GimpProcedure *procedure,
GIMP_PDB_ITEM_CONTENT, error) &&
gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
{
floating_sel = gimp_edit_paste (gimp_item_get_image (GIMP_ITEM (drawable)),
drawable, paste,
paste_into ?
GIMP_PASTE_TYPE_FLOATING_INTO :
GIMP_PASTE_TYPE_FLOATING,
-1, -1, -1, -1);
GList *list;
gint i;
if (! floating_sel)
list = gimp_edit_paste (gimp_item_get_image (GIMP_ITEM (drawable)),
drawable, paste,
paste_into ?
GIMP_PASTE_TYPE_FLOATING_INTO :
GIMP_PASTE_TYPE_FLOATING,
-1, -1, -1, -1);
if (! list)
success = FALSE;
num_layers = g_list_length (list);
layers = g_new (GimpLayer *, num_layers);
for (i = 0; i < num_layers; i++, list = g_list_next (list))
layers[i] = g_object_ref (list->data);
g_list_free (list);
}
else
success = FALSE;
@ -281,7 +293,10 @@ edit_paste_invoker (GimpProcedure *procedure,
error ? *error : NULL);
if (success)
g_value_set_object (gimp_value_array_index (return_vals, 1), floating_sel);
{
g_value_set_int (gimp_value_array_index (return_vals, 1), num_layers);
gimp_value_take_object_array (gimp_value_array_index (return_vals, 2), GIMP_TYPE_LAYER, (GObject **) layers, num_layers);
}
return return_vals;
}
@ -562,14 +577,20 @@ edit_named_paste_invoker (GimpProcedure *procedure,
GIMP_PDB_ITEM_CONTENT, error) &&
gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
{
floating_sel = gimp_edit_paste (gimp_item_get_image (GIMP_ITEM (drawable)),
drawable, GIMP_OBJECT (buffer),
paste_into ?
GIMP_PASTE_TYPE_FLOATING_INTO :
GIMP_PASTE_TYPE_FLOATING,
-1, -1, -1, -1);
if (! floating_sel)
GList *layers;
layers = gimp_edit_paste (gimp_item_get_image (GIMP_ITEM (drawable)),
drawable, GIMP_OBJECT (buffer),
paste_into ?
GIMP_PASTE_TYPE_FLOATING_INTO :
GIMP_PASTE_TYPE_FLOATING,
-1, -1, -1, -1);
if (! layers)
success = FALSE;
else
floating_sel = layers->data;
g_list_free (layers);
}
else
success = FALSE;
@ -735,7 +756,8 @@ register_edit_procs (GimpPDB *pdb)
"gimp-edit-paste");
gimp_procedure_set_static_help (procedure,
"Paste buffer to the specified drawable.",
"This procedure pastes a copy of the internal GIMP edit buffer to the specified drawable. The GIMP edit buffer will be empty unless a call was previously made to either 'gimp-edit-cut' or 'gimp-edit-copy'. The \"paste_into\" option specifies whether to clear the current image selection, or to paste the buffer \"behind\" the selection. This allows the selection to act as a mask for the pasted buffer. Anywhere that the selection mask is non-zero, the pasted buffer will show through. The pasted buffer will be a new layer in the image which is designated as the image floating selection. If the image has a floating selection at the time of pasting, the old floating selection will be anchored to its drawable before the new floating selection is added. This procedure returns the new floating layer. The resulting floating selection will already be attached to the specified drawable, and a subsequent call to floating_sel_attach is not needed.",
"This procedure pastes a copy of the internal GIMP edit buffer to the specified drawable. The GIMP edit buffer will be empty unless a call was previously made to either 'gimp-edit-cut' or 'gimp-edit-copy'. The \"paste_into\" option specifies whether to clear the current image selection, or to paste the buffer \"behind\" the selection. This allows the selection to act as a mask for the pasted buffer. Anywhere that the selection mask is non-zero, the pasted buffer will show through. The pasted data may be a floating selection when relevant, layers otherwise. If the image has a floating selection at the time of pasting, the old floating selection will be anchored to its drawable before the new floating selection is added.\n"
"This procedure returns the new layers (floating or not). If the result is a floating selection, it will already be attached to the specified drawable, and a subsequent call to floating_sel_attach is not needed.",
NULL);
gimp_procedure_set_static_attribution (procedure,
"Spencer Kimball & Peter Mattis",
@ -754,11 +776,17 @@ register_edit_procs (GimpPDB *pdb)
FALSE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
gimp_param_spec_layer ("floating-sel",
"floating sel",
"The new floating selection",
FALSE,
GIMP_PARAM_READWRITE));
g_param_spec_int ("num-layers",
"num layers",
"The newly pasted layers",
0, G_MAXINT32, 0,
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
gimp_param_spec_object_array ("layers",
"layers",
"The list of pasted layers.",
GIMP_TYPE_LAYER,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);

View File

@ -170,6 +170,7 @@ gimp_edit_copy_visible (GimpImage *image)
* gimp_edit_paste:
* @drawable: The drawable to paste to.
* @paste_into: Clear selection, or paste behind it?
* @num_layers: (out): The newly pasted layers.
*
* Paste buffer to the specified drawable.
*
@ -180,24 +181,27 @@ gimp_edit_copy_visible (GimpImage *image)
* image selection, or to paste the buffer \"behind\" the selection.
* This allows the selection to act as a mask for the pasted buffer.
* Anywhere that the selection mask is non-zero, the pasted buffer will
* show through. The pasted buffer will be a new layer in the image
* which is designated as the image floating selection. If the image
* has a floating selection at the time of pasting, the old floating
* selection will be anchored to its drawable before the new floating
* selection is added. This procedure returns the new floating layer.
* The resulting floating selection will already be attached to the
* show through. The pasted data may be a floating selection when
* relevant, layers otherwise. If the image has a floating selection at
* the time of pasting, the old floating selection will be anchored to
* its drawable before the new floating selection is added.
* This procedure returns the new layers (floating or not). If the
* result is a floating selection, it will already be attached to the
* specified drawable, and a subsequent call to floating_sel_attach is
* not needed.
*
* Returns: (transfer none): The new floating selection.
* Returns: (array length=num_layers) (element-type GimpLayer) (transfer container):
* The list of pasted layers.
* The returned value must be freed with g_free().
**/
GimpLayer *
GimpLayer **
gimp_edit_paste (GimpDrawable *drawable,
gboolean paste_into)
gboolean paste_into,
gint *num_layers)
{
GimpValueArray *args;
GimpValueArray *return_vals;
GimpLayer *floating_sel = NULL;
GimpLayer **layers = NULL;
args = gimp_value_array_new_from_types (NULL,
GIMP_TYPE_DRAWABLE, drawable,
@ -209,12 +213,17 @@ gimp_edit_paste (GimpDrawable *drawable,
args);
gimp_value_array_unref (args);
*num_layers = 0;
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
floating_sel = GIMP_VALUES_GET_LAYER (return_vals, 1);
{
*num_layers = GIMP_VALUES_GET_INT (return_vals, 1);
{ GimpObjectArray *a = g_value_get_boxed (gimp_value_array_index (return_vals, 2)); if (a) layers = g_memdup (a->data, a->length * sizeof (gpointer)); };
}
gimp_value_array_unref (return_vals);
return floating_sel;
return layers;
}
/**

View File

@ -32,26 +32,27 @@ G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
gboolean gimp_edit_cut (gint num_drawables,
const GimpItem **drawables);
gboolean gimp_edit_copy (gint num_drawables,
const GimpItem **drawables);
gboolean gimp_edit_copy_visible (GimpImage *image);
GimpLayer* gimp_edit_paste (GimpDrawable *drawable,
gboolean paste_into);
GimpImage* gimp_edit_paste_as_new_image (void);
gchar* gimp_edit_named_cut (gint num_drawables,
const GimpItem **drawables,
const gchar *buffer_name);
gchar* gimp_edit_named_copy (gint num_drawables,
const GimpItem **drawables,
const gchar *buffer_name);
gchar* gimp_edit_named_copy_visible (GimpImage *image,
const gchar *buffer_name);
GimpLayer* gimp_edit_named_paste (GimpDrawable *drawable,
const gchar *buffer_name,
gboolean paste_into);
GimpImage* gimp_edit_named_paste_as_new_image (const gchar *buffer_name);
gboolean gimp_edit_cut (gint num_drawables,
const GimpItem **drawables);
gboolean gimp_edit_copy (gint num_drawables,
const GimpItem **drawables);
gboolean gimp_edit_copy_visible (GimpImage *image);
GimpLayer** gimp_edit_paste (GimpDrawable *drawable,
gboolean paste_into,
gint *num_layers);
GimpImage* gimp_edit_paste_as_new_image (void);
gchar* gimp_edit_named_cut (gint num_drawables,
const GimpItem **drawables,
const gchar *buffer_name);
gchar* gimp_edit_named_copy (gint num_drawables,
const GimpItem **drawables,
const gchar *buffer_name);
gchar* gimp_edit_named_copy_visible (GimpImage *image,
const gchar *buffer_name);
GimpLayer* gimp_edit_named_paste (GimpDrawable *drawable,
const gchar *buffer_name,
gboolean paste_into);
GimpImage* gimp_edit_named_paste_as_new_image (const gchar *buffer_name);
G_END_DECLS

View File

@ -238,13 +238,15 @@ was previously made to either gimp_edit_cut() or gimp_edit_copy(). The
selection, or to paste the buffer "behind" the selection. This allows
the selection to act as a mask for the pasted buffer. Anywhere that
the selection mask is non-zero, the pasted buffer will show
through. The pasted buffer will be a new layer in the image which is
designated as the image floating selection. If the image has a
floating selection at the time of pasting, the old floating selection
will be anchored to its drawable before the new floating selection is
added. This procedure returns the new floating layer. The resulting
floating selection will already be attached to the specified drawable,
and a subsequent call to floating_sel_attach is not needed.
through.
The pasted data may be a floating selection when relevant, layers otherwise.
If the image has a floating selection at the time of pasting, the old
floating selection will be anchored to its drawable before the new
floating selection is added.
This procedure returns the new layers (floating or not). If the result
is a floating selection, it will already be attached to the specified
drawable, and a subsequent call to floating_sel_attach is not needed.
HELP
&std_pdb_misc;
@ -257,8 +259,10 @@ HELP
);
@outargs = (
{ name => 'floating_sel', type => 'layer',
desc => 'The new floating selection' }
{ name => 'layers', type => 'layerarray',
desc => 'The list of pasted layers.',
array => { name => 'num_layers',
desc => 'The newly pasted layers' } }
);
%invoke = (
@ -271,15 +275,26 @@ HELP
GIMP_PDB_ITEM_CONTENT, error) &&
gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
{
floating_sel = gimp_edit_paste (gimp_item_get_image (GIMP_ITEM (drawable)),
drawable, paste,
paste_into ?
GIMP_PASTE_TYPE_FLOATING_INTO :
GIMP_PASTE_TYPE_FLOATING,
-1, -1, -1, -1);
GList *list;
gint i;
if (! floating_sel)
list = gimp_edit_paste (gimp_item_get_image (GIMP_ITEM (drawable)),
drawable, paste,
paste_into ?
GIMP_PASTE_TYPE_FLOATING_INTO :
GIMP_PASTE_TYPE_FLOATING,
-1, -1, -1, -1);
if (! list)
success = FALSE;
num_layers = g_list_length (list);
layers = g_new (GimpLayer *, num_layers);
for (i = 0; i < num_layers; i++, list = g_list_next (list))
layers[i] = g_object_ref (list->data);
g_list_free (list);
}
else
success = FALSE;
@ -583,14 +598,20 @@ HELP
GIMP_PDB_ITEM_CONTENT, error) &&
gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
{
floating_sel = gimp_edit_paste (gimp_item_get_image (GIMP_ITEM (drawable)),
drawable, GIMP_OBJECT (buffer),
paste_into ?
GIMP_PASTE_TYPE_FLOATING_INTO :
GIMP_PASTE_TYPE_FLOATING,
-1, -1, -1, -1);
if (! floating_sel)
GList *layers;
layers = gimp_edit_paste (gimp_item_get_image (GIMP_ITEM (drawable)),
drawable, GIMP_OBJECT (buffer),
paste_into ?
GIMP_PASTE_TYPE_FLOATING_INTO :
GIMP_PASTE_TYPE_FLOATING,
-1, -1, -1, -1);
if (! layers)
success = FALSE;
else
floating_sel = layers->data;
g_list_free (layers);
}
else
success = FALSE;

View File

@ -625,7 +625,16 @@ p_if_selection_float_it (GimpImage *image,
the selection */
if (gimp_edit_copy (1, (const GimpItem **) &layer))
{
layer = gimp_edit_paste (GIMP_DRAWABLE (layer), FALSE);
GimpLayer **layers;
gint num_layers;
layers = gimp_edit_paste (GIMP_DRAWABLE (layer), FALSE, &num_layers);
/* Since we explicitly copied a single layer, there should
* be no more than a single layer in the paste as well.
*/
layer = num_layers ? layers[0] : NULL;
g_free (layers);
}
else
{