[gimp] app: remove the old tool presets system



commit 91195e859392395526e12fd6ffe47610d059c7e5
Author: Michael Natterer <mitch gimp org>
Date:   Wed Mar 23 09:27:29 2011 +0100

    app: remove the old tool presets system
    
    Instead, keep around a GimpFilteredContainer in GimpToolInfo that
    maintains a per-tool list of presets from the global preset factory.
    Turn the tool options dialog's preset Save/Restore/Edit/Delete menus
    and buttons into shortcuts for managing the active tool's presets.

 app/actions/tool-options-actions.c  |   82 ++++-----
 app/actions/tool-options-commands.c |  192 +++++++++------------
 app/actions/tool-options-commands.h |   36 ++--
 app/core/Makefile.am                |    2 -
 app/core/core-types.h               |    1 -
 app/core/gimptoolinfo.c             |   26 +++-
 app/core/gimptoolinfo.h             |    2 +-
 app/core/gimptoolpresets.c          |  320 -----------------------------------
 app/core/gimptoolpresets.h          |   66 -------
 app/menus/tool-options-menu.c       |   13 +-
 app/tools/gimp-tools.c              |    5 +-
 app/widgets/gimphelp-ids.h          |    2 +-
 app/widgets/gimptooloptionseditor.c |  131 +++-----------
 menus/tool-options-menu.xml         |   10 +-
 14 files changed, 202 insertions(+), 686 deletions(-)
---
diff --git a/app/actions/tool-options-actions.c b/app/actions/tool-options-actions.c
index bc0c095..10c5819 100644
--- a/app/actions/tool-options-actions.c
+++ b/app/actions/tool-options-actions.c
@@ -42,7 +42,6 @@
 static void tool_options_actions_update_presets (GimpActionGroup *group,
                                                  const gchar     *action_prefix,
                                                  GCallback        callback,
-                                                 const gchar     *stock_id,
                                                  const gchar     *help_id,
                                                  GimpContainer   *presets);
 
@@ -55,25 +54,25 @@ static const GimpActionEntry tool_options_actions[] =
     NC_("tool-options-action", "Tool Options Menu"), NULL, NULL, NULL,
     GIMP_HELP_TOOL_OPTIONS_DIALOG },
 
-  { "tool-options-save-menu", GTK_STOCK_SAVE,
-    NC_("tool-options-action", "_Save Options To"), "", NULL, NULL,
+  { "tool-options-save-preset-menu", GTK_STOCK_SAVE,
+    NC_("tool-options-action", "_Save Tool Preset"), "", NULL, NULL,
     GIMP_HELP_TOOL_OPTIONS_SAVE },
 
-  { "tool-options-restore-menu", GTK_STOCK_REVERT_TO_SAVED,
-    NC_("tool-options-action", "_Restore Options From"), "", NULL, NULL,
+  { "tool-options-restore-preset-menu", GTK_STOCK_REVERT_TO_SAVED,
+    NC_("tool-options-action", "_Restore Tool Preset"), "", NULL, NULL,
     GIMP_HELP_TOOL_OPTIONS_RESTORE },
 
-  { "tool-options-rename-menu", GTK_STOCK_EDIT,
-    NC_("tool-options-action", "Re_name Saved Options"), NULL, NULL, NULL,
-    GIMP_HELP_TOOL_OPTIONS_RENAME },
+  { "tool-options-edit-preset-menu", GTK_STOCK_EDIT,
+    NC_("tool-options-action", "E_dit Tool Preset"), NULL, NULL, NULL,
+    GIMP_HELP_TOOL_OPTIONS_EDIT },
 
-  { "tool-options-delete-menu", GTK_STOCK_DELETE,
-    NC_("tool-options-action", "_Delete Saved Options"), "", NULL, NULL,
+  { "tool-options-delete-preset-menu", GTK_STOCK_DELETE,
+    NC_("tool-options-action", "_Delete Tool Preset"), "", NULL, NULL,
     GIMP_HELP_TOOL_OPTIONS_DELETE },
 
-  { "tool-options-save-new", GTK_STOCK_NEW,
-    NC_("tool-options-action", "_New Entry..."), "", NULL,
-    G_CALLBACK (tool_options_save_new_cmd_callback),
+  { "tool-options-save-new-preset", GTK_STOCK_NEW,
+    NC_("tool-options-action", "_New Tool Preset..."), "", NULL,
+    G_CALLBACK (tool_options_save_new_preset_cmd_callback),
     GIMP_HELP_TOOL_OPTIONS_SAVE },
 
   { "tool-options-reset", GIMP_STOCK_RESET,
@@ -104,9 +103,9 @@ tool_options_actions_setup (GimpActionGroup *group)
                                  tool_options_actions,
                                  G_N_ELEMENTS (tool_options_actions));
 
-  SET_HIDE_EMPTY ("tool-options-restore-menu", FALSE);
-  SET_HIDE_EMPTY ("tool-options-rename-menu",  FALSE);
-  SET_HIDE_EMPTY ("tool-options-delete-menu",  FALSE);
+  SET_HIDE_EMPTY ("tool-options-restore-preset-menu", FALSE);
+  SET_HIDE_EMPTY ("tool-options-edit-preset-menu",    FALSE);
+  SET_HIDE_EMPTY ("tool-options-delete-preset-menu",  FALSE);
 }
 
 void
@@ -116,34 +115,30 @@ tool_options_actions_update (GimpActionGroup *group,
   GimpContext  *context   = gimp_get_user_context (group->gimp);
   GimpToolInfo *tool_info = gimp_context_get_tool (context);
 
-  SET_VISIBLE ("tool-options-save-menu",    tool_info->presets);
-  SET_VISIBLE ("tool-options-restore-menu", tool_info->presets);
-  SET_VISIBLE ("tool-options-rename-menu",  tool_info->presets);
-  SET_VISIBLE ("tool-options-delete-menu",  tool_info->presets);
+  SET_VISIBLE ("tool-options-save-preset-menu",    tool_info->presets);
+  SET_VISIBLE ("tool-options-restore-preset-menu", tool_info->presets);
+  SET_VISIBLE ("tool-options-edit-preset-menu",    tool_info->presets);
+  SET_VISIBLE ("tool-options-delete-preset-menu",  tool_info->presets);
 
-  tool_options_actions_update_presets (group, "tool-options-save-",
-                                       G_CALLBACK (tool_options_save_to_cmd_callback),
-                                       GTK_STOCK_SAVE,
+  tool_options_actions_update_presets (group, "tool-options-save-preset",
+                                       G_CALLBACK (tool_options_save_preset_cmd_callback),
                                        GIMP_HELP_TOOL_OPTIONS_SAVE,
-                                       GIMP_CONTAINER (tool_info->presets));
+                                       tool_info->presets);
 
-  tool_options_actions_update_presets (group, "tool-options-restore-",
-                                       G_CALLBACK (tool_options_restore_from_cmd_callback),
-                                       GTK_STOCK_REVERT_TO_SAVED,
+  tool_options_actions_update_presets (group, "tool-options-restore-preset",
+                                       G_CALLBACK (tool_options_restore_preset_cmd_callback),
                                        GIMP_HELP_TOOL_OPTIONS_RESTORE,
-                                       GIMP_CONTAINER (tool_info->presets));
+                                       tool_info->presets);
 
-  tool_options_actions_update_presets (group, "tool-options-rename-",
-                                       G_CALLBACK (tool_options_rename_saved_cmd_callback),
-                                       GTK_STOCK_EDIT,
-                                       GIMP_HELP_TOOL_OPTIONS_RENAME,
-                                       GIMP_CONTAINER (tool_info->presets));
+  tool_options_actions_update_presets (group, "tool-options-edit-preset",
+                                       G_CALLBACK (tool_options_edit_preset_cmd_callback),
+                                       GIMP_HELP_TOOL_OPTIONS_EDIT,
+                                       tool_info->presets);
 
-  tool_options_actions_update_presets (group, "tool-options-delete-",
-                                       G_CALLBACK (tool_options_delete_saved_cmd_callback),
-                                       GTK_STOCK_DELETE,
+  tool_options_actions_update_presets (group, "tool-options-delete-preset",
+                                       G_CALLBACK (tool_options_delete_preset_cmd_callback),
                                        GIMP_HELP_TOOL_OPTIONS_DELETE,
-                                       GIMP_CONTAINER (tool_info->presets));
+                                       tool_info->presets);
 }
 
 
@@ -153,7 +148,6 @@ static void
 tool_options_actions_update_presets (GimpActionGroup *group,
                                      const gchar     *action_prefix,
                                      GCallback        callback,
-                                     const gchar     *stock_id,
                                      const gchar     *help_id,
                                      GimpContainer   *presets)
 {
@@ -166,7 +160,7 @@ tool_options_actions_update_presets (GimpActionGroup *group,
       gchar     *action_name;
       GtkAction *action;
 
-      action_name = g_strdup_printf ("%s%03d", action_prefix, i);
+      action_name = g_strdup_printf ("%s-%03d", action_prefix, i);
       action = gtk_action_group_get_action (GTK_ACTION_GROUP (group),
                                             action_name);
       g_free (action_name);
@@ -185,7 +179,6 @@ tool_options_actions_update_presets (GimpActionGroup *group,
       GimpEnumActionEntry entry;
 
       entry.name           = NULL;
-      entry.stock_id       = stock_id;
       entry.label          = NULL;
       entry.accelerator    = "";
       entry.tooltip        = NULL;
@@ -197,11 +190,12 @@ tool_options_actions_update_presets (GimpActionGroup *group,
            list;
            list = g_list_next (list), i++)
         {
-          GimpToolOptions *options = list->data;
+          GimpObject *options = list->data;
 
-          entry.name  = g_strdup_printf ("%s%03d", action_prefix, i);
-          entry.label = gimp_object_get_name (options);
-          entry.value = i;
+          entry.name     = g_strdup_printf ("%s-%03d", action_prefix, i);
+          entry.label    = gimp_object_get_name (options);
+          entry.stock_id = gimp_viewable_get_stock_id (GIMP_VIEWABLE (options));
+          entry.value    = i;
 
           gimp_action_group_add_enum_actions (group, NULL, &entry, 1, callback);
 
diff --git a/app/actions/tool-options-commands.c b/app/actions/tool-options-commands.c
index 02ba368..340c86c 100644
--- a/app/actions/tool-options-commands.c
+++ b/app/actions/tool-options-commands.c
@@ -27,10 +27,14 @@
 #include "actions-types.h"
 
 #include "core/gimp.h"
+#include "core/gimpcontainer.h"
+#include "core/gimpdatafactory.h"
 #include "core/gimptoolinfo.h"
 #include "core/gimptooloptions.h"
-#include "core/gimptoolpresets.h"
+#include "core/gimptoolpreset.h"
 
+#include "widgets/gimpdataeditor.h"
+#include "widgets/gimpdialogfactory.h"
 #include "widgets/gimpeditor.h"
 #include "widgets/gimphelp-ids.h"
 #include "widgets/gimpmessagebox.h"
@@ -45,123 +49,109 @@
 
 /*  local function prototypes  */
 
-static void   tool_options_save_callback   (GtkWidget   *widget,
-                                            const gchar *name,
-                                            gpointer     data);
-static void   tool_options_rename_callback (GtkWidget   *widget,
-                                            const gchar *name,
-                                            gpointer     data);
+static void   tool_options_show_preset_editor (GimpEditor     *editor,
+                                               GimpToolPreset *preset);
 
 
 /*  public functions  */
 
 void
-tool_options_save_new_cmd_callback (GtkAction *action,
-                                    gpointer   data)
+tool_options_save_new_preset_cmd_callback (GtkAction *action,
+                                           gpointer   user_data)
 {
-  GimpEditor   *editor    = GIMP_EDITOR (data);
-  GimpContext  *context   = gimp_get_user_context (editor->ui_manager->gimp);
-  GimpToolInfo *tool_info = gimp_context_get_tool (context);
-  GtkWidget    *dialog;
-
-  context   = gimp_get_user_context (editor->ui_manager->gimp);
-  tool_info = gimp_context_get_tool (context);
-
-  dialog = gimp_query_string_box (_("Save Tool Options"),
-                                  gtk_widget_get_toplevel (GTK_WIDGET (editor)),
-                                  gimp_standard_help_func,
-                                  GIMP_HELP_TOOL_OPTIONS_DIALOG,
-                                  _("Enter a name for the saved options"),
-                                  _("Saved Options"),
-                                  NULL, NULL,
-                                  tool_options_save_callback, tool_info);
-  gtk_widget_show (dialog);
+  GimpEditor  *editor  = GIMP_EDITOR (user_data);
+  GimpContext *context = gimp_get_user_context (editor->ui_manager->gimp);
+  GimpData    *data;
+
+  data = gimp_data_factory_data_new (context->gimp->tool_preset_factory,
+                                     context, _("Untitled"));
+
+  tool_options_show_preset_editor (editor, GIMP_TOOL_PRESET (data));
 }
 
 void
-tool_options_save_to_cmd_callback (GtkAction *action,
-                                   gint       value,
-                                   gpointer   data)
+tool_options_save_preset_cmd_callback (GtkAction *action,
+                                       gint       value,
+                                       gpointer   data)
 {
-  GimpEditor      *editor    = GIMP_EDITOR (data);
-  GimpContext     *context   = gimp_get_user_context (editor->ui_manager->gimp);
-  GimpToolInfo    *tool_info = gimp_context_get_tool (context);
-  GimpToolOptions *options;
+  GimpEditor     *editor    = GIMP_EDITOR (data);
+  GimpContext    *context   = gimp_get_user_context (editor->ui_manager->gimp);
+  GimpToolInfo   *tool_info = gimp_context_get_tool (context);
+  GimpToolPreset *preset;
 
-  options = gimp_tool_presets_get_options (tool_info->presets, value);
+  preset = (GimpToolPreset *)
+    gimp_container_get_child_by_index (tool_info->presets, value);
 
-  if (options)
+  if (preset)
     {
-      gchar *name = g_strdup (gimp_object_get_name (options));
-
       gimp_config_sync (G_OBJECT (tool_info->tool_options),
-                        G_OBJECT (options),
-                        GIMP_CONFIG_PARAM_SERIALIZE);
-      gimp_object_take_name (GIMP_OBJECT (options), name);
+                        G_OBJECT (preset->tool_options), 0);
+
+      tool_options_show_preset_editor (editor, preset);
     }
 }
 
 void
-tool_options_restore_from_cmd_callback (GtkAction *action,
-                                        gint       value,
-                                        gpointer   data)
+tool_options_restore_preset_cmd_callback (GtkAction *action,
+                                          gint       value,
+                                          gpointer   data)
 {
-  GimpEditor      *editor    = GIMP_EDITOR (data);
-  GimpContext     *context   = gimp_get_user_context (editor->ui_manager->gimp);
-  GimpToolInfo    *tool_info = gimp_context_get_tool (context);
-  GimpToolOptions *options;
+  GimpEditor     *editor    = GIMP_EDITOR (data);
+  GimpContext    *context   = gimp_get_user_context (editor->ui_manager->gimp);
+  GimpToolInfo   *tool_info = gimp_context_get_tool (context);
+  GimpToolPreset *preset;
 
-  options = gimp_tool_presets_get_options (tool_info->presets, value);
+  preset = (GimpToolPreset *)
+    gimp_container_get_child_by_index (tool_info->presets, value);
 
-  if (options)
-    gimp_config_sync (G_OBJECT (options),
-                      G_OBJECT (tool_info->tool_options),
-                      GIMP_CONFIG_PARAM_SERIALIZE);
+  if (preset)
+    {
+      if (gimp_context_get_tool_preset (context) != preset)
+        gimp_context_set_tool_preset (context, preset);
+      else
+        gimp_context_tool_preset_changed (context);
+    }
 }
 
 void
-tool_options_rename_saved_cmd_callback (GtkAction *action,
-                                        gint       value,
-                                        gpointer   data)
+tool_options_edit_preset_cmd_callback (GtkAction *action,
+                                       gint       value,
+                                       gpointer   data)
 {
-  GimpEditor      *editor    = GIMP_EDITOR (data);
-  GimpContext     *context   = gimp_get_user_context (editor->ui_manager->gimp);
-  GimpToolInfo    *tool_info = gimp_context_get_tool (context);
-  GimpToolOptions *options;
+  GimpEditor     *editor    = GIMP_EDITOR (data);
+  GimpContext    *context   = gimp_get_user_context (editor->ui_manager->gimp);
+  GimpToolInfo   *tool_info = gimp_context_get_tool (context);
+  GimpToolPreset *preset;
 
-  options = gimp_tool_presets_get_options (tool_info->presets, value);
+  preset = (GimpToolPreset *)
+    gimp_container_get_child_by_index (tool_info->presets, value);
 
-  if (options)
+  if (preset)
     {
-      GtkWidget *dialog;
-
-      dialog = gimp_query_string_box (_("Rename Saved Tool Options"),
-                                      gtk_widget_get_toplevel (GTK_WIDGET (editor)),
-                                      gimp_standard_help_func,
-                                      GIMP_HELP_TOOL_OPTIONS_DIALOG,
-                                      _("Enter a new name for the saved options"),
-                                      gimp_object_get_name (options),
-                                      NULL, NULL,
-                                      tool_options_rename_callback, options);
-      gtk_widget_show (dialog);
+      tool_options_show_preset_editor (editor, preset);
     }
 }
 
 void
-tool_options_delete_saved_cmd_callback (GtkAction *action,
-                                        gint       value,
-                                        gpointer   data)
+tool_options_delete_preset_cmd_callback (GtkAction *action,
+                                         gint       value,
+                                         gpointer   data)
 {
-  GimpEditor      *editor    = GIMP_EDITOR (data);
-  GimpContext     *context   = gimp_get_user_context (editor->ui_manager->gimp);
-  GimpToolInfo    *tool_info = gimp_context_get_tool (context);
-  GimpToolOptions *options;
+  GimpEditor     *editor    = GIMP_EDITOR (data);
+  GimpContext    *context   = gimp_get_user_context (editor->ui_manager->gimp);
+  GimpToolInfo   *tool_info = gimp_context_get_tool (context);
+  GimpToolPreset *preset;
 
-  options = gimp_tool_presets_get_options (tool_info->presets, value);
+  preset = (GimpToolPreset *)
+    gimp_container_get_child_by_index (tool_info->presets, value);
 
-  if (options)
-    gimp_container_remove (GIMP_CONTAINER (tool_info->presets),
-                           GIMP_OBJECT (options));
+  if (preset)
+    {
+      GimpDataFactory *preset_factory = context->gimp->tool_preset_factory;
+
+      gimp_container_remove (gimp_data_factory_get_container (preset_factory),
+                             GIMP_OBJECT (preset));
+    }
 }
 
 void
@@ -230,34 +220,16 @@ tool_options_reset_all_cmd_callback (GtkAction *action,
 /*  private functions  */
 
 static void
-tool_options_save_callback (GtkWidget   *widget,
-                            const gchar *name,
-                            gpointer     data)
+tool_options_show_preset_editor (GimpEditor     *editor,
+                                 GimpToolPreset *preset)
 {
-  GimpToolInfo *tool_info = GIMP_TOOL_INFO (data);
-  GimpConfig   *copy;
-
-  copy = gimp_config_duplicate (GIMP_CONFIG (tool_info->tool_options));
-
-  if (name && strlen (name))
-    gimp_object_set_name (GIMP_OBJECT (copy), name);
-  else
-    gimp_object_set_static_name (GIMP_OBJECT (copy), _("Saved Options"));
+  GtkWidget *dockable;
 
-  gimp_container_insert (GIMP_CONTAINER (tool_info->presets),
-                         GIMP_OBJECT (copy), -1);
-  g_object_unref (copy);
-}
-
-static void
-tool_options_rename_callback (GtkWidget   *widget,
-                              const gchar *name,
-                              gpointer     data)
-{
-  GimpToolOptions *options = GIMP_TOOL_OPTIONS (data);
+  dockable =
+    gimp_dialog_factory_dialog_raise (gimp_dialog_factory_get_singleton (),
+                                      gtk_widget_get_screen (GTK_WIDGET (editor)),
+                                      "gimp-tool-preset-editor", -1);
 
-  if (name && strlen (name))
-    gimp_object_set_name (GIMP_OBJECT (options), name);
-  else
-    gimp_object_set_static_name (GIMP_OBJECT (options), _("Saved Options"));
+  gimp_data_editor_set_data (GIMP_DATA_EDITOR (gtk_bin_get_child (GTK_BIN (dockable))),
+                             GIMP_DATA (preset));
 }
diff --git a/app/actions/tool-options-commands.h b/app/actions/tool-options-commands.h
index 53df61d..47efda8 100644
--- a/app/actions/tool-options-commands.h
+++ b/app/actions/tool-options-commands.h
@@ -19,26 +19,26 @@
 #define __TOOL_OPTIONS_COMMANDS_H__
 
 
-void   tool_options_save_new_cmd_callback     (GtkAction *action,
-                                               gpointer   data);
+void   tool_options_save_new_preset_cmd_callback (GtkAction *action,
+                                                  gpointer   data);
 
-void   tool_options_save_to_cmd_callback      (GtkAction *action,
-                                               gint       value,
-                                               gpointer   data);
-void   tool_options_restore_from_cmd_callback (GtkAction *action,
-                                               gint       value,
-                                               gpointer   data);
-void   tool_options_rename_saved_cmd_callback (GtkAction *action,
-                                               gint       value,
-                                               gpointer   data);
-void   tool_options_delete_saved_cmd_callback (GtkAction *action,
-                                               gint       value,
-                                               gpointer   data);
+void   tool_options_save_preset_cmd_callback     (GtkAction *action,
+                                                  gint       value,
+                                                  gpointer   data);
+void   tool_options_restore_preset_cmd_callback  (GtkAction *action,
+                                                  gint       value,
+                                                  gpointer   data);
+void   tool_options_edit_preset_cmd_callback     (GtkAction *action,
+                                                  gint       value,
+                                                  gpointer   data);
+void   tool_options_delete_preset_cmd_callback   (GtkAction *action,
+                                                  gint       value,
+                                                  gpointer   data);
 
-void   tool_options_reset_cmd_callback        (GtkAction *action,
-                                               gpointer   data);
-void   tool_options_reset_all_cmd_callback    (GtkAction *action,
-                                               gpointer   data);
+void   tool_options_reset_cmd_callback           (GtkAction *action,
+                                                  gpointer   data);
+void   tool_options_reset_all_cmd_callback       (GtkAction *action,
+                                                  gpointer   data);
 
 
 #endif /* __TOOL_OPTIONS_COMMANDS_H__ */
diff --git a/app/core/Makefile.am b/app/core/Makefile.am
index 89e6253..c51b10f 100644
--- a/app/core/Makefile.am
+++ b/app/core/Makefile.am
@@ -367,8 +367,6 @@ libappcore_a_sources = \
 	gimptoolpreset-load.h			\
 	gimptoolpreset-save.c			\
 	gimptoolpreset-save.h			\
-	gimptoolpresets.c			\
-	gimptoolpresets.h			\
 	gimptreehandler.c			\
 	gimptreehandler.h			\
 	gimpunit.c				\
diff --git a/app/core/core-types.h b/app/core/core-types.h
index d164483..3990ace 100644
--- a/app/core/core-types.h
+++ b/app/core/core-types.h
@@ -73,7 +73,6 @@ typedef struct _GimpDrawableStack     GimpDrawableStack;
 typedef struct _GimpFilteredContainer GimpFilteredContainer;
 typedef struct _GimpItemStack         GimpItemStack;
 typedef struct _GimpTaggedContainer   GimpTaggedContainer;
-typedef struct _GimpToolPresets       GimpToolPresets;
 
 
 /*  not really a container  */
diff --git a/app/core/gimptoolinfo.c b/app/core/gimptoolinfo.c
index 93ffb2c..013d82e 100644
--- a/app/core/gimptoolinfo.c
+++ b/app/core/gimptoolinfo.c
@@ -29,13 +29,12 @@
 #include "base/temp-buf.h"
 
 #include "gimp.h"
-#include "gimpcontainer.h"
-#include "gimpcontext.h"
-#include "gimplist.h"
+#include "gimpdatafactory.h"
+#include "gimpfilteredcontainer.h"
 #include "gimppaintinfo.h"
 #include "gimptoolinfo.h"
 #include "gimptooloptions.h"
-#include "gimptoolpresets.h"
+#include "gimptoolpreset.h"
 
 
 enum
@@ -214,6 +213,16 @@ gimp_tool_info_get_description (GimpViewable  *viewable,
   return g_strdup (tool_info->blurb);
 }
 
+static gboolean
+gimp_tool_info_filter_preset (const GimpObject *object,
+                              gpointer          user_data)
+{
+  GimpToolPreset *preset    = GIMP_TOOL_PRESET (object);
+  GimpToolInfo   *tool_info = user_data;
+
+  return preset->tool_options->tool_info == tool_info;
+}
+
 GimpToolInfo *
 gimp_tool_info_new (Gimp                *gimp,
                     GType                tool_type,
@@ -294,7 +303,14 @@ gimp_tool_info_new (Gimp                *gimp,
 
   if (tool_info->tool_options_type != GIMP_TYPE_TOOL_OPTIONS)
     {
-      tool_info->presets = gimp_tool_presets_new (tool_info);
+      GimpContainer *presets;
+
+      presets = gimp_data_factory_get_container (gimp->tool_preset_factory);
+
+      tool_info->presets =
+        gimp_filtered_container_new (presets,
+                                     gimp_tool_info_filter_preset,
+                                     tool_info);
     }
 
   return tool_info;
diff --git a/app/core/gimptoolinfo.h b/app/core/gimptoolinfo.h
index 745384c..aa6c6e4 100644
--- a/app/core/gimptoolinfo.h
+++ b/app/core/gimptoolinfo.h
@@ -55,7 +55,7 @@ struct _GimpToolInfo
   GimpToolOptions     *tool_options;
   GimpPaintInfo       *paint_info;
 
-  GimpToolPresets     *presets;
+  GimpContainer       *presets;
 };
 
 struct _GimpToolInfoClass
diff --git a/app/menus/tool-options-menu.c b/app/menus/tool-options-menu.c
index 60180b7..6cd4e2b 100644
--- a/app/menus/tool-options-menu.c
+++ b/app/menus/tool-options-menu.c
@@ -110,19 +110,19 @@ tool_options_menu_update_after (GimpUIManager *manager,
 
   tool_options_menu_update_presets (manager, merge_id, ui_path,
                                     "Save", "save",
-                                    GIMP_CONTAINER (tool_info->presets));
+                                    tool_info->presets);
 
   tool_options_menu_update_presets (manager, merge_id, ui_path,
                                     "Restore", "restore",
-                                    GIMP_CONTAINER (tool_info->presets));
+                                    tool_info->presets);
 
   tool_options_menu_update_presets (manager, merge_id, ui_path,
-                                    "Rename", "rename",
-                                    GIMP_CONTAINER (tool_info->presets));
+                                    "Edit", "edit",
+                                    tool_info->presets);
 
   tool_options_menu_update_presets (manager, merge_id, ui_path,
                                     "Delete", "delete",
-                                    GIMP_CONTAINER (tool_info->presets));
+                                    tool_info->presets);
 
   gtk_ui_manager_ensure_update (GTK_UI_MANAGER (manager));
 }
@@ -145,7 +145,8 @@ tool_options_menu_update_presets (GimpUIManager *manager,
       gchar *action_name;
       gchar *path;
 
-      action_name = g_strdup_printf ("tool-options-%s-%03d", which_action, i);
+      action_name = g_strdup_printf ("tool-options-%s-preset-%03d",
+                                     which_action, i);
       path        = g_strdup_printf ("%s/%s", ui_path, menu_path);
 
       gtk_ui_manager_add_ui (GTK_UI_MANAGER (manager), merge_id,
diff --git a/app/tools/gimp-tools.c b/app/tools/gimp-tools.c
index 7dbe40d..56e027c 100644
--- a/app/tools/gimp-tools.c
+++ b/app/tools/gimp-tools.c
@@ -30,9 +30,9 @@
 
 #include "core/gimp.h"
 #include "core/gimp-contexts.h"
+#include "core/gimplist.h"
 #include "core/gimptoolinfo.h"
 #include "core/gimptooloptions.h"
-#include "core/gimptoolpresets.h"
 
 #include "gimp-tools.h"
 #include "gimptooloptions-gui.h"
@@ -359,9 +359,6 @@ gimp_tools_restore (Gimp *gimp)
 
       gimp_tools_set_tool_options_gui (tool_info->tool_options,
                                        g_object_ref_sink (options_gui));
-
-      if (tool_info->presets)
-        gimp_tool_presets_load (tool_info->presets, NULL);
     }
 }
 
diff --git a/app/widgets/gimphelp-ids.h b/app/widgets/gimphelp-ids.h
index e8fd264..b03021e 100644
--- a/app/widgets/gimphelp-ids.h
+++ b/app/widgets/gimphelp-ids.h
@@ -414,7 +414,7 @@
 #define GIMP_HELP_TOOL_OPTIONS_DIALOG             "gimp-tool-options-dialog"
 #define GIMP_HELP_TOOL_OPTIONS_SAVE               "gimp-tool-options-save"
 #define GIMP_HELP_TOOL_OPTIONS_RESTORE            "gimp-tool-options-restore"
-#define GIMP_HELP_TOOL_OPTIONS_RENAME             "gimp-tool-options-rename"
+#define GIMP_HELP_TOOL_OPTIONS_EDIT               "gimp-tool-options-edit"
 #define GIMP_HELP_TOOL_OPTIONS_DELETE             "gimp-tool-options-delete"
 #define GIMP_HELP_TOOL_OPTIONS_RESET              "gimp-tool-options-reset"
 
diff --git a/app/widgets/gimptooloptionseditor.c b/app/widgets/gimptooloptionseditor.c
index 6ab8dd1..bc94b50 100644
--- a/app/widgets/gimptooloptionseditor.c
+++ b/app/widgets/gimptooloptionseditor.c
@@ -31,7 +31,6 @@
 #include "core/gimplist.h"
 #include "core/gimptoolinfo.h"
 #include "core/gimptooloptions.h"
-#include "core/gimptoolpresets.h"
 
 #include "gimpdnd.h"
 #include "gimpdocked.h"
@@ -66,9 +65,6 @@ struct _GimpToolOptionsEditorPrivate
   GtkWidget       *reset_button;
 
   GimpToolOptions *visible_tool_options;
-
-  GList           *save_queue;
-  guint            save_idle_id;
 };
 
 
@@ -103,11 +99,7 @@ static void        gimp_tool_options_editor_drop_tool         (GtkWidget
 static void        gimp_tool_options_editor_tool_changed      (GimpContext           *context,
                                                                GimpToolInfo          *tool_info,
                                                                GimpToolOptionsEditor *editor);
-static void        gimp_tool_options_editor_presets_changed   (GimpToolPresets       *presets,
-                                                               GimpToolOptionsEditor *editor);
-static void        gimp_tool_options_editor_presets_update    (GimpToolOptionsEditor *editor,
-                                                               GimpToolPresets       *presets);
-static void        gimp_tool_options_editor_save_presets      (GimpToolOptionsEditor *editor);
+static void        gimp_tool_options_editor_presets_update    (GimpToolOptionsEditor *editor);
 
 
 G_DEFINE_TYPE_WITH_CODE (GimpToolOptionsEditor, gimp_tool_options_editor,
@@ -194,9 +186,6 @@ gimp_tool_options_editor_init (GimpToolOptionsEditor *editor)
   editor->p->options_vbox = gtk_vbox_new (FALSE, 0);
   gtk_container_add (GTK_CONTAINER (viewport), editor->p->options_vbox);
   gtk_widget_show (editor->p->options_vbox);
-
-  editor->p->save_queue   = NULL;
-  editor->p->save_idle_id = 0;
 }
 
 static void
@@ -210,7 +199,7 @@ gimp_tool_options_editor_constructed (GObject *object)
 
   editor->p->save_button =
     gimp_editor_add_button (GIMP_EDITOR (editor), GTK_STOCK_SAVE,
-                            _("Save options to..."),
+                            _("Save Tool Preset..."),
                             GIMP_HELP_TOOL_OPTIONS_SAVE,
                             G_CALLBACK (gimp_tool_options_editor_save_clicked),
                             NULL,
@@ -218,7 +207,7 @@ gimp_tool_options_editor_constructed (GObject *object)
 
   editor->p->restore_button =
     gimp_editor_add_button (GIMP_EDITOR (editor), GTK_STOCK_REVERT_TO_SAVED,
-                            _("Restore options from..."),
+                            _("Restore Tool Preset..."),
                             GIMP_HELP_TOOL_OPTIONS_RESTORE,
                             G_CALLBACK (gimp_tool_options_editor_restore_clicked),
                             NULL,
@@ -226,7 +215,7 @@ gimp_tool_options_editor_constructed (GObject *object)
 
   editor->p->delete_button =
     gimp_editor_add_button (GIMP_EDITOR (editor), GTK_STOCK_DELETE,
-                            _("Delete saved options..."),
+                            _("Delete Tool Preset..."),
                             GIMP_HELP_TOOL_OPTIONS_DELETE,
                             G_CALLBACK (gimp_tool_options_editor_delete_clicked),
                             NULL,
@@ -275,8 +264,6 @@ gimp_tool_options_editor_dispose (GObject *object)
       editor->p->options_vbox = NULL;
     }
 
-  gimp_tool_options_editor_save_presets (editor);
-
   G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
@@ -430,7 +417,7 @@ gimp_tool_options_editor_save_clicked (GtkWidget             *widget,
     {
       gimp_ui_manager_activate_action (GIMP_EDITOR (editor)->ui_manager,
                                        "tool-options",
-                                       "tool-options-save-new");
+                                       "tool-options-save-new-preset");
     }
 }
 
@@ -470,8 +457,8 @@ gimp_tool_options_editor_tool_changed (GimpContext           *context,
                                        GimpToolInfo          *tool_info,
                                        GimpToolOptionsEditor *editor)
 {
-  GimpToolPresets *presets;
-  GtkWidget       *options_gui;
+  GimpContainer *presets;
+  GtkWidget     *options_gui;
 
   if (tool_info && tool_info->tool_options == editor->p->visible_tool_options)
     return;
@@ -482,7 +469,7 @@ gimp_tool_options_editor_tool_changed (GimpContext           *context,
 
       if (presets)
         g_signal_handlers_disconnect_by_func (presets,
-                                              gimp_tool_options_editor_presets_changed,
+                                              gimp_tool_options_editor_presets_update,
                                               editor);
 
       options_gui = gimp_tools_get_tool_options_gui (editor->p->visible_tool_options);
@@ -498,9 +485,17 @@ gimp_tool_options_editor_tool_changed (GimpContext           *context,
       presets = tool_info->presets;
 
       if (presets)
-        g_signal_connect_object (presets, "changed",
-                                 G_CALLBACK (gimp_tool_options_editor_presets_changed),
-                                 G_OBJECT (editor), 0);
+        {
+          g_signal_connect_object (presets, "add",
+                                   G_CALLBACK (gimp_tool_options_editor_presets_update),
+                                   G_OBJECT (editor), G_CONNECT_SWAPPED);
+          g_signal_connect_object (presets, "remove",
+                                   G_CALLBACK (gimp_tool_options_editor_presets_update),
+                                   G_OBJECT (editor), G_CONNECT_SWAPPED);
+          g_signal_connect_object (presets, "thaw",
+                                   G_CALLBACK (gimp_tool_options_editor_presets_update),
+                                   G_OBJECT (editor), G_CONNECT_SWAPPED);
+        }
 
       options_gui = gimp_tools_get_tool_options_gui (tool_info->tool_options);
 
@@ -515,12 +510,8 @@ gimp_tool_options_editor_tool_changed (GimpContext           *context,
       gimp_help_set_help_data (editor->p->scrolled_window, NULL,
                                tool_info->help_id);
     }
-  else
-    {
-      presets = NULL;
-    }
 
-  gimp_tool_options_editor_presets_update (editor, presets);
+  gimp_tool_options_editor_presets_update (editor);
 
   if (editor->p->title_label != NULL)
     {
@@ -534,87 +525,21 @@ gimp_tool_options_editor_tool_changed (GimpContext           *context,
   gimp_docked_title_changed (GIMP_DOCKED (editor));
 }
 
-static gboolean
-gimp_tool_options_editor_save_presets_idle (GimpToolOptionsEditor *editor)
-{
-  editor->p->save_idle_id = 0;
-
-  gimp_tool_options_editor_save_presets (editor);
-
-  return FALSE;
-}
-
-static void
-gimp_tool_options_editor_queue_save_presets (GimpToolOptionsEditor *editor,
-                                             GimpToolPresets       *presets)
-{
-  if (g_list_find (editor->p->save_queue, presets))
-    return;
-
-  editor->p->save_queue = g_list_append (editor->p->save_queue, presets);
-
-  if (! editor->p->save_idle_id)
-    {
-      editor->p->save_idle_id =
-        g_idle_add ((GSourceFunc) gimp_tool_options_editor_save_presets_idle,
-                    editor);
-    }
-}
-
-static void
-gimp_tool_options_editor_save_presets (GimpToolOptionsEditor *editor)
-{
-  GList *list;
-
-  if (editor->p->save_idle_id)
-    {
-      g_source_remove (editor->p->save_idle_id);
-      editor->p->save_idle_id = 0;
-    }
-
-  for (list = editor->p->save_queue; list; list = list->next)
-    {
-      GimpToolPresets *presets = list->data;
-      GError          *error   = NULL;
-
-      if (! gimp_tool_presets_save (presets, &error))
-        {
-          gimp_message (editor->p->gimp, G_OBJECT (editor), GIMP_MESSAGE_ERROR,
-                        _("Error saving tool options presets: %s"),
-                        error->message);
-          g_error_free (error);
-        }
-    }
-
-  g_list_free (editor->p->save_queue);
-
-  editor->p->save_queue = NULL;
-}
-
-static void
-gimp_tool_options_editor_presets_changed (GimpToolPresets       *presets,
-                                          GimpToolOptionsEditor *editor)
-{
-  gimp_tool_options_editor_queue_save_presets (editor, presets);
-
-  gimp_tool_options_editor_presets_update (editor, presets);
-}
-
 static void
-gimp_tool_options_editor_presets_update (GimpToolOptionsEditor *editor,
-                                         GimpToolPresets       *presets)
+gimp_tool_options_editor_presets_update (GimpToolOptionsEditor *editor)
 {
-  gboolean save_sensitive    = FALSE;
-  gboolean restore_sensitive = FALSE;
-  gboolean delete_sensitive  = FALSE;
-  gboolean reset_sensitive   = FALSE;
+  GimpToolInfo *tool_info         = editor->p->visible_tool_options->tool_info;
+  gboolean      save_sensitive    = FALSE;
+  gboolean      restore_sensitive = FALSE;
+  gboolean      delete_sensitive  = FALSE;
+  gboolean      reset_sensitive   = FALSE;
 
-  if (presets)
+  if (tool_info->presets)
     {
       save_sensitive  = TRUE;
       reset_sensitive = TRUE;
 
-      if (! gimp_container_is_empty (GIMP_CONTAINER (presets)))
+      if (! gimp_container_is_empty (tool_info->presets))
         {
           restore_sensitive = TRUE;
           delete_sensitive  = TRUE;
diff --git a/menus/tool-options-menu.xml b/menus/tool-options-menu.xml
index 9a3ad35..78e65ee 100644
--- a/menus/tool-options-menu.xml
+++ b/menus/tool-options-menu.xml
@@ -3,13 +3,13 @@
 
 <ui>
   <popup action="tool-options-popup">
-    <menu action="tool-options-save-menu" name="Save">
-      <menuitem action="tool-options-save-new" />
+    <menu action="tool-options-save-preset-menu" name="Save">
+      <menuitem action="tool-options-save-new-preset" />
       <separator />
     </menu>
-    <menu action="tool-options-restore-menu" name="Restore" />
-    <menu action="tool-options-rename-menu" name="Rename" />
-    <menu action="tool-options-delete-menu" name="Delete" />
+    <menu action="tool-options-restore-preset-menu" name="Restore" />
+    <menu action="tool-options-edit-preset-menu" name="Edit" />
+    <menu action="tool-options-delete-preset-menu" name="Delete" />
     <separator />
     <menuitem action="tool-options-reset" />
     <menuitem action="tool-options-reset-all" />



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