[gimp] app: make demo scripting even simpler/cleaner.



commit 4dc41f1aaf8387d166172dc3907d61ee9ccf3275
Author: Jehan <jehan girinstud io>
Date:   Sun Mar 6 13:34:12 2022 +0100

    app: make demo scripting even simpler/cleaner.
    
    First I strip now every pieces of text. What it allows it to span the
    script elements for instance on several lines, indent them and all that.
    
    The second thing is that since all the dockable start with "gimp-", we
    may as well allow use shorter names (both are allowed). Same for tool
    (which we special-case), all the tool buttons ID start with "tools-"
    since we reused the action names. So let's just allow the shorter
    versions.
    
    Finally I create a new gimp_blink_toolbox() which is a specialized
    gimp_blink_dockable() for the toolbox in particular. I also move there
    the whole code about selecting the right tool.

 app/dialogs/welcome-dialog.c    | 59 +++++++++++++++++++++--------------------
 app/widgets/gimpwidgets-utils.c | 41 ++++++++++++++++++++++++++++
 app/widgets/gimpwidgets-utils.h |  4 +++
 3 files changed, 75 insertions(+), 29 deletions(-)
---
diff --git a/app/dialogs/welcome-dialog.c b/app/dialogs/welcome-dialog.c
index 566ff3afb0..642e9b3e31 100644
--- a/app/dialogs/welcome-dialog.c
+++ b/app/dialogs/welcome-dialog.c
@@ -32,18 +32,10 @@
 
 #include "dialogs-types.h"
 
-#include "config/gimpguiconfig.h"
-
 #include "core/gimp.h"
 #include "core/gimp-utils.h"
 
-#include "widgets/gimpaction.h"
-#include "widgets/gimpdialogfactory.h"
-#include "widgets/gimphelp-ids.h"
-#include "widgets/gimptoolbox.h"
-#include "widgets/gimpuimanager.h"
 #include "widgets/gimpwidgets-utils.h"
-#include "widgets/gimpwindowstrategy.h"
 
 #include "welcome-dialog.h"
 #include "welcome-dialog-data.h"
@@ -544,34 +536,43 @@ welcome_dialog_release_item_activated (GtkListBox    *listbox,
       dockable_id = ids[0];
       widget_id   = ids[1];
 
-      if (g_strcmp0 (dockable_id, "gimp-toolbox") == 0 &&
-          widget_id != NULL)
+      /* Allowing white spaces so that the demo in XML metadata can be
+       * spaced-out or even on multiple lines for clarity.
+       */
+      dockable_id = g_strstrip (dockable_id);
+      widget_id   = g_strstrip (widget_id);
+
+      /* All our dockable IDs start with "gimp-". This allows to write
+       * shorter names in the demo script.
+       */
+      if (! g_str_has_prefix (dockable_id, "gimp-"))
         {
-          GimpUIManager *ui_manager;
-          GtkWidget     *toolbox;
+          gchar *tmp = g_strdup_printf ("gimp-%s", dockable_id);
 
-          /* As a special case, for the toolbox, we don't just raise it,
-           * we also select the tool if one was requested.
+          g_free (ids[0]);
+          dockable_id = ids[0] = tmp;
+        }
+
+      /* Blink widget. */
+      if (g_strcmp0 (dockable_id, "gimp-toolbox") == 0)
+        {
+          /* All tool button IDs start with "tools-". This allows to
+           * write shorter tool names in the demo script.
            */
-          toolbox = gimp_window_strategy_show_dockable_dialog (GIMP_WINDOW_STRATEGY 
(gimp_get_window_strategy (gimp)),
-                                                               gimp,
-                                                               gimp_dialog_factory_get_singleton (),
-                                                               gimp_get_monitor_at_pointer (),
-                                                               "gimp-toolbox");
-          /* Find and activate the tool. */
-          if (toolbox &&
-              (ui_manager = gimp_dock_get_ui_manager (GIMP_DOCK (toolbox))))
+          if (! g_str_has_prefix (widget_id, "tools-"))
             {
-              GimpAction *action;
+              gchar *tmp = g_strdup_printf ("tools-%s", widget_id);
 
-              action = gimp_ui_manager_find_action (ui_manager, "tools", widget_id);
-                                                    /*"tools-bucket-fill");*/
-              gimp_action_activate (GIMP_ACTION (action));
+              g_free (ids[1]);
+              widget_id = ids[1] = tmp;
             }
-        }
 
-      /* Blink widget. */
-      gimp_blink_dockable (gimp, dockable_id, widget_id, &blink_script);
+          gimp_blink_toolbox (gimp, widget_id, &blink_script);
+        }
+      else
+        {
+          gimp_blink_dockable (gimp, dockable_id, widget_id, &blink_script);
+        }
 
       g_strfreev (ids);
     }
diff --git a/app/widgets/gimpwidgets-utils.c b/app/widgets/gimpwidgets-utils.c
index b4cc12a86f..2aed53ab82 100644
--- a/app/widgets/gimpwidgets-utils.c
+++ b/app/widgets/gimpwidgets-utils.c
@@ -61,6 +61,7 @@
 #include "gimpdockwindow.h"
 #include "gimperrordialog.h"
 #include "gimpsessioninfo.h"
+#include "gimpuimanager.h"
 #include "gimpwidgets-utils.h"
 #include "gimpwindowstrategy.h"
 
@@ -1527,6 +1528,46 @@ gimp_widget_blink_cancel (GtkWidget *widget)
     }
 }
 
+/**
+ * gimp_blink_toolbox:
+ * @gimp:
+ * @action_name:
+ * @blink_scenario:
+ *
+ * This is similar to gimp_blink_dockable() for the toolbox
+ * specifically. What it will do, additionally to blink the tool button,
+ * is first to activate it.
+ *
+ * Also the identifier is easy as it is simply the action name.
+ */
+void
+gimp_blink_toolbox (Gimp         *gimp,
+                    const gchar  *action_name,
+                    GList       **blink_scenario)
+{
+  GimpUIManager *ui_manager;
+  GtkWidget     *toolbox;
+
+  /* As a special case, for the toolbox, we don't just raise it,
+   * we also select the tool if one was requested.
+   */
+  toolbox = gimp_window_strategy_show_dockable_dialog (GIMP_WINDOW_STRATEGY (gimp_get_window_strategy 
(gimp)),
+                                                       gimp,
+                                                       gimp_dialog_factory_get_singleton (),
+                                                       gimp_get_monitor_at_pointer (),
+                                                       "gimp-toolbox");
+  /* Find and activate the tool. */
+  if (toolbox && action_name != NULL &&
+      (ui_manager = gimp_dock_get_ui_manager (GIMP_DOCK (toolbox))))
+    {
+      GimpAction *action;
+
+      action = gimp_ui_manager_find_action (ui_manager, "tools", action_name);
+      gimp_action_activate (GIMP_ACTION (action));
+    }
+  gimp_blink_dockable (gimp, "gimp-toolbox", action_name, blink_scenario);
+}
+
 /**
  * gimp_blink_dockable:
  * @gimp:
diff --git a/app/widgets/gimpwidgets-utils.h b/app/widgets/gimpwidgets-utils.h
index da70260acd..f60cdb9551 100644
--- a/app/widgets/gimpwidgets-utils.h
+++ b/app/widgets/gimpwidgets-utils.h
@@ -93,6 +93,10 @@ void              gimp_widget_blink_rect           (GtkWidget            *widget
                                                     GdkRectangle         *rect);
 void              gimp_widget_blink                (GtkWidget             *widget);
 void              gimp_widget_blink_cancel         (GtkWidget             *widget);
+
+void              gimp_blink_toolbox               (Gimp                  *gimp,
+                                                    const gchar           *action_name,
+                                                    GList               **blink_script);
 void              gimp_blink_dockable              (Gimp                  *gimp,
                                                     const gchar           *dockable_identifier,
                                                     const gchar           *widget_identifier,


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