From 91195e859392395526e12fd6ffe47610d059c7e5 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Wed, 23 Mar 2011 09:27:29 +0100 Subject: [PATCH] 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 | 200 ++++++++--------- 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, 206 insertions(+), 690 deletions(-) delete mode 100644 app/core/gimptoolpresets.c delete mode 100644 app/core/gimptoolpresets.h diff --git a/app/actions/tool-options-actions.c b/app/actions/tool-options-actions.c index bc0c095c34..10c58197fe 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 02ba368bb2..340c86c85b 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; + GimpEditor *editor = GIMP_EDITOR (user_data); + GimpContext *context = gimp_get_user_context (editor->ui_manager->gimp); + GimpData *data; - context = gimp_get_user_context (editor->ui_manager->gimp); - tool_info = gimp_context_get_tool (context); + data = gimp_data_factory_data_new (context->gimp->tool_preset_factory, + context, _("Untitled")); - 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); + 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); -} - -void -tool_options_rename_saved_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; - - options = gimp_tool_presets_get_options (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); + 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_delete_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) - gimp_container_remove (GIMP_CONTAINER (tool_info->presets), - GIMP_OBJECT (options)); + if (preset) + { + tool_options_show_preset_editor (editor, preset); + } +} + +void +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); + GimpToolPreset *preset; + + preset = (GimpToolPreset *) + gimp_container_get_child_by_index (tool_info->presets, value); + + 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; + GtkWidget *dockable; - copy = gimp_config_duplicate (GIMP_CONFIG (tool_info->tool_options)); + 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 (copy), name); - else - gimp_object_set_static_name (GIMP_OBJECT (copy), _("Saved Options")); - - 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); - - 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 53df61d916..47efda846c 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 89e6253c30..c51b10f66f 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 d16448332a..3990ace662 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 93ffb2c8d3..013d82ede3 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 745384c824..aa6c6e46cb 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/core/gimptoolpresets.c b/app/core/gimptoolpresets.c deleted file mode 100644 index fe54cca952..0000000000 --- a/app/core/gimptoolpresets.c +++ /dev/null @@ -1,320 +0,0 @@ -/* GIMP - The GNU Image Manipulation Program - * Copyright (C) 1995 Spencer Kimball and Peter Mattis - * - * gimptoolpresets.c - * Copyright (C) 2006 Sven Neumann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "config.h" - -#include - -#include -#include - -#include "libgimpbase/gimpbase.h" -#include "libgimpconfig/gimpconfig.h" - -#include "core-types.h" - -#include "gimp.h" -#include "gimpmarshal.h" -#include "gimptoolinfo.h" -#include "gimptooloptions.h" -#include "gimptoolpresets.h" - -#include "gimp-intl.h" - - -enum -{ - CHANGED, - LAST_SIGNAL -}; - -enum -{ - PROP_0, - PROP_TOOL_INFO -}; - - -static void gimp_tool_presets_finalize (GObject *object); -static void gimp_tool_presets_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec); -static void gimp_tool_presets_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec); -static void gimp_tool_presets_add (GimpContainer *container, - GimpObject *object); -static void gimp_tool_presets_remove (GimpContainer *container, - GimpObject *object); -static void gimp_tool_presets_notify (GimpToolPresets *presets); - - -G_DEFINE_TYPE (GimpToolPresets, gimp_tool_presets, GIMP_TYPE_LIST) - -#define parent_class gimp_tool_presets_parent_class - -static guint gimp_tool_presets_signals[LAST_SIGNAL] = { 0 }; - - -static void -gimp_tool_presets_class_init (GimpToolPresetsClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GimpContainerClass *container_class = GIMP_CONTAINER_CLASS (klass); - - gimp_tool_presets_signals[CHANGED] = - g_signal_new ("changed", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (GimpToolPresetsClass, changed), - NULL, NULL, - gimp_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - object_class->set_property = gimp_tool_presets_set_property; - object_class->get_property = gimp_tool_presets_get_property; - object_class->finalize = gimp_tool_presets_finalize; - - container_class->add = gimp_tool_presets_add; - container_class->remove = gimp_tool_presets_remove; - - klass->changed = NULL; - - g_object_class_install_property (object_class, PROP_TOOL_INFO, - g_param_spec_object ("tool-info", - NULL, NULL, - GIMP_TYPE_TOOL_INFO, - G_PARAM_CONSTRUCT_ONLY | - GIMP_PARAM_READWRITE)); -} - -static void -gimp_tool_presets_init (GimpToolPresets *presets) -{ - presets->tool_info = NULL; -} - -static void -gimp_tool_presets_finalize (GObject *object) -{ - GimpToolPresets *presets = GIMP_TOOL_PRESETS (object); - - if (presets->tool_info) - { - g_object_unref (presets->tool_info); - presets->tool_info = NULL; - } - - G_OBJECT_CLASS (parent_class)->finalize (object); -} - -static void -gimp_tool_presets_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - GimpToolPresets *presets = GIMP_TOOL_PRESETS (object); - - switch (property_id) - { - case PROP_TOOL_INFO: - presets->tool_info = g_value_dup_object (value); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -gimp_tool_presets_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - GimpToolPresets *presets = GIMP_TOOL_PRESETS (object); - - switch (property_id) - { - case PROP_TOOL_INFO: - g_value_set_object (value, presets->tool_info); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -gimp_tool_presets_add (GimpContainer *container, - GimpObject *object) -{ - GIMP_CONTAINER_CLASS (parent_class)->add (container, object); - - g_signal_connect_swapped (object, "notify", - G_CALLBACK (gimp_tool_presets_notify), - container); - - g_signal_emit (container, gimp_tool_presets_signals[CHANGED], 0); -} - -static void -gimp_tool_presets_remove (GimpContainer *container, - GimpObject *object) -{ - g_signal_handlers_disconnect_by_func (object, - G_CALLBACK (gimp_tool_presets_notify), - container); - - GIMP_CONTAINER_CLASS (parent_class)->remove (container, object); - - g_signal_emit (container, gimp_tool_presets_signals[CHANGED], 0); -} - -static void -gimp_tool_presets_notify (GimpToolPresets *presets) -{ - g_signal_emit (presets, gimp_tool_presets_signals[CHANGED], 0); -} - -GimpToolPresets * -gimp_tool_presets_new (GimpToolInfo *tool_info) -{ - GimpToolPresets *presets; - gchar *name; - - g_return_val_if_fail (GIMP_IS_TOOL_INFO (tool_info), NULL); - - presets = g_object_new (GIMP_TYPE_TOOL_PRESETS, - "tool-info", tool_info, - "children-type", tool_info->tool_options_type, - "policy", GIMP_CONTAINER_POLICY_STRONG, - NULL); - - name = g_strdup_printf ("%s options", gimp_object_get_name (tool_info)); - - gimp_object_take_name (GIMP_OBJECT (presets), name); - - return presets; -} - -GimpToolOptions * -gimp_tool_presets_get_options (GimpToolPresets *presets, - gint index) -{ - g_return_val_if_fail (GIMP_IS_TOOL_PRESETS (presets), NULL); - - return (GimpToolOptions *) - gimp_container_get_child_by_index (GIMP_CONTAINER (presets), index); -} - -gboolean -gimp_tool_presets_save (GimpToolPresets *presets, - GError **error) -{ - Gimp *gimp; - gchar *filename; - gboolean retval = TRUE; - - g_return_val_if_fail (GIMP_IS_TOOL_PRESETS (presets), FALSE); - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - gimp = presets->tool_info->gimp; - - filename = gimp_tool_info_build_options_filename (presets->tool_info, - ".presets"); - - if (! gimp_container_is_empty (GIMP_CONTAINER (presets))) - { - gchar *footer; - - if (gimp->be_verbose) - g_print ("Writing '%s'\n", gimp_filename_to_utf8 (filename)); - - gimp_tool_options_create_folder (); - - footer = g_strdup_printf ("end of %s", gimp_object_get_name (presets)); - - retval = gimp_config_serialize_to_file (GIMP_CONFIG (presets), filename, - gimp_object_get_name (presets), - footer, - NULL, error); - - g_free (footer); - } - else if (g_file_test (filename, G_FILE_TEST_EXISTS)) - { - if (gimp->be_verbose) - g_print ("Deleting '%s'\n", gimp_filename_to_utf8 (filename)); - - if (g_unlink (filename) != 0 && errno != ENOENT) - { - retval = FALSE; - - g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno), - _("Could not delete '%s': %s"), - gimp_filename_to_utf8 (filename), g_strerror (errno)); - } - } - - g_free (filename); - - return retval; -} - -gboolean -gimp_tool_presets_load (GimpToolPresets *presets, - GError **error) -{ - Gimp *gimp; - GList *list; - gchar *filename; - gboolean retval = TRUE; - - g_return_val_if_fail (GIMP_IS_TOOL_PRESETS (presets), FALSE); - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - gimp = presets->tool_info->gimp; - - gimp_container_clear (GIMP_CONTAINER (presets)); - - filename = gimp_tool_info_build_options_filename (presets->tool_info, - ".presets"); - - if (gimp->be_verbose) - g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename)); - - retval = gimp_config_deserialize_file (GIMP_CONFIG (presets), filename, gimp, - error); - - g_free (filename); - - gimp_list_reverse (GIMP_LIST (presets)); - - for (list = GIMP_LIST (presets)->list; list; list = g_list_next (list)) - g_object_set (list->data, "tool-info", presets->tool_info, NULL); - - return retval; -} diff --git a/app/core/gimptoolpresets.h b/app/core/gimptoolpresets.h deleted file mode 100644 index 695dc7af0e..0000000000 --- a/app/core/gimptoolpresets.h +++ /dev/null @@ -1,66 +0,0 @@ -/* GIMP - The GNU Image Manipulation Program - * Copyright (C) 1995 Spencer Kimball and Peter Mattis - * - * gimptoolpresets.h - * Copyright (C) 2006 Sven Neumann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef __GIMP_TOOL_PRESETS_H__ -#define __GIMP_TOOL_PRESETS_H__ - - -#include "core/gimplist.h" - - -#define GIMP_TYPE_TOOL_PRESETS (gimp_tool_presets_get_type ()) -#define GIMP_TOOL_PRESETS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_TOOL_PRESETS, GimpToolPresets)) -#define GIMP_TOOL_PRESETS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_TOOL_PRESETS, GimpToolPresetsClass)) -#define GIMP_IS_TOOL_PRESETS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_TOOL_PRESETS)) -#define GIMP_IS_TOOL_PRESETS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_TOOL_PRESETS)) -#define GIMP_TOOL_PRESETS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_TOOL_PRESETS, GimpToolPresetsClass)) - - -typedef struct _GimpToolPresetsClass GimpToolPresetsClass; - -struct _GimpToolPresets -{ - GimpList parent_instance; - - GimpToolInfo *tool_info; -}; - -struct _GimpToolPresetsClass -{ - GimpListClass parent_class; - - void (* changed) (GimpToolPresets *presets); -}; - - -GType gimp_tool_presets_get_type (void) G_GNUC_CONST; - -GimpToolPresets * gimp_tool_presets_new (GimpToolInfo *tool_info); - -GimpToolOptions * gimp_tool_presets_get_options (GimpToolPresets *presets, - gint index); - -gboolean gimp_tool_presets_save (GimpToolPresets *presets, - GError **error); -gboolean gimp_tool_presets_load (GimpToolPresets *presets, - GError **error); - - -#endif /* __GIMP_TOOL_PRESETS_H__ */ diff --git a/app/menus/tool-options-menu.c b/app/menus/tool-options-menu.c index 60180b77e4..6cd4e2bc2a 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 7dbe40d4fc..56e027c0c0 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 e8fd264a23..b03021e2ba 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 6ab8dd115a..bc94b50da6 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) +gimp_tool_options_editor_presets_update (GimpToolOptionsEditor *editor) { - if (g_list_find (editor->p->save_queue, presets)) - return; + 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; - 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) -{ - 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 9a3ad35dab..78e65ee31d 100644 --- a/menus/tool-options-menu.xml +++ b/menus/tool-options-menu.xml @@ -3,13 +3,13 @@ - - + + - - - + + +