[gimp] app, pdb: plug-in-autocrop-layer() multi-layer aware.



commit 3f9184f5765aed32899e3c59ec5701adef8e3393
Author: Jehan <jehan girinstud io>
Date:   Wed Apr 21 00:13:24 2021 +0200

    app, pdb: plug-in-autocrop-layer() multi-layer aware.
    
    This PDB procedure will now crop all selected layers relatively to the
    input drawable.

 app/pdb/plug-in-compat-cmds.c | 26 +++++++++++++++++---------
 pdb/groups/plug_in_compat.pdb | 28 ++++++++++++++++++----------
 2 files changed, 35 insertions(+), 19 deletions(-)
---
diff --git a/app/pdb/plug-in-compat-cmds.c b/app/pdb/plug-in-compat-cmds.c
index 4362a1d1a3..a27e863a2a 100644
--- a/app/pdb/plug-in-compat-cmds.c
+++ b/app/pdb/plug-in-compat-cmds.c
@@ -714,10 +714,11 @@ plug_in_autocrop_layer_invoker (GimpProcedure         *procedure,
       if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
                                      GIMP_PDB_ITEM_CONTENT, error))
         {
-          GimpLayer *layer = gimp_image_get_active_layer (image);
-          gint       x, y, width, height;
+          GList *layers = gimp_image_get_selected_layers (image);
+          GList *iter;
+          gint   x, y, width, height;
 
-          if (layer)
+          if (layers)
             {
               switch (gimp_pickable_auto_shrink (GIMP_PICKABLE (drawable),
                                                  0, 0,
@@ -729,9 +730,10 @@ plug_in_autocrop_layer_invoker (GimpProcedure         *procedure,
                   gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_ITEM_RESIZE,
                                                _("Autocrop layer"));
 
-                  gimp_item_resize (GIMP_ITEM (layer),
-                                    context, GIMP_FILL_TRANSPARENT,
-                                    width, height, -x, -y);
+                  for (iter = layers; iter; iter = iter->next)
+                      gimp_item_resize (GIMP_ITEM (iter->data),
+                                        context, GIMP_FILL_TRANSPARENT,
+                                        width, height, -x, -y);
 
                   gimp_image_undo_group_end (image);
                   break;
@@ -740,9 +742,15 @@ plug_in_autocrop_layer_invoker (GimpProcedure         *procedure,
                   break;
                 }
             }
+          else
+            {
+              success = FALSE;
+            }
         }
       else
-        success = FALSE;
+        {
+          success = FALSE;
+        }
     }
 
   return gimp_procedure_get_return_values (procedure, success,
@@ -5103,8 +5111,8 @@ register_plug_in_compat_procs (GimpPDB *pdb)
   gimp_object_set_static_name (GIMP_OBJECT (procedure),
                                "plug-in-autocrop-layer");
   gimp_procedure_set_static_help (procedure,
-                                  "Crop the active layer based on empty borders of the input drawable",
-                                  "Crop the active layer of the input \"image\" based on empty borders of 
the input \"drawable\". \n\nThe input drawable serves as a base for detecting cropping extents (transparency 
or background color), and is not necessarily the cropped layer (the current active layer).",
+                                  "Crop the selected layers based on empty borders of the input drawable",
+                                  "Crop the selected layers of the input \"image\" based on empty borders of 
the input \"drawable\". \n\nThe input drawable serves as a base for detecting cropping extents (transparency 
or background color), and is not necessarily among the cropped layers (the current selected layers).",
                                   NULL);
   gimp_procedure_set_static_attribution (procedure,
                                          "Spencer Kimball & Peter Mattis",
diff --git a/pdb/groups/plug_in_compat.pdb b/pdb/groups/plug_in_compat.pdb
index 2c14874fd0..cceb3e79fe 100644
--- a/pdb/groups/plug_in_compat.pdb
+++ b/pdb/groups/plug_in_compat.pdb
@@ -317,11 +317,11 @@ CODE
 }
 
 sub plug_in_autocrop_layer {
-    $blurb = 'Crop the active layer based on empty borders of the input drawable';
+    $blurb = 'Crop the selected layers based on empty borders of the input drawable';
 
     $help = <<'HELP';
-Crop the active layer of the input "image" based on empty borders of the input "drawable".
-\n\nThe input drawable serves as a base for detecting cropping extents (transparency or background color), 
and is not necessarily the cropped layer (the current active layer).
+Crop the selected layers of the input "image" based on empty borders of the input "drawable".
+\n\nThe input drawable serves as a base for detecting cropping extents (transparency or background color), 
and is not necessarily among the cropped layers (the current selected layers).
 HELP
 
     &std_pdb_misc;
@@ -342,10 +342,11 @@ HELP
   if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
                                  GIMP_PDB_ITEM_CONTENT, error))
     {
-      GimpLayer *layer = gimp_image_get_active_layer (image);
-      gint       x, y, width, height;
+      GList *layers = gimp_image_get_selected_layers (image);
+      GList *iter;
+      gint   x, y, width, height;
 
-      if (layer)
+      if (layers)
         {
           switch (gimp_pickable_auto_shrink (GIMP_PICKABLE (drawable),
                                              0, 0,
@@ -357,9 +358,10 @@ HELP
               gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_ITEM_RESIZE,
                                            _("Autocrop layer"));
 
-              gimp_item_resize (GIMP_ITEM (layer),
-                                context, GIMP_FILL_TRANSPARENT,
-                                width, height, -x, -y);
+              for (iter = layers; iter; iter = iter->next)
+                  gimp_item_resize (GIMP_ITEM (iter->data),
+                                    context, GIMP_FILL_TRANSPARENT,
+                                    width, height, -x, -y);
 
               gimp_image_undo_group_end (image);
              break;
@@ -368,9 +370,15 @@ HELP
              break;
             }
        }
+      else
+        {
+          success = FALSE;
+        }
     }
   else
-    success = FALSE;
+    {
+      success = FALSE;
+    }
 }
 CODE
     );


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