[gimp] app, libgimpwigets: new internal util function gimp_tools_blink_widget()



commit 71a2c83a9412d1441f757207a38765014474faa9
Author: Jehan <jehan girinstud io>
Date:   Fri Mar 4 15:34:03 2022 +0100

    app, libgimpwigets: new internal util function gimp_tools_blink_widget()
    
    This function will help us raise attention to various widgets in
    dockables by blinking them similarly to how we blink locks or visibility
    icons.
    
    I associate this with the fact that property widgets identifier will be
    the property name, so we get identifiers for free when creating widgets
    through the propwidgets API.

 app/tools/gimptools-utils.c      |  69 ++++++++++++++++++++
 app/tools/gimptools-utils.h      |   4 ++
 app/widgets/gimppropwidgets.c    |   4 ++
 libgimpwidgets/gimppropwidgets.c | 132 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 209 insertions(+)
---
diff --git a/app/tools/gimptools-utils.c b/app/tools/gimptools-utils.c
index 85f24acf20..1e50214e24 100644
--- a/app/tools/gimptools-utils.c
+++ b/app/tools/gimptools-utils.c
@@ -39,6 +39,10 @@
 #include "gimptools-utils.h"
 
 
+static void gimp_tools_search_widget_rec (GtkWidget   *widget,
+                                          const gchar *searched_id);
+
+
 /*  public functions  */
 
 void
@@ -77,3 +81,68 @@ gimp_tools_blink_lock_box (Gimp     *gimp,
   view = GIMP_ITEM_TREE_VIEW (gtk_bin_get_child (GTK_BIN (dockable)));
   gimp_item_tree_view_blink_lock (view, item);
 }
+
+
+/**
+ * gimp_tools_blink_property:
+ * @gimp:
+ * @dockable_identifier:
+ * @widget_identifier:
+ *
+ * This function will raise the dockable identified by
+ * @dockable_identifier. The list of dockable identifiers can be found
+ * in `app/dialogs/dialogs.c`.
+ *
+ * Then it will find the widget identified by @widget_identifier. Note
+ * that for propwidgets, this is usually the associated property name.
+ * Finally it will blink this widget to raise attention.
+ */
+void
+gimp_tools_blink_widget (Gimp        *gimp,
+                         const gchar *dockable_identifier,
+                         const gchar *widget_identifier)
+{
+  GtkWidget  *dockable;
+  GdkMonitor *monitor;
+
+  g_return_if_fail (GIMP_IS_GIMP (gimp));
+
+  monitor = gimp_get_monitor_at_pointer ();
+
+  dockable = gimp_window_strategy_show_dockable_dialog (
+    GIMP_WINDOW_STRATEGY (gimp_get_window_strategy (gimp)),
+    gimp,
+    gimp_dialog_factory_get_singleton (),
+    monitor,
+    dockable_identifier);
+
+  if (! dockable)
+    return;
+
+  gtk_container_foreach (GTK_CONTAINER (dockable),
+                         (GtkCallback) gimp_tools_search_widget_rec,
+                         (gpointer) widget_identifier);
+}
+
+
+/*  private functions  */
+
+static void
+gimp_tools_search_widget_rec (GtkWidget   *widget,
+                              const gchar *searched_id)
+{
+  if (gtk_widget_is_visible (widget))
+    {
+      const gchar *id;
+
+      id = g_object_get_data (G_OBJECT (widget),
+                              "gimp-widget-identifier");
+
+      if (id && g_strcmp0 (id, searched_id) == 0)
+        gimp_widget_blink (widget);
+      else if (GTK_IS_CONTAINER (widget))
+        gtk_container_foreach (GTK_CONTAINER (widget),
+                               (GtkCallback) gimp_tools_search_widget_rec,
+                               (gpointer) searched_id);
+    }
+}
diff --git a/app/tools/gimptools-utils.h b/app/tools/gimptools-utils.h
index 5810f19ca6..c2821fa888 100644
--- a/app/tools/gimptools-utils.h
+++ b/app/tools/gimptools-utils.h
@@ -22,5 +22,9 @@
 void   gimp_tools_blink_lock_box (Gimp     *gimp,
                                   GimpItem *item);
 
+void   gimp_tools_blink_widget   (Gimp        *gimp,
+                                  const gchar *dockable_identifier,
+                                  const gchar *widget_identifier);
+
 
 #endif  /* __GIMP_TOOLS_UTILS_H__ */
diff --git a/app/widgets/gimppropwidgets.c b/app/widgets/gimppropwidgets.c
index 976af2d54e..bd6e2ca09f 100644
--- a/app/widgets/gimppropwidgets.c
+++ b/app/widgets/gimppropwidgets.c
@@ -141,6 +141,10 @@ gimp_prop_expanding_frame_new (GObject      *config,
 
   gtk_widget_show (frame);
 
+  g_object_set_data_full (G_OBJECT (frame), "gimp-widget-identifier",
+                          g_strdup (property_name),
+                          (GDestroyNotify) g_free);
+
   return frame;
 }
 
diff --git a/libgimpwidgets/gimppropwidgets.c b/libgimpwidgets/gimppropwidgets.c
index 42afa20250..872e54d4a3 100644
--- a/libgimpwidgets/gimppropwidgets.c
+++ b/libgimpwidgets/gimppropwidgets.c
@@ -134,6 +134,10 @@ gimp_prop_check_button_new (GObject     *config,
                           button, "active",
                           G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
 
+  g_object_set_data_full (G_OBJECT (button), "gimp-widget-identifier",
+                          g_strdup (property_name),
+                          (GDestroyNotify) g_free);
+
   return button;
 }
 
@@ -213,6 +217,10 @@ gimp_prop_enum_check_button_new (GObject     *config,
 
   gtk_widget_show (button);
 
+  g_object_set_data_full (G_OBJECT (button), "gimp-widget-identifier",
+                          g_strdup (property_name),
+                          (GDestroyNotify) g_free);
+
   return button;
 }
 
@@ -360,6 +368,10 @@ gimp_prop_switch_new (GObject     *config,
   if (switch_out)
     *switch_out = pswitch;
 
+  g_object_set_data_full (G_OBJECT (hbox), "gimp-widget-identifier",
+                          g_strdup (property_name),
+                          (GDestroyNotify) g_free);
+
   return hbox;
 }
 
@@ -424,6 +436,10 @@ gimp_prop_int_combo_box_new (GObject      *config,
                           combo_box, "value",
                           G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
 
+  g_object_set_data_full (G_OBJECT (combo_box), "gimp-widget-identifier",
+                          g_strdup (property_name),
+                          (GDestroyNotify) g_free);
+
   return combo_box;
 }
 
@@ -490,6 +506,10 @@ gimp_prop_pointer_combo_box_new (GObject      *config,
                   G_CALLBACK (gimp_prop_pointer_combo_box_notify),
                   combo_box);
 
+  g_object_set_data_full (G_OBJECT (combo_box), "gimp-widget-identifier",
+                          g_strdup (property_name),
+                          (GDestroyNotify) g_free);
+
   gtk_widget_show (combo_box);
 
   return combo_box;
@@ -580,6 +600,10 @@ gimp_prop_enum_combo_box_new (GObject     *config,
 
   gtk_widget_show (combo_box);
 
+  g_object_set_data_full (G_OBJECT (combo_box), "gimp-widget-identifier",
+                          g_strdup (property_name),
+                          (GDestroyNotify) g_free);
+
   return combo_box;
 }
 
@@ -738,6 +762,10 @@ gimp_prop_boolean_combo_box_new (GObject     *config,
                   G_CALLBACK (gimp_prop_boolean_combo_box_notify),
                   combo);
 
+  g_object_set_data_full (G_OBJECT (combo), "gimp-widget-identifier",
+                          g_strdup (property_name),
+                          (GDestroyNotify) g_free);
+
   gtk_widget_show (combo);
 
   return combo;
@@ -875,6 +903,10 @@ gimp_prop_enum_radio_frame_new (GObject     *config,
 
   gtk_widget_show (frame);
 
+  g_object_set_data_full (G_OBJECT (frame), "gimp-widget-identifier",
+                          g_strdup (property_name),
+                          (GDestroyNotify) g_free);
+
   return frame;
 }
 
@@ -945,6 +977,10 @@ gimp_prop_enum_radio_box_new (GObject     *config,
 
   g_object_set_data (G_OBJECT (vbox), "radio-button", button);
 
+  g_object_set_data_full (G_OBJECT (vbox), "gimp-widget-identifier",
+                          g_strdup (property_name),
+                          (GDestroyNotify) g_free);
+
   gtk_widget_show (vbox);
 
   return vbox;
@@ -993,6 +1029,10 @@ gimp_prop_int_radio_frame_new (GObject      *config,
   gtk_container_add (GTK_CONTAINER (frame), box);
   gtk_widget_show (box);
 
+  g_object_set_data_full (G_OBJECT (frame), "gimp-widget-identifier",
+                          g_strdup (property_name),
+                          (GDestroyNotify) g_free);
+
   gtk_widget_show (frame);
 
   return frame;
@@ -1081,6 +1121,10 @@ gimp_prop_int_radio_box_new (GObject      *config,
 
   g_object_set_data (G_OBJECT (vbox), "radio-button", button);
 
+  g_object_set_data_full (G_OBJECT (vbox), "gimp-widget-identifier",
+                          g_strdup (property_name),
+                          (GDestroyNotify) g_free);
+
   gtk_widget_show (vbox);
 
   return vbox;
@@ -1133,6 +1177,10 @@ gimp_prop_enum_label_new (GObject     *config,
                   G_CALLBACK (gimp_prop_enum_label_notify),
                   label);
 
+  g_object_set_data_full (G_OBJECT (label), "gimp-widget-identifier",
+                          g_strdup (property_name),
+                          (GDestroyNotify) g_free);
+
   gtk_widget_show (label);
 
   return label;
@@ -1215,6 +1263,10 @@ gimp_prop_boolean_radio_frame_new (GObject     *config,
 
   g_object_set_data (G_OBJECT (frame), "radio-button", button);
 
+  g_object_set_data_full (G_OBJECT (frame), "gimp-widget-identifier",
+                          g_strdup (property_name),
+                          (GDestroyNotify) g_free);
+
   gtk_widget_show (frame);
 
   return frame;
@@ -1290,6 +1342,10 @@ gimp_prop_enum_icon_box_new (GObject     *config,
                   G_CALLBACK (gimp_prop_radio_button_notify),
                   button);
 
+  g_object_set_data_full (G_OBJECT (box), "gimp-widget-identifier",
+                          g_strdup (property_name),
+                          (GDestroyNotify) g_free);
+
   gtk_widget_show (box);
 
   return box;
@@ -1403,6 +1459,10 @@ gimp_prop_spin_button_new (GObject     *config,
                      "gimp-prop-adjustment-binding",
                      binding);
 
+  g_object_set_data_full (G_OBJECT (spinbutton), "gimp-widget-identifier",
+                          g_strdup (property_name),
+                          (GDestroyNotify) g_free);
+
   gtk_widget_show (spinbutton);
 
   return spinbutton;
@@ -1450,6 +1510,10 @@ gimp_prop_label_spin_new (GObject     *config,
                           widget, "value",
                           G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
 
+  g_object_set_data_full (G_OBJECT (widget), "gimp-widget-identifier",
+                          g_strdup (property_name),
+                          (GDestroyNotify) g_free);
+
   return widget;
 }
 
@@ -1526,6 +1590,10 @@ gimp_prop_spin_scale_new (GObject     *config,
 
   gtk_widget_show (spinscale);
 
+  g_object_set_data_full (G_OBJECT (spinscale), "gimp-widget-identifier",
+                          g_strdup (property_name),
+                          (GDestroyNotify) g_free);
+
   return spinscale;
 }
 
@@ -1721,6 +1789,10 @@ gimp_prop_hscale_new (GObject     *config,
                   G_CALLBACK (gimp_prop_adjustment_notify),
                   adjustment);
 
+  g_object_set_data_full (G_OBJECT (scale), "gimp-widget-identifier",
+                          g_strdup (property_name),
+                          (GDestroyNotify) g_free);
+
   gtk_widget_show (scale);
 
   return scale;
@@ -1830,6 +1902,10 @@ gimp_prop_scale_entry_new (GObject     *config,
 
     }
 
+  g_object_set_data_full (G_OBJECT (widget), "gimp-widget-identifier",
+                          g_strdup (property_name),
+                          (GDestroyNotify) g_free);
+
   return widget;
 }
 
@@ -2074,6 +2150,10 @@ gimp_prop_memsize_entry_new (GObject     *config,
                   G_CALLBACK (gimp_prop_memsize_notify),
                   entry);
 
+  g_object_set_data_full (G_OBJECT (entry), "gimp-widget-identifier",
+                          g_strdup (property_name),
+                          (GDestroyNotify) g_free);
+
   gtk_widget_show (entry);
 
   return entry;
@@ -2182,6 +2262,10 @@ gimp_prop_label_new (GObject     *config,
   g_object_bind_property (config, property_name,
                           label, "label", flags);
 
+  g_object_set_data_full (G_OBJECT (label), "gimp-widget-identifier",
+                          g_strdup (property_name),
+                          (GDestroyNotify) g_free);
+
   return label;
 }
 
@@ -2251,6 +2335,10 @@ gimp_prop_entry_new (GObject     *config,
                   G_CALLBACK (gimp_prop_entry_notify),
                   entry);
 
+  g_object_set_data_full (G_OBJECT (entry), "gimp-widget-identifier",
+                          g_strdup (property_name),
+                          (GDestroyNotify) g_free);
+
   gtk_widget_show (entry);
 
   return entry;
@@ -2364,6 +2452,10 @@ gimp_prop_label_entry_new (GObject     *config,
                           label_entry, "value",
                           G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
 
+  g_object_set_data_full (G_OBJECT (label_entry), "gimp-widget-identifier",
+                          g_strdup (property_name),
+                          (GDestroyNotify) g_free);
+
   gtk_widget_show (label_entry);
 
   return label_entry;
@@ -2590,6 +2682,10 @@ gimp_prop_string_combo_box_new (GObject      *config,
                   G_CALLBACK (gimp_prop_string_combo_box_notify),
                   combo_box);
 
+  g_object_set_data_full (G_OBJECT (combo_box), "gimp-widget-identifier",
+                          g_strdup (property_name),
+                          (GDestroyNotify) g_free);
+
   gtk_widget_show (combo_box);
 
   return combo_box;
@@ -2964,6 +3060,10 @@ gimp_prop_path_editor_new (GObject     *config,
                       editor);
     }
 
+  g_object_set_data_full (G_OBJECT (editor), "gimp-widget-identifier",
+                          g_strdup (path_property_name),
+                          (GDestroyNotify) g_free);
+
   gtk_widget_show (editor);
 
   return editor;
@@ -3273,6 +3373,10 @@ gimp_prop_size_entry_new (GObject                   *config,
                       entry);
     }
 
+  g_object_set_data_full (G_OBJECT (entry), "gimp-widget-identifier",
+                          g_strdup (property_name),
+                          (GDestroyNotify) g_free);
+
   gtk_widget_show (entry);
 
   return entry;
@@ -3509,6 +3613,10 @@ gimp_prop_coordinates_new (GObject                   *config,
       return NULL;
     }
 
+  g_object_set_data_full (G_OBJECT (entry), "gimp-widget-identifier",
+                          g_strdup (x_property_name),
+                          (GDestroyNotify) g_free);
+
   gtk_widget_show (entry);
 
   return entry;
@@ -3964,6 +4072,10 @@ gimp_prop_color_area_new (GObject           *config,
                   G_CALLBACK (gimp_prop_color_area_notify),
                   area);
 
+  g_object_set_data_full (G_OBJECT (area), "gimp-widget-identifier",
+                          g_strdup (property_name),
+                          (GDestroyNotify) g_free);
+
   gtk_widget_show (area);
 
   return area;
@@ -4062,6 +4174,11 @@ gimp_prop_color_select_new (GObject           *config,
   g_object_bind_property (config, property_name,
                           button, "color",
                           G_BINDING_BIDIRECTIONAL);
+
+  g_object_set_data_full (G_OBJECT (button), "gimp-widget-identifier",
+                          g_strdup (property_name),
+                          (GDestroyNotify) g_free);
+
   gtk_widget_show (button);
 
   return button;
@@ -4108,6 +4225,9 @@ gimp_prop_label_color_new (GObject     *config,
                           prop_widget, "value",
                           G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
 
+  g_object_set_data_full (G_OBJECT (prop_widget), "gimp-widget-identifier",
+                          g_strdup (property_name),
+                          (GDestroyNotify) g_free);
 
   gtk_widget_show (prop_widget);
 
@@ -4184,6 +4304,10 @@ gimp_prop_unit_combo_box_new (GObject     *config,
                   G_CALLBACK (gimp_prop_unit_combo_box_notify),
                   combo);
 
+  g_object_set_data_full (G_OBJECT (combo), "gimp-widget-identifier",
+                          g_strdup (property_name),
+                          (GDestroyNotify) g_free);
+
   gtk_widget_show (combo);
 
   return combo;
@@ -4294,6 +4418,10 @@ gimp_prop_icon_image_new (GObject     *config,
                           image, "icon-name",
                           G_BINDING_BIDIRECTIONAL);
 
+  g_object_set_data_full (G_OBJECT (image), "gimp-widget-identifier",
+                          g_strdup (property_name),
+                          (GDestroyNotify) g_free);
+
   g_free (icon_name);
 
   return image;
@@ -4364,6 +4492,10 @@ gimp_prop_expander_new (GObject     *config,
                   G_CALLBACK (gimp_prop_expander_notify),
                   expander);
 
+  g_object_set_data_full (G_OBJECT (expander), "gimp-widget-identifier",
+                          g_strdup (property_name),
+                          (GDestroyNotify) g_free);
+
   gtk_widget_show (expander);
 
   return expander;


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