[gimp] app: more cleanup in the action history code, mostly general consistency



commit 50ca9068daef83c27fe5aea0a7fb19628f8f13c2
Author: Michael Natterer <mitch gimp org>
Date:   Tue Jul 29 12:28:18 2014 +0200

    app: more cleanup in the action history code, mostly general consistency

 app/dialogs/action-search-dialog.c |   15 ++---
 app/dialogs/preferences-dialog.c   |   14 ++--
 app/gui/gui.c                      |    5 +-
 app/widgets/gimpaction-history.c   |  108 +++++++++++++++++++++---------------
 app/widgets/gimpaction-history.h   |   25 +++++----
 5 files changed, 95 insertions(+), 72 deletions(-)
---
diff --git a/app/dialogs/action-search-dialog.c b/app/dialogs/action-search-dialog.c
index 6d3be77..7d7cb4b 100644
--- a/app/dialogs/action-search-dialog.c
+++ b/app/dialogs/action-search-dialog.c
@@ -65,7 +65,7 @@ typedef struct
 {
   GtkWidget     *dialog;
 
-  GimpGuiConfig *config;
+  Gimp          *gimp;
   GtkWidget     *keyword_entry;
   GtkWidget     *results_list;
   GtkWidget     *list_view;
@@ -122,16 +122,15 @@ action_search_dialog_create (Gimp *gimp)
 
   if (! private)
     {
-      GtkWidget     *action_search_dialog = gtk_window_new (GTK_WINDOW_TOPLEVEL);
-      GimpGuiConfig *config               = GIMP_GUI_CONFIG (gimp->config);
-      GtkWidget     *main_vbox;
+      GtkWidget *action_search_dialog = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+      GtkWidget *main_vbox;
 
       private = g_slice_new0 (SearchDialog);
       g_object_weak_ref (G_OBJECT (action_search_dialog),
                          (GWeakNotify) search_dialog_free, private);
 
       private->dialog = action_search_dialog;
-      private->config = config;
+      private->gimp   = gimp;
 
       gtk_window_set_role (GTK_WINDOW (action_search_dialog),
                            "gimp-action-search-dialog");
@@ -537,9 +536,9 @@ action_search_history_and_actions (const gchar  *keyword,
   if (g_strcmp0 (keyword, "") == 0)
     return;
 
-  history_actions = gimp_action_history_search (keyword,
+  history_actions = gimp_action_history_search (private->gimp,
                                                 action_search_match_keyword,
-                                                private->config);
+                                                keyword);
 
   /* First put on top of the list any matching action of user history. */
   for (list = history_actions; list; list = g_list_next (list))
@@ -581,7 +580,7 @@ action_search_history_and_actions (const gchar  *keyword,
             continue;
 
           if (! gtk_action_is_sensitive (action) &&
-              ! private->config->search_show_unavailable)
+              ! GIMP_GUI_CONFIG (private->gimp->config)->search_show_unavailable)
             continue;
 
           if (action_search_match_keyword (action, keyword, &section, TRUE))
diff --git a/app/dialogs/preferences-dialog.c b/app/dialogs/preferences-dialog.c
index 57eb7a7..62f9272 100644
--- a/app/dialogs/preferences-dialog.c
+++ b/app/dialogs/preferences-dialog.c
@@ -114,8 +114,8 @@ static void   prefs_devices_save_callback         (GtkWidget  *widget,
                                                    Gimp       *gimp);
 static void   prefs_devices_clear_callback        (GtkWidget  *widget,
                                                    Gimp       *gimp);
-static void   prefs_search_empty_callback         (GtkWidget  *widget,
-                                                   gpointer    user_data);
+static void   prefs_search_clear_callback         (GtkWidget  *widget,
+                                                   Gimp       *gimp);
 static void   prefs_tool_options_save_callback    (GtkWidget  *widget,
                                                    Gimp       *gimp);
 static void   prefs_tool_options_clear_callback   (GtkWidget  *widget,
@@ -653,10 +653,10 @@ prefs_devices_clear_callback (GtkWidget *widget,
 }
 
 static void
-prefs_search_empty_callback (GtkWidget  *widget,
-                             gpointer    user_data)
+prefs_search_clear_callback (GtkWidget *widget,
+                             Gimp      *gimp)
 {
-  gimp_action_history_empty ();
+  gimp_action_history_clear (gimp);
 }
 
 static void
@@ -1647,8 +1647,8 @@ prefs_dialog_new (Gimp       *gimp,
                              _("Clear Action History"),
                              GTK_BOX (vbox2));
   g_signal_connect (button, "clicked",
-                    G_CALLBACK (prefs_search_empty_callback),
-                    NULL);
+                    G_CALLBACK (prefs_search_clear_callback),
+                    gimp);
 
   g_object_unref (size_group);
   size_group = NULL;
diff --git a/app/gui/gui.c b/app/gui/gui.c
index 017fa17..fc2f848 100644
--- a/app/gui/gui.c
+++ b/app/gui/gui.c
@@ -520,7 +520,8 @@ gui_restore_after_callback (Gimp               *gimp,
                                                     gimp,
                                                     gui_config->tearoff_menus);
   gimp_ui_manager_update (image_ui_manager, gimp);
-  gimp_action_history_init (gui_config);
+
+  gimp_action_history_init (gimp);
 
 #ifdef GDK_WINDOWING_QUARTZ
   {
@@ -697,7 +698,7 @@ gui_exit_after_callback (Gimp     *gimp,
                                         gui_show_tooltips_notify,
                                         gimp);
 
-  gimp_action_history_exit (GIMP_GUI_CONFIG (gimp->config));
+  gimp_action_history_exit (gimp);
 
   g_object_unref (image_ui_manager);
   image_ui_manager = NULL;
diff --git a/app/widgets/gimpaction-history.c b/app/widgets/gimpaction-history.c
index ea08c7e..14aea39 100644
--- a/app/widgets/gimpaction-history.c
+++ b/app/widgets/gimpaction-history.c
@@ -31,6 +31,8 @@
 
 #include "config/gimpguiconfig.h"
 
+#include "core/gimp.h"
+
 #include "gimpuimanager.h"
 #include "gimpaction.h"
 #include "gimpaction-history.h"
@@ -70,8 +72,9 @@ static gint gimp_action_history_compare_func      (GimpActionHistoryItem *a,
 /*  public functions  */
 
 void
-gimp_action_history_init (GimpGuiConfig *config)
+gimp_action_history_init (Gimp *gimp)
 {
+  GimpGuiConfig *config;
   GimpUIManager *manager;
   GFile         *file;
   GScanner      *scanner;
@@ -79,6 +82,10 @@ gimp_action_history_init (GimpGuiConfig *config)
   gint           count;
   gint           n_items = 0;
 
+  g_return_if_fail (GIMP_IS_GIMP (gimp));
+
+  config = GIMP_GUI_CONFIG (gimp->config);
+
   if (history.items != NULL)
     {
       g_warning ("%s: must be run only once.", G_STRFUNC);
@@ -179,8 +186,9 @@ gimp_action_history_init (GimpGuiConfig *config)
 }
 
 void
-gimp_action_history_exit (GimpGuiConfig *config)
+gimp_action_history_exit (Gimp *gimp)
 {
+  GimpGuiConfig         *config;
   GimpActionHistoryItem *item;
   GList                 *actions;
   GFile                 *file;
@@ -188,6 +196,10 @@ gimp_action_history_exit (GimpGuiConfig *config)
   gint                   min_count = 0;
   gint                   i;
 
+  g_return_if_fail (GIMP_IS_GIMP (gimp));
+
+  config = GIMP_GUI_CONFIG (gimp->config);
+
   /* If we have more items than current history size, trim the history
    * and move down all count so that 1 is lower.
    */
@@ -214,7 +226,56 @@ gimp_action_history_exit (GimpGuiConfig *config)
 
   gimp_config_writer_finish (writer, "end of action-history", NULL);
 
-  gimp_action_history_empty ();
+  gimp_action_history_clear (gimp);
+}
+
+void
+gimp_action_history_clear (Gimp *gimp)
+{
+  g_return_if_fail (GIMP_IS_GIMP (gimp));
+
+  g_list_free_full (history.items,
+                    (GDestroyNotify) gimp_action_history_item_free);
+  history.items = NULL;
+}
+
+/* Search all history actions which match "keyword" with function
+ * match_func(action, keyword).
+ *
+ * @return a list of GtkAction*, to free with:
+ * g_list_free_full (result, (GDestroyNotify) g_object_unref);
+ */
+GList *
+gimp_action_history_search (Gimp                *gimp,
+                            GimpActionMatchFunc  match_func,
+                            const gchar         *keyword)
+{
+  GimpGuiConfig *config;
+  GList         *actions;
+  GList         *result = NULL;
+  gint           i;
+
+  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
+  g_return_val_if_fail (match_func != NULL, NULL);
+
+  config = GIMP_GUI_CONFIG (gimp->config);
+
+  for (actions = history.items, i = 0;
+       actions && i < config->action_history_size;
+       actions = g_list_next (actions), i++)
+    {
+      GimpActionHistoryItem *item   = actions->data;
+      GtkAction             *action = item->action;
+
+      if (! gtk_action_is_sensitive (action) &&
+          ! config->search_show_unavailable)
+        continue;
+
+      if (match_func (action, keyword, NULL, FALSE))
+        result = g_list_prepend (result, g_object_ref (action));
+    }
+
+  return g_list_reverse (result);
 }
 
 /* gimp_action_history_excluded_action:
@@ -310,47 +371,6 @@ gimp_action_history_activate_callback (GtkAction *action,
                           (GCompareFunc) gimp_action_history_compare_func);
 }
 
-void
-gimp_action_history_empty (void)
-{
-  g_list_free_full (history.items,
-                    (GDestroyNotify) gimp_action_history_item_free);
-  history.items = NULL;
-}
-
-/* Search all history actions which match "keyword" with function
- * match_func(action, keyword).
- *
- * @return a list of GtkAction*, to free with:
- * g_list_free_full (result, (GDestroyNotify) g_object_unref);
- */
-GList *
-gimp_action_history_search (const gchar         *keyword,
-                            GimpActionMatchFunc  match_func,
-                            GimpGuiConfig       *config)
-{
-  GList *actions;
-  GList *result = NULL;
-  gint   i;
-
-  for (actions = history.items, i = 0;
-       actions && i < config->action_history_size;
-       actions = g_list_next (actions), i++)
-    {
-      GimpActionHistoryItem *item   = actions->data;
-      GtkAction             *action = item->action;
-
-      if (! gtk_action_is_sensitive (action) &&
-          ! config->search_show_unavailable)
-        continue;
-
-      if (match_func (action, keyword, NULL, FALSE))
-        result = g_list_prepend (result, g_object_ref (action));
-    }
-
-  return g_list_reverse (result);
-}
-
 
 /*  private functions  */
 
diff --git a/app/widgets/gimpaction-history.h b/app/widgets/gimpaction-history.h
index 5c97910..1f0f402 100644
--- a/app/widgets/gimpaction-history.h
+++ b/app/widgets/gimpaction-history.h
@@ -21,23 +21,26 @@
 #ifndef __GIMP_ACTION_HISTORY_H__
 #define __GIMP_ACTION_HISTORY_H__
 
-typedef gboolean   (* GimpActionMatchFunc)       (GtkAction           *action,
-                                                  const gchar         *keyword,
-                                                  gint                *section,
-                                                  gboolean             match_fuzzy);
 
-void       gimp_action_history_init              (GimpGuiConfig       *config);
-void       gimp_action_history_exit              (GimpGuiConfig       *config);
+typedef gboolean (* GimpActionMatchFunc) (GtkAction   *action,
+                                          const gchar *keyword,
+                                          gint        *section,
+                                          gboolean     match_fuzzy);
 
-void       gimp_action_history_activate_callback (GtkAction           *action,
-                                                  gpointer             user_data);
 
-void       gimp_action_history_empty             (void);
+void       gimp_action_history_init              (Gimp                *gimp);
+void       gimp_action_history_exit              (Gimp                *gimp);
 
-GList *    gimp_action_history_search            (const gchar         *keyword,
+void       gimp_action_history_clear             (Gimp                *gimp);
+
+GList    * gimp_action_history_search            (Gimp                *gimp,
                                                   GimpActionMatchFunc  match_func,
-                                                  GimpGuiConfig       *config);
+                                                  const gchar         *keyword);
 
 gboolean   gimp_action_history_excluded_action   (const gchar         *action_name);
 
+void       gimp_action_history_activate_callback (GtkAction           *action,
+                                                  gpointer             user_data);
+
+
 #endif  /* __GIMP_ACTION_HISTORY_H__ */


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