[gimp/gimp-2-10] app: add GimpToolItem::shown property



commit f95decdc9f7b215f8761ad95e36a7f4746b1b8d1
Author: Ell <ell_se yahoo com>
Date:   Sat Feb 1 12:45:31 2020 +0200

    app: add GimpToolItem::shown property
    
    Add a new read-only GimpToolItem::shown property, and a
    corresponding GimpToolItem::shown-changed signal, which determines
    if a tool item is visible throughtout the hierarchy, i.e., if it
    and all its ancestors are visible.  This replaces
    gimp_tool_item_is_visible().
    
    Use the new property and signal in GimpToolPalette and
    GimpToolEditor, to simplify the code, and in preparation for a flat
    toolbox view.
    
    (cherry picked from commit ee9661237eec69ff403188bf88664c3090596d57)

 app/core/gimptoolgroup.c      | 33 ++++++++++++++++++++---
 app/core/gimptoolitem.c       | 63 +++++++++++++++++++++++++++++++++++--------
 app/core/gimptoolitem.h       | 17 ++++++++----
 app/widgets/gimptooleditor.c  | 30 +++++++--------------
 app/widgets/gimptoolpalette.c |  4 +--
 5 files changed, 105 insertions(+), 42 deletions(-)
---
diff --git a/app/core/gimptoolgroup.c b/app/core/gimptoolgroup.c
index 31d91b93f5..aa8e3bca2a 100644
--- a/app/core/gimptoolgroup.c
+++ b/app/core/gimptoolgroup.c
@@ -89,6 +89,8 @@ static void            gimp_tool_group_child_remove    (GimpContainer  *containe
                                                         GimpToolInfo   *tool_info,
                                                         GimpToolGroup  *tool_group);
 
+static void            gimp_tool_group_shown_changed   (GimpToolItem   *tool_item);
+
 
 G_DEFINE_TYPE_WITH_PRIVATE (GimpToolGroup, gimp_tool_group, GIMP_TYPE_TOOL_ITEM)
 
@@ -105,6 +107,7 @@ gimp_tool_group_class_init (GimpToolGroupClass *klass)
   GObjectClass      *object_class      = G_OBJECT_CLASS (klass);
   GimpObjectClass   *gimp_object_class = GIMP_OBJECT_CLASS (klass);
   GimpViewableClass *viewable_class    = GIMP_VIEWABLE_CLASS (klass);
+  GimpToolItemClass *tool_item_class   = GIMP_TOOL_ITEM_CLASS (klass);
 
   gimp_tool_group_signals[ACTIVE_TOOL_CHANGED] =
     g_signal_new ("active-tool-changed",
@@ -127,6 +130,8 @@ gimp_tool_group_class_init (GimpToolGroupClass *klass)
   viewable_class->get_expanded      = gimp_tool_group_get_expanded;
   viewable_class->set_expanded      = gimp_tool_group_set_expanded;
 
+  tool_item_class->shown_changed    = gimp_tool_group_shown_changed;
+
   GIMP_CONFIG_PROP_STRING (object_class, PROP_ACTIVE_TOOL,
                            "active-tool", NULL, NULL,
                            NULL,
@@ -319,19 +324,39 @@ gimp_tool_group_child_remove (GimpContainer *container,
     }
 }
 
+static void
+gimp_tool_group_shown_changed (GimpToolItem *tool_item)
+{
+  GimpToolGroup *tool_group = GIMP_TOOL_GROUP (tool_item);
+  GList         *iter;
+
+  if (GIMP_TOOL_ITEM_CLASS (parent_class)->shown_changed)
+    GIMP_TOOL_ITEM_CLASS (parent_class)->shown_changed (tool_item);
+
+  for (iter = GIMP_LIST (tool_group->priv->children)->queue->head;
+       iter;
+       iter = g_list_next (iter))
+    {
+      GimpToolItem *tool_item = iter->data;
+
+      if (gimp_tool_item_get_visible (tool_item))
+        gimp_tool_item_shown_changed (tool_item);
+    }
+}
+
 
 /*  public functions  */
 
 GimpToolGroup *
 gimp_tool_group_new (void)
 {
-  GimpToolGroup *group;
+  GimpToolGroup *tool_group;
 
-  group = g_object_new (GIMP_TYPE_TOOL_GROUP, NULL);
+  tool_group = g_object_new (GIMP_TYPE_TOOL_GROUP, NULL);
 
-  gimp_object_set_static_name (GIMP_OBJECT (group), "tool group");
+  gimp_object_set_static_name (GIMP_OBJECT (tool_group), "tool group");
 
-  return group;
+  return tool_group;
 }
 
 void
diff --git a/app/core/gimptoolitem.c b/app/core/gimptoolitem.c
index 5252cb091c..984597b963 100644
--- a/app/core/gimptoolitem.c
+++ b/app/core/gimptoolitem.c
@@ -38,13 +38,15 @@
 enum
 {
   VISIBLE_CHANGED,
+  SHOWN_CHANGED,
   LAST_SIGNAL
 };
 
 enum
 {
   PROP_0,
-  PROP_VISIBLE
+  PROP_VISIBLE,
+  PROP_SHOWN
 };
 
 
@@ -56,14 +58,14 @@ struct _GimpToolItemPrivate
 
 /*  local function prototypes  */
 
-static void   gimp_tool_item_get_property (GObject      *object,
-                                           guint         property_id,
-                                           GValue       *value,
-                                           GParamSpec   *pspec);
-static void   gimp_tool_item_set_property (GObject      *object,
-                                           guint         property_id,
-                                           const GValue *value,
-                                           GParamSpec   *pspec);
+static void   gimp_tool_item_get_property  (GObject      *object,
+                                            guint         property_id,
+                                            GValue       *value,
+                                            GParamSpec   *pspec);
+static void   gimp_tool_item_set_property  (GObject      *object,
+                                            guint         property_id,
+                                            const GValue *value,
+                                            GParamSpec   *pspec);
 
 
 G_DEFINE_TYPE_WITH_PRIVATE (GimpToolItem, gimp_tool_item, GIMP_TYPE_VIEWABLE)
@@ -89,6 +91,15 @@ gimp_tool_item_class_init (GimpToolItemClass *klass)
                   gimp_marshal_VOID__VOID,
                   G_TYPE_NONE, 0);
 
+  gimp_tool_item_signals[SHOWN_CHANGED] =
+    g_signal_new ("shown-changed",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_FIRST,
+                  G_STRUCT_OFFSET (GimpToolItemClass, shown_changed),
+                  NULL, NULL,
+                  gimp_marshal_VOID__VOID,
+                  G_TYPE_NONE, 0);
+
   object_class->get_property = gimp_tool_item_get_property;
   object_class->set_property = gimp_tool_item_set_property;
 
@@ -96,6 +107,11 @@ gimp_tool_item_class_init (GimpToolItemClass *klass)
                             "visible", NULL, NULL,
                             TRUE,
                             GIMP_PARAM_STATIC_STRINGS);
+
+  g_object_class_install_property (object_class, PROP_SHOWN,
+                                   g_param_spec_boolean ("shown", NULL, NULL,
+                                                         TRUE,
+                                                         GIMP_PARAM_READABLE));
 }
 
 static void
@@ -117,6 +133,9 @@ gimp_tool_item_get_property (GObject    *object,
     case PROP_VISIBLE:
       g_value_set_boolean (value, tool_item->priv->visible);
       break;
+    case PROP_SHOWN:
+      g_value_set_boolean (value, gimp_tool_item_get_shown (tool_item));
+      break;
 
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -155,11 +174,22 @@ gimp_tool_item_set_visible (GimpToolItem *tool_item,
 
   if (visible != tool_item->priv->visible)
     {
+      gboolean old_shown;
+
+      g_object_freeze_notify (G_OBJECT (tool_item));
+
+      old_shown = gimp_tool_item_get_shown (tool_item);
+
       tool_item->priv->visible = visible;
 
       g_signal_emit (tool_item, gimp_tool_item_signals[VISIBLE_CHANGED], 0);
 
+      if (gimp_tool_item_get_shown (tool_item) != old_shown)
+        gimp_tool_item_shown_changed (tool_item);
+
       g_object_notify (G_OBJECT (tool_item), "visible");
+
+      g_object_thaw_notify (G_OBJECT (tool_item));
     }
 }
 
@@ -172,7 +202,7 @@ gimp_tool_item_get_visible (GimpToolItem *tool_item)
 }
 
 gboolean
-gimp_tool_item_is_visible (GimpToolItem *tool_item)
+gimp_tool_item_get_shown (GimpToolItem *tool_item)
 {
   GimpToolItem *parent;
 
@@ -182,5 +212,16 @@ gimp_tool_item_is_visible (GimpToolItem *tool_item)
     gimp_viewable_get_parent (GIMP_VIEWABLE (tool_item)));
 
   return tool_item->priv->visible &&
-         (! parent || gimp_tool_item_is_visible (parent));
+         (! parent || gimp_tool_item_get_shown (parent));
+}
+
+
+/*  protected functions  */
+
+void
+gimp_tool_item_shown_changed (GimpToolItem *tool_item)
+{
+  g_signal_emit (tool_item, gimp_tool_item_signals[SHOWN_CHANGED], 0);
+
+  g_object_notify (G_OBJECT (tool_item), "shown");
 }
diff --git a/app/core/gimptoolitem.h b/app/core/gimptoolitem.h
index 9568bb98ec..3f19f496d5 100644
--- a/app/core/gimptoolitem.h
+++ b/app/core/gimptoolitem.h
@@ -49,15 +49,22 @@ struct _GimpToolItemClass
 
   /*  signals  */
   void (* visible_changed) (GimpToolItem *tool_item);
+  void (* shown_changed)   (GimpToolItem *tool_item);
 };
 
 
-GType      gimp_tool_item_get_type    (void) G_GNUC_CONST;
+GType      gimp_tool_item_get_type      (void) G_GNUC_CONST;
+                                        
+void       gimp_tool_item_set_visible   (GimpToolItem *tool_item,
+                                         gboolean      visible);
+gboolean   gimp_tool_item_get_visible   (GimpToolItem *tool_item);
+                                        
+gboolean   gimp_tool_item_get_shown     (GimpToolItem *tool_item);
 
-void       gimp_tool_item_set_visible (GimpToolItem *tool_item,
-                                       gboolean      visible);
-gboolean   gimp_tool_item_get_visible (GimpToolItem *tool_item);
-gboolean   gimp_tool_item_is_visible  (GimpToolItem *tool_item);
+
+/*  protected  */
+
+void       gimp_tool_item_shown_changed (GimpToolItem *tool_item);
 
 
 #endif  /*  __GIMP_TOOL_ITEM_H__  */
diff --git a/app/widgets/gimptooleditor.c b/app/widgets/gimptooleditor.c
index 1045599b6c..be7d7aeb9e 100644
--- a/app/widgets/gimptooleditor.c
+++ b/app/widgets/gimptooleditor.c
@@ -61,7 +61,7 @@ struct _GimpToolEditorPrivate
   GtkWidget       *delete_button;
   GtkWidget       *reset_button;
 
-  GimpTreeHandler *visible_changed_handler;
+  GimpTreeHandler *shown_changed_handler;
 
   /* State of tools at creation of the editor, stored to support
    * reverting changes
@@ -97,7 +97,7 @@ static void            gimp_tool_editor_drop_viewable             (GimpContainer
                                                                    GimpViewable               *dest_viewable,
                                                                    GtkTreeViewDropPosition     drop_pos);
 
-static void            gimp_tool_editor_visible_changed          (GimpToolItem                *tool_item,
+static void            gimp_tool_editor_shown_changed            (GimpToolItem                *tool_item,
                                                                   GimpToolEditor              *tool_editor);
 
 static void            gimp_tool_editor_eye_data_func            (GtkTreeViewColumn           *tree_column,
@@ -575,8 +575,8 @@ gimp_tool_editor_reset_clicked (GtkButton      *button,
 }
 
 static void
-gimp_tool_editor_visible_changed (GimpToolItem   *tool_item,
-                                  GimpToolEditor *tool_editor)
+gimp_tool_editor_shown_changed (GimpToolItem   *tool_item,
+                                GimpToolEditor *tool_editor)
 {
   GimpContainerTreeView *tree_view      = GIMP_CONTAINER_TREE_VIEW (tool_editor);
   GimpContainerView     *container_view = GIMP_CONTAINER_VIEW (tool_editor);
@@ -587,23 +587,13 @@ gimp_tool_editor_visible_changed (GimpToolItem   *tool_item,
 
   if (iter)
     {
-      GtkTreePath   *path;
-      GimpContainer *children;
+      GtkTreePath *path;
 
       path = gtk_tree_model_get_path (tree_view->model, iter);
 
       gtk_tree_model_row_changed (tree_view->model, path, iter);
 
       gtk_tree_path_free (path);
-
-      children = gimp_viewable_get_children (GIMP_VIEWABLE (tool_item));
-
-      if (children)
-        {
-          gimp_container_foreach (children,
-                                  (GFunc) gimp_tool_editor_visible_changed,
-                                  tool_editor);
-        }
     }
 }
 
@@ -626,7 +616,7 @@ gimp_tool_editor_eye_data_func (GtkTreeViewColumn *tree_column,
   g_object_set (cell,
                 "active",       gimp_tool_item_get_visible (tool_item),
                 "inconsistent", gimp_tool_item_get_visible (tool_item) &&
-                                ! gimp_tool_item_is_visible (tool_item),
+                                ! gimp_tool_item_get_shown (tool_item),
                 NULL);
 
   g_object_unref (renderer);
@@ -725,7 +715,7 @@ gimp_tool_editor_update_container (GimpToolEditor *tool_editor)
   GimpContainer     *container;
   GimpContext       *context;
 
-  g_clear_pointer (&tool_editor->priv->visible_changed_handler,
+  g_clear_pointer (&tool_editor->priv->shown_changed_handler,
                    gimp_tree_handler_disconnect);
 
   g_clear_pointer (&tool_editor->priv->initial_tool_state, g_free);
@@ -741,9 +731,9 @@ gimp_tool_editor_update_container (GimpToolEditor *tool_editor)
       tool_editor->priv->container = container;
       tool_editor->priv->context   = context;
 
-      tool_editor->priv->visible_changed_handler = gimp_tree_handler_connect (
-        container, "visible-changed",
-        G_CALLBACK (gimp_tool_editor_visible_changed),
+      tool_editor->priv->shown_changed_handler = gimp_tree_handler_connect (
+        container, "shown-changed",
+        G_CALLBACK (gimp_tool_editor_shown_changed),
         tool_editor);
 
       /* save initial tool order */
diff --git a/app/widgets/gimptoolpalette.c b/app/widgets/gimptoolpalette.c
index 0a941f0c38..ddd58d4644 100644
--- a/app/widgets/gimptoolpalette.c
+++ b/app/widgets/gimptoolpalette.c
@@ -435,10 +435,10 @@ gimp_tool_palette_add_button (GimpToolPalette *palette,
                               tool_button, index);
   gtk_widget_show (GTK_WIDGET (tool_button));
 
-  g_object_bind_property (tool_item,   "visible",
+  g_object_bind_property (tool_item,   "shown",
                           tool_button, "visible-horizontal",
                           G_BINDING_SYNC_CREATE);
-  g_object_bind_property (tool_item,   "visible",
+  g_object_bind_property (tool_item,   "shown",
                           tool_button, "visible-vertical",
                           G_BINDING_SYNC_CREATE);
 


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