[gimp] app: action "drawable-visible" now multi-layer aware.



commit c73ac8fdf43f9a964ac501a1480c8765a7552f4c
Author: Jehan <jehan girinstud io>
Date:   Mon Aug 3 19:49:26 2020 +0200

    app: action "drawable-visible" now multi-layer aware.

 app/actions/drawable-actions.c  | 21 ++++++++++---
 app/actions/drawable-commands.c | 65 +++++++++++++++++++++++++++++++++--------
 2 files changed, 70 insertions(+), 16 deletions(-)
---
diff --git a/app/actions/drawable-actions.c b/app/actions/drawable-actions.c
index a4b6233060..23faac0722 100644
--- a/app/actions/drawable-actions.c
+++ b/app/actions/drawable-actions.c
@@ -159,8 +159,9 @@ drawable_actions_update (GimpActionGroup *group,
 {
   GimpImage    *image;
   GimpDrawable *drawable     = NULL;
+  GList        *drawables    = NULL;
+  gboolean      has_visible  = FALSE;
   gboolean      is_rgb       = FALSE;
-  gboolean      visible      = FALSE;
   gboolean      linked       = FALSE;
   gboolean      locked       = FALSE;
   gboolean      can_lock     = FALSE;
@@ -169,12 +170,23 @@ drawable_actions_update (GimpActionGroup *group,
   gboolean      writable     = FALSE;
   gboolean      movable      = FALSE;
   gboolean      children     = FALSE;
+  GList        *iter;
 
   image = action_data_get_image (data);
 
   if (image)
     {
       drawable = gimp_image_get_active_drawable (image);
+      drawables = gimp_image_get_selected_drawables (image);
+
+      for (iter = drawables; iter; iter = iter->next)
+        {
+          if (gimp_item_get_visible (iter->data))
+            has_visible = TRUE;
+
+          if (has_visible)
+            break;
+        }
 
       if (drawable)
         {
@@ -187,7 +199,6 @@ drawable_actions_update (GimpActionGroup *group,
           else
             item = GIMP_ITEM (drawable);
 
-          visible       = gimp_item_get_visible (item);
           linked        = gimp_item_get_linked (item);
           locked        = gimp_item_get_lock_content (item);
           can_lock      = gimp_item_can_lock_content (item);
@@ -209,12 +220,12 @@ drawable_actions_update (GimpActionGroup *group,
   SET_SENSITIVE ("drawable-equalize",       writable && !children);
   SET_SENSITIVE ("drawable-levels-stretch", writable && !children && is_rgb);
 
-  SET_SENSITIVE ("drawable-visible",       drawable);
+  SET_SENSITIVE ("drawable-visible",       drawables);
   SET_SENSITIVE ("drawable-linked",        drawable);
   SET_SENSITIVE ("drawable-lock-content",  can_lock);
   SET_SENSITIVE ("drawable-lock-position", can_lock_pos);
 
-  SET_ACTIVE ("drawable-visible",       visible);
+  SET_ACTIVE ("drawable-visible",       has_visible);
   SET_ACTIVE ("drawable-linked",        linked);
   SET_ACTIVE ("drawable-lock-content",  locked);
   SET_ACTIVE ("drawable-lock-position", locked_pos);
@@ -228,4 +239,6 @@ drawable_actions_update (GimpActionGroup *group,
 
 #undef SET_SENSITIVE
 #undef SET_ACTIVE
+
+  g_list_free (drawables);
 }
diff --git a/app/actions/drawable-commands.c b/app/actions/drawable-commands.c
index 7ea70e8b6d..4e920562f7 100644
--- a/app/actions/drawable-commands.c
+++ b/app/actions/drawable-commands.c
@@ -122,30 +122,71 @@ drawable_visible_cmd_callback (GimpAction *action,
                                gpointer    data)
 {
   GimpImage    *image;
-  GimpDrawable *drawable;
+  GList        *drawables;
+  GList        *iter;
+  GimpUndo     *undo;
+  gboolean      push_undo = TRUE;
   gboolean      visible;
-  return_if_no_drawable (image, drawable, data);
+
+  return_if_no_drawables (image, drawables, data);
 
   visible = g_variant_get_boolean (value);
 
-  if (GIMP_IS_LAYER_MASK (drawable))
-    drawable =
-      GIMP_DRAWABLE (gimp_layer_mask_get_layer (GIMP_LAYER_MASK (drawable)));
+  if (GIMP_IS_LAYER_MASK (drawables->data))
+    {
+      GimpLayerMask *mask = GIMP_LAYER_MASK (drawables->data);
 
-  if (visible != gimp_item_get_visible (GIMP_ITEM (drawable)))
+      g_list_free (drawables);
+      drawables = g_list_prepend (NULL, gimp_layer_mask_get_layer (mask));
+    }
+
+  for (iter = drawables; iter; iter = iter->next)
     {
-      GimpUndo *undo;
-      gboolean  push_undo = TRUE;
+      if (visible && gimp_item_get_visible (iter->data))
+        {
+          /* If any of the drawables are already visible, we don't
+           * toggle the selection visibility. This prevents the
+           * SET_ACTIVE() in drawables-actions.c to toggle visibility
+           * unexpectedly.
+           */
+          g_list_free (drawables);
+          return;
+        }
+    }
 
+  for (iter = drawables; iter; iter = iter->next)
+    if (visible != gimp_item_get_visible (iter->data))
+      break;
+
+  if (! iter)
+    {
+      g_list_free (drawables);
+      return;
+    }
+
+  if (g_list_length (drawables) == 1)
+    {
       undo = gimp_image_undo_can_compress (image, GIMP_TYPE_ITEM_UNDO,
                                            GIMP_UNDO_ITEM_VISIBILITY);
 
-      if (undo && GIMP_ITEM_UNDO (undo)->item == GIMP_ITEM (drawable))
+      if (undo && GIMP_ITEM_UNDO (undo)->item == GIMP_ITEM (drawables->data))
         push_undo = FALSE;
-
-      gimp_item_set_visible (GIMP_ITEM (drawable), visible, push_undo);
-      gimp_image_flush (image);
     }
+  else
+    {
+      /* TODO: undo groups cannot be compressed so far. */
+      gimp_image_undo_group_start (image,
+                                   GIMP_UNDO_GROUP_ITEM_VISIBILITY,
+                                   "Item visibility");
+    }
+
+  for (; iter; iter = iter->next)
+    gimp_item_set_visible (iter->data, visible, push_undo);
+
+  if (g_list_length (drawables) != 1)
+    gimp_image_undo_group_end (image);
+
+  gimp_image_flush (image);
 }
 
 void


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