From 8f07d76786cbc898fa18d75d688de564ac99e149 Mon Sep 17 00:00:00 2001 From: Ell Date: Sat, 24 Mar 2018 12:43:30 -0400 Subject: [PATCH] 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. --- app/actions/edit-commands.c | 10 ++++----- app/core/gimp-edit.c | 44 +++++++++++++++++++++++++------------ 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/app/actions/edit-commands.c b/app/actions/edit-commands.c index 9959c635bc..0c6d75d5b7 100644 --- a/app/actions/edit-commands.c +++ b/app/actions/edit-commands.c @@ -560,7 +560,9 @@ edit_paste (GimpDisplay *display, gint x, y; 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))) { @@ -568,8 +570,6 @@ edit_paste (GimpDisplay *display, GIMP_MESSAGE_INFO, _("Pasted as new layer because the " "target is a layer group.")); - - paste_type = GIMP_PASTE_TYPE_NEW_LAYER; } else if (gimp_item_is_content_locked (GIMP_ITEM (drawable))) { @@ -577,9 +577,9 @@ edit_paste (GimpDisplay *display, GIMP_MESSAGE_INFO, _("Pasted as new layer because the " "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); diff --git a/app/core/gimp-edit.c b/app/core/gimp-edit.c index 6591d36cec..36662a624d 100644 --- a/app/core/gimp-edit.c +++ b/app/core/gimp-edit.c @@ -197,6 +197,25 @@ gimp_edit_copy_visible (GimpImage *image, 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 * gimp_edit_paste_get_layer (GimpImage *image, GimpDrawable *drawable, @@ -213,7 +232,10 @@ gimp_edit_paste_get_layer (GimpImage *image, gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) || gimp_item_is_content_locked (GIMP_ITEM (drawable))) { - *paste_type = GIMP_PASTE_TYPE_NEW_LAYER; + 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; } /* floating pastes always have the pasted-to drawable's format with @@ -546,11 +568,14 @@ gimp_edit_paste (GimpImage *image, if (! layer) 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), viewport_x, viewport_y, @@ -558,15 +583,6 @@ gimp_edit_paste (GimpImage *image, viewport_height, &offset_x, &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, -- GitLab