app: fix paste-in-place when pasting over a layer group/locked item

When pasting in place over a layer group or a content-locked item,
change the paste type to NEW_LAYER_IN_PLACE, rather than NEW_LAYER,
so that the new layer is still pasted in the right location.

Additionally, avoid showing the "Pasted as new layer because ..."
message when pasting over a layer group or a content-locked item,
when the paste type is NEW_LAYER[_IN_PLACE] to begin with.
This commit is contained in:
Ell 2018-03-24 12:43:30 -04:00
parent 888baac9c8
commit 8f07d76786
2 changed files with 35 additions and 19 deletions

View File

@ -560,7 +560,9 @@ edit_paste (GimpDisplay *display,
gint x, y; gint x, y;
gint width, height; gint width, height;
if (drawable) if (drawable &&
paste_type != GIMP_PASTE_TYPE_NEW_LAYER &&
paste_type != GIMP_PASTE_TYPE_NEW_LAYER_IN_PLACE)
{ {
if (gimp_viewable_get_children (GIMP_VIEWABLE (drawable))) if (gimp_viewable_get_children (GIMP_VIEWABLE (drawable)))
{ {
@ -568,8 +570,6 @@ edit_paste (GimpDisplay *display,
GIMP_MESSAGE_INFO, GIMP_MESSAGE_INFO,
_("Pasted as new layer because the " _("Pasted as new layer because the "
"target is a layer group.")); "target is a layer group."));
paste_type = GIMP_PASTE_TYPE_NEW_LAYER;
} }
else if (gimp_item_is_content_locked (GIMP_ITEM (drawable))) else if (gimp_item_is_content_locked (GIMP_ITEM (drawable)))
{ {
@ -577,9 +577,9 @@ edit_paste (GimpDisplay *display,
GIMP_MESSAGE_INFO, GIMP_MESSAGE_INFO,
_("Pasted as new layer because the " _("Pasted as new layer because the "
"target's pixels are locked.")); "target's pixels are locked."));
paste_type = GIMP_PASTE_TYPE_NEW_LAYER;
} }
/* the actual paste-type conversion happens in gimp_edit_paste() */
} }
gimp_display_shell_untransform_viewport (shell, &x, &y, &width, &height); gimp_display_shell_untransform_viewport (shell, &x, &y, &width, &height);

View File

@ -197,6 +197,25 @@ gimp_edit_copy_visible (GimpImage *image,
return NULL; return NULL;
} }
static gboolean
gimp_edit_paste_is_in_place (GimpPasteType paste_type)
{
switch (paste_type)
{
case GIMP_PASTE_TYPE_FLOATING:
case GIMP_PASTE_TYPE_FLOATING_INTO:
case GIMP_PASTE_TYPE_NEW_LAYER:
return FALSE;
case GIMP_PASTE_TYPE_FLOATING_IN_PLACE:
case GIMP_PASTE_TYPE_FLOATING_INTO_IN_PLACE:
case GIMP_PASTE_TYPE_NEW_LAYER_IN_PLACE:
return TRUE;
}
g_return_val_if_reached (FALSE);
}
static GimpLayer * static GimpLayer *
gimp_edit_paste_get_layer (GimpImage *image, gimp_edit_paste_get_layer (GimpImage *image,
GimpDrawable *drawable, GimpDrawable *drawable,
@ -213,6 +232,9 @@ gimp_edit_paste_get_layer (GimpImage *image,
gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) || gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) ||
gimp_item_is_content_locked (GIMP_ITEM (drawable))) gimp_item_is_content_locked (GIMP_ITEM (drawable)))
{ {
if (gimp_edit_paste_is_in_place (*paste_type))
*paste_type = GIMP_PASTE_TYPE_NEW_LAYER_IN_PLACE;
else
*paste_type = GIMP_PASTE_TYPE_NEW_LAYER; *paste_type = GIMP_PASTE_TYPE_NEW_LAYER;
} }
@ -546,11 +568,14 @@ gimp_edit_paste (GimpImage *image,
if (! layer) if (! layer)
return NULL; return NULL;
switch (paste_type) if (gimp_edit_paste_is_in_place (paste_type))
{
gimp_edit_paste_get_paste_offset (image, drawable, paste,
&offset_x,
&offset_y);
}
else
{ {
case GIMP_PASTE_TYPE_FLOATING:
case GIMP_PASTE_TYPE_FLOATING_INTO:
case GIMP_PASTE_TYPE_NEW_LAYER:
gimp_edit_paste_get_viewport_offset (image, drawable, GIMP_OBJECT (layer), gimp_edit_paste_get_viewport_offset (image, drawable, GIMP_OBJECT (layer),
viewport_x, viewport_x,
viewport_y, viewport_y,
@ -558,15 +583,6 @@ gimp_edit_paste (GimpImage *image,
viewport_height, viewport_height,
&offset_x, &offset_x,
&offset_y); &offset_y);
break;
case GIMP_PASTE_TYPE_FLOATING_IN_PLACE:
case GIMP_PASTE_TYPE_FLOATING_INTO_IN_PLACE:
case GIMP_PASTE_TYPE_NEW_LAYER_IN_PLACE:
gimp_edit_paste_get_paste_offset (image, drawable, paste,
&offset_x,
&offset_y);
break;
} }
return gimp_edit_paste_paste (image, drawable, layer, paste_type, return gimp_edit_paste_paste (image, drawable, layer, paste_type,