[gimp] app: layers-resize-to-image action multi-layer aware.



commit 5565a6a3892bd02ab25a50049bf5b35ef48dc5f7
Author: Jehan <jehan girinstud io>
Date:   Wed Jul 1 01:00:48 2020 +0200

    app: layers-resize-to-image action multi-layer aware.

 app/actions/layers-actions.c  | 17 +++++++++++++----
 app/actions/layers-commands.c | 19 ++++++++++++++-----
 2 files changed, 27 insertions(+), 9 deletions(-)
---
diff --git a/app/actions/layers-actions.c b/app/actions/layers-actions.c
index f44463f7d7..053d4b850f 100644
--- a/app/actions/layers-actions.c
+++ b/app/actions/layers-actions.c
@@ -235,8 +235,8 @@ static const GimpActionEntry layers_actions[] =
     GIMP_HELP_LAYER_RESIZE },
 
   { "layers-resize-to-image", GIMP_ICON_LAYER_TO_IMAGESIZE,
-    NC_("layers-action", "Layer to _Image Size"), NULL,
-    NC_("layers-action", "Resize the layer to the size of the image"),
+    NC_("layers-action", "Layers to _Image Size"), NULL,
+    NC_("layers-action", "Resize the layers to the size of the image"),
     layers_resize_to_image_cmd_callback,
     GIMP_HELP_LAYER_RESIZE_TO_IMAGE },
 
@@ -797,6 +797,8 @@ layers_actions_update (GimpActionGroup *group,
   gboolean       all_next_visible   = TRUE;
   gboolean       all_masks_shown    = TRUE;
   gboolean       all_masks_disabled = TRUE;
+  gboolean       all_writable       = TRUE;
+  gboolean       all_movable        = TRUE;
 
   gint           n_layers       = 0;
 
@@ -843,6 +845,11 @@ layers_actions_update (GimpActionGroup *group,
 
           if (! gimp_item_is_content_locked (GIMP_ITEM (iter->data)))
             have_writable = TRUE;
+          else
+            all_writable  = FALSE;
+
+          if (gimp_item_is_position_locked (GIMP_ITEM (iter->data)))
+            all_movable = FALSE;
 
           if (gimp_layer_can_lock_alpha (iter->data))
             {
@@ -913,7 +920,9 @@ layers_actions_update (GimpActionGroup *group,
 
           if (have_masks && have_no_masks            &&
               have_groups && have_no_groups          &&
-              have_writable && ! all_masks_shown     &&
+              have_writable && ! all_writable        &&
+              ! all_movable                          &&
+              ! all_masks_shown                      &&
               ! all_masks_disabled                   &&
               ! lock_alpha && can_lock_alpha         &&
               ! prev_mode && ! next_mode             &&
@@ -1049,7 +1058,7 @@ layers_actions_update (GimpActionGroup *group,
   SET_VISIBLE   ("layers-text-along-vectors", text_layer && !ac);
 
   SET_SENSITIVE ("layers-resize",          writable && movable && !ac);
-  SET_SENSITIVE ("layers-resize-to-image", writable && movable && !ac);
+  SET_SENSITIVE ("layers-resize-to-image", all_writable && all_movable && !ac);
   SET_SENSITIVE ("layers-scale",           writable && movable && !ac);
 
   SET_SENSITIVE ("layers-crop-to-selection", writable && movable && sel);
diff --git a/app/actions/layers-commands.c b/app/actions/layers-commands.c
index 0df6cec1e9..f6b9a8985f 100644
--- a/app/actions/layers-commands.c
+++ b/app/actions/layers-commands.c
@@ -1107,12 +1107,21 @@ layers_resize_to_image_cmd_callback (GimpAction *action,
                                      gpointer    data)
 {
   GimpImage *image;
-  GimpLayer *layer;
-  return_if_no_layer (image, layer, data);
+  GList     *layers;
+  GList     *iter;
+  return_if_no_layers (image, layers, data);
+
+  if (g_list_length (layers) > 1)
+    gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_ITEM_RESIZE,
+                                 _("Layers to Image Size"));
+  for (iter = layers; iter; iter = iter->next)
+    gimp_layer_resize_to_image (iter->data,
+                                action_data_get_context (data),
+                                GIMP_FILL_TRANSPARENT);
+
+  if (g_list_length (layers) > 1)
+    gimp_image_undo_group_end (image);
 
-  gimp_layer_resize_to_image (layer,
-                              action_data_get_context (data),
-                              GIMP_FILL_TRANSPARENT);
   gimp_image_flush (image);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]