[gimp/wip/Jehan/layers-dockable-refresh: 47/92] app: add Alt-click on visibility and locks for exclusive switch within…




commit 5321e711e389c9a9b8095e52fd2ea16c6edeb308
Author: Jehan <jehan girinstud io>
Date:   Thu Feb 11 18:08:19 2021 +0100

    app: add Alt-click on visibility and locks for exclusive switch within…
    
    … the selected items only.
    This is the exact same algorithm as Shift-click, except that Shift-click
    switch exclusivity within the whole level of items. Alt-click does the
    same but only within selected items in the list.

 app/core/gimpimage.c           | 27 +++++++++++++++++++++++++++
 app/core/gimpimage.h           |  2 ++
 app/core/gimpitem-exclusive.c  | 24 +++++++++++++++++++-----
 app/core/gimpitem-exclusive.h  |  2 ++
 app/widgets/gimpitemtreeview.c |  9 ++++++---
 5 files changed, 56 insertions(+), 8 deletions(-)
---
diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c
index 4d37139988..e070bfc164 100644
--- a/app/core/gimpimage.c
+++ b/app/core/gimpimage.c
@@ -4666,6 +4666,33 @@ gimp_image_set_active_vectors (GimpImage   *image,
   return active_vectors;
 }
 
+/**
+ * gimp_image_is_selected_drawable:
+ * @image:
+ * @drawable:
+ *
+ * Checks if @drawable belong to the list of currently selected
+ * drawables. It doesn't mean this is the only selected drawable (if
+ * this is what you want to check, use
+ * gimp_image_equal_selected_drawables() with a list containing only
+ * this drawable).
+ *
+ * Returns: %TRUE is @drawable is one of the selected drawables.
+ */
+gboolean
+gimp_image_is_selected_drawable (GimpImage    *image,
+                                 GimpDrawable *drawable)
+{
+  GList    *selected_drawables;
+  gboolean  found;
+
+  selected_drawables = gimp_image_get_selected_drawables (image);
+  found = (g_list_find (selected_drawables, drawable) != NULL);
+  g_list_free (selected_drawables);
+
+  return found;
+}
+
 /**
  * gimp_image_equal_selected_drawables:
  * @image:
diff --git a/app/core/gimpimage.h b/app/core/gimpimage.h
index 4e45e798b6..b3f0de5eb7 100644
--- a/app/core/gimpimage.h
+++ b/app/core/gimpimage.h
@@ -386,6 +386,8 @@ void          gimp_image_unset_selected_channels (GimpImage          *image);
 GimpVectors   * gimp_image_set_active_vectors    (GimpImage          *image,
                                                   GimpVectors        *vectors);
 
+gboolean        gimp_image_is_selected_drawable  (GimpImage          *image,
+                                                  GimpDrawable       *drawable);
 gboolean     gimp_image_equal_selected_drawables (GimpImage          *image,
                                                   GList              *drawables);
 
diff --git a/app/core/gimpitem-exclusive.c b/app/core/gimpitem-exclusive.c
index 7f62bfac81..dc680be8d2 100644
--- a/app/core/gimpitem-exclusive.c
+++ b/app/core/gimpitem-exclusive.c
@@ -26,6 +26,8 @@
 #include "core-types.h"
 
 #include "gimpcontext.h"
+#include "gimpdrawable.h"
+#include "gimpimage.h"
 #include "gimpimage-undo.h"
 #include "gimpimage-undo-push.h"
 #include "gimpitem.h"
@@ -42,6 +44,7 @@ static void    gimp_item_exclusive_get_lists    (GimpItem              *item,
                                                  GimpItemIsEnabledFunc  is_enabled,
                                                  GimpItemCanSetFunc     can_set,
                                                  GimpItemIsPropLocked   is_prop_locked,
+                                                 gboolean               only_selected,
                                                  GList                **on,
                                                  GList                **off);
 
@@ -50,6 +53,7 @@ static void    gimp_item_exclusive_get_lists    (GimpItem              *item,
 
 void
 gimp_item_toggle_exclusive_visible (GimpItem    *item,
+                                    gboolean     only_selected,
                                     GimpContext *context)
 {
   gimp_item_toggle_exclusive (item,
@@ -60,7 +64,7 @@ gimp_item_toggle_exclusive_visible (GimpItem    *item,
                               (GimpItemUndoPush)      gimp_image_undo_push_item_visibility,
                               _("Set Item Exclusive Visibility"),
                               GIMP_UNDO_GROUP_ITEM_VISIBILITY,
-                              context);
+                              only_selected, context);
 }
 
 void
@@ -72,6 +76,7 @@ gimp_item_toggle_exclusive (GimpItem               *item,
                             GimpItemUndoPush        undo_push,
                             const gchar            *undo_desc,
                             GimpUndoType            group_undo_type,
+                            gboolean                only_selected,
                             GimpContext            *context)
 {
   GList       *ancestry;
@@ -85,7 +90,8 @@ gimp_item_toggle_exclusive (GimpItem               *item,
   g_return_if_fail (context == NULL || GIMP_IS_CONTEXT (context));
 
   ancestry = gimp_item_exclusive_get_ancestry (item);
-  gimp_item_exclusive_get_lists (item, is_enabled, can_set, is_prop_locked, &on, &off);
+  gimp_item_exclusive_get_lists (item, is_enabled, can_set, is_prop_locked,
+                                 only_selected, &on, &off);
 
   if (on || off || (! is_enabled (item) && (can_set == NULL || can_set (item))))
     {
@@ -265,9 +271,11 @@ gimp_item_exclusive_get_lists (GimpItem              *item,
                                GimpItemIsEnabledFunc  is_enabled,
                                GimpItemCanSetFunc     can_set,
                                GimpItemIsPropLocked   is_prop_locked,
+                               gboolean               only_selected,
                                GList                 **on,
                                GList                 **off)
 {
+  GimpImage    *image = NULL;
   GimpItemTree *tree;
   GList        *items;
   GList        *list;
@@ -279,15 +287,21 @@ gimp_item_exclusive_get_lists (GimpItem              *item,
 
   items = gimp_item_stack_get_item_list (GIMP_ITEM_STACK (tree->container));
 
+  if (only_selected)
+    image = gimp_item_get_image (item);
+
   for (list = items; list; list = g_list_next (list))
     {
       GimpItem *other = list->data;
 
-      if (other != item                                        &&
+      if (other != item                                                                &&
           /* Don't include item with visibility locks. */
-          (is_prop_locked == NULL || ! is_prop_locked (other)) &&
+          (is_prop_locked == NULL || ! is_prop_locked (other))                         &&
           /* Don't include item which can be changed. */
-          (can_set == NULL || can_set (other))                 &&
+          (can_set == NULL || can_set (other))                                         &&
+          /* Do we care only about selected drawables? */
+          (! only_selected  || gimp_image_is_selected_drawable (image,
+                                                                GIMP_DRAWABLE (other))) &&
           /* We are only interested in same level items. */
           gimp_viewable_get_parent (GIMP_VIEWABLE (other)) ==
           gimp_viewable_get_parent (GIMP_VIEWABLE (item)))
diff --git a/app/core/gimpitem-exclusive.h b/app/core/gimpitem-exclusive.h
index 5381721bdd..efb7030df9 100644
--- a/app/core/gimpitem-exclusive.h
+++ b/app/core/gimpitem-exclusive.h
@@ -32,6 +32,7 @@ typedef GimpUndo      * (*GimpItemUndoPush)          (GimpImage     *image,
                                                       GimpItem      *item);
 
 void   gimp_item_toggle_exclusive_visible (GimpItem             *item,
+                                           gboolean              only_selected,
                                            GimpContext          *context);
 void   gimp_item_toggle_exclusive         (GimpItem             *item,
                                            GimpItemIsEnabledFunc is_enabled,
@@ -41,6 +42,7 @@ void   gimp_item_toggle_exclusive         (GimpItem             *item,
                                            GimpItemUndoPush      undo_push,
                                            const gchar          *undo_desc,
                                            GimpUndoType          group_undo_type,
+                                           gboolean              only_selected,
                                            GimpContext          *context);
 void   gimp_item_toggle_exclusive_linked  (GimpItem             *item,
                                            GimpContext          *context);
diff --git a/app/widgets/gimpitemtreeview.c b/app/widgets/gimpitemtreeview.c
index 01d4dec9e6..8604536128 100644
--- a/app/widgets/gimpitemtreeview.c
+++ b/app/widgets/gimpitemtreeview.c
@@ -1734,9 +1734,10 @@ gimp_item_tree_view_eye_clicked (GtkCellRendererToggle *toggle,
 
       image = gimp_item_get_image (item);
 
-      if ((state & GDK_SHIFT_MASK))
+      if ((state & GDK_SHIFT_MASK) ||
+          (state & GDK_MOD1_MASK))
         {
-          gimp_item_toggle_exclusive_visible (item, context);
+          gimp_item_toggle_exclusive_visible (item, (state & GDK_MOD1_MASK), context);
         }
       else
         {
@@ -1885,7 +1886,8 @@ gimp_item_tree_view_lock_button_release (GtkWidget        *widget,
   data      = g_object_get_data (G_OBJECT (widget), "lock-data");
   modifiers = bevent->state & gimp_get_all_modifiers_mask ();
 
-  if (modifiers == GDK_SHIFT_MASK)
+  if (modifiers == GDK_SHIFT_MASK ||
+      modifiers == GDK_MOD1_MASK)
     gimp_item_toggle_exclusive (view->priv->lock_box_item,
                                 data->is_locked,
                                 data->lock,
@@ -1894,6 +1896,7 @@ gimp_item_tree_view_lock_button_release (GtkWidget        *widget,
                                 data->undo_push,
                                 data->undo_exclusive_desc,
                                 data->group_undo_type,
+                                (modifiers == GDK_MOD1_MASK),
                                 NULL);
   else
     return GDK_EVENT_PROPAGATE;


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