[gimp] app: "layers-mask-selection-*" multi-layers aware.



commit 338ac504df5b508ba6021ff349e728399c168703
Author: Jehan <jehan girinstud io>
Date:   Wed May 20 22:59:34 2020 +0200

    app: "layers-mask-selection-*" multi-layers aware.
    
    All selected layers' masks are combined first as union, then the result
    is combined with the image selection according to requested boolean
    operation.
    Also use new gimp_channel_combine_items() function.

 app/actions/layers-actions.c  | 24 ++++++++++++------------
 app/actions/layers-commands.c | 39 ++++++++++++++++++++++++++++++++-------
 2 files changed, 44 insertions(+), 19 deletions(-)
---
diff --git a/app/actions/layers-actions.c b/app/actions/layers-actions.c
index 0424215e23..cf047638aa 100644
--- a/app/actions/layers-actions.c
+++ b/app/actions/layers-actions.c
@@ -500,26 +500,26 @@ static const GimpEnumActionEntry layers_mask_apply_actions[] =
 static const GimpEnumActionEntry layers_mask_to_selection_actions[] =
 {
   { "layers-mask-selection-replace", GIMP_ICON_SELECTION_REPLACE,
-    NC_("layers-action", "_Mask to Selection"), NULL,
-    NC_("layers-action", "Replace the selection with the layer mask"),
+    NC_("layers-action", "_Masks to Selection"), NULL,
+    NC_("layers-action", "Replace the selection with the layer masks"),
     GIMP_CHANNEL_OP_REPLACE, FALSE,
     GIMP_HELP_LAYER_MASK_SELECTION_REPLACE },
 
   { "layers-mask-selection-add", GIMP_ICON_SELECTION_ADD,
-    NC_("layers-action", "_Add to Selection"), NULL,
-    NC_("layers-action", "Add the layer mask to the current selection"),
+    NC_("layers-action", "_Add Masks to Selection"), NULL,
+    NC_("layers-action", "Add the layer masks to the current selection"),
     GIMP_CHANNEL_OP_ADD, FALSE,
     GIMP_HELP_LAYER_MASK_SELECTION_ADD },
 
   { "layers-mask-selection-subtract", GIMP_ICON_SELECTION_SUBTRACT,
-    NC_("layers-action", "_Subtract from Selection"), NULL,
-    NC_("layers-action", "Subtract the layer mask from the current selection"),
+    NC_("layers-action", "_Subtract Masks from Selection"), NULL,
+    NC_("layers-action", "Subtract the layer masks from the current selection"),
     GIMP_CHANNEL_OP_SUBTRACT, FALSE,
     GIMP_HELP_LAYER_MASK_SELECTION_SUBTRACT },
 
   { "layers-mask-selection-intersect", GIMP_ICON_SELECTION_INTERSECT,
-    NC_("layers-action", "_Intersect with Selection"), NULL,
-    NC_("layers-action", "Intersect the layer mask with the current selection"),
+    NC_("layers-action", "_Intersect Masks with Selection"), NULL,
+    NC_("layers-action", "Intersect the layer masks with the current selection"),
     GIMP_CHANNEL_OP_INTERSECT, FALSE,
     GIMP_HELP_LAYER_MASK_SELECTION_INTERSECT }
 };
@@ -1089,10 +1089,10 @@ layers_actions_update (GimpActionGroup *group,
   SET_ACTIVE ("layers-mask-show",    all_masks_shown);
   SET_ACTIVE ("layers-mask-disable", all_masks_disabled);
 
-  SET_SENSITIVE ("layers-mask-selection-replace",   layer && !fs && !ac && mask);
-  SET_SENSITIVE ("layers-mask-selection-add",       layer && !fs && !ac && mask);
-  SET_SENSITIVE ("layers-mask-selection-subtract",  layer && !fs && !ac && mask);
-  SET_SENSITIVE ("layers-mask-selection-intersect", layer && !fs && !ac && mask);
+  SET_SENSITIVE ("layers-mask-selection-replace",   n_layers && !fs && !ac && have_masks);
+  SET_SENSITIVE ("layers-mask-selection-add",       n_layers && !fs && !ac && have_masks);
+  SET_SENSITIVE ("layers-mask-selection-subtract",  n_layers && !fs && !ac && have_masks);
+  SET_SENSITIVE ("layers-mask-selection-intersect", n_layers && !fs && !ac && have_masks);
 
   SET_SENSITIVE ("layers-alpha-selection-replace",   n_layers > 0 && !fs && !ac);
   SET_SENSITIVE ("layers-alpha-selection-add",       n_layers > 0 && !fs && !ac);
diff --git a/app/actions/layers-commands.c b/app/actions/layers-commands.c
index 4cce3f5c61..a64904a66c 100644
--- a/app/actions/layers-commands.c
+++ b/app/actions/layers-commands.c
@@ -1502,19 +1502,44 @@ layers_mask_to_selection_cmd_callback (GimpAction *action,
                                        gpointer    data)
 {
   GimpImage     *image;
-  GimpLayer     *layer;
-  GimpLayerMask *mask;
-  return_if_no_layer (image, layer, data);
+  GList         *layers;
+  GList         *iter;
+  GList         *masks = NULL;
+  return_if_no_layers (image, layers, data);
 
-  mask = gimp_layer_get_mask (layer);
+  for (iter = layers; iter; iter = iter->next)
+    {
+      if (gimp_layer_get_mask (iter->data))
+        masks = g_list_prepend (masks, gimp_layer_get_mask (iter->data));
+    }
 
-  if (mask)
+  if (masks)
     {
       GimpChannelOps operation = (GimpChannelOps) g_variant_get_int32 (value);
 
-      gimp_item_to_selection (GIMP_ITEM (mask), operation,
-                              TRUE, FALSE, 0.0, 0.0);
+      switch (operation)
+        {
+        case GIMP_CHANNEL_OP_REPLACE:
+          gimp_channel_push_undo (gimp_image_get_mask (image),
+                                  C_("undo-type", "Masks to Selection"));
+          break;
+        case GIMP_CHANNEL_OP_ADD:
+          gimp_channel_push_undo (gimp_image_get_mask (image),
+                                  C_("undo-type", "Add Masks to Selection"));
+          break;
+        case GIMP_CHANNEL_OP_SUBTRACT:
+          gimp_channel_push_undo (gimp_image_get_mask (image),
+                                  C_("undo-type", "Subtract Masks from Selection"));
+          break;
+        case GIMP_CHANNEL_OP_INTERSECT:
+          gimp_channel_push_undo (gimp_image_get_mask (image),
+                                  C_("undo-type", "Intersect Masks with Selection"));
+          break;
+        }
+      gimp_channel_combine_items (gimp_image_get_mask (image),
+                                  masks, operation);
       gimp_image_flush (image);
+      g_list_free (masks);
     }
 }
 


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