From d1ba870458d7f20557151dc16aa2ceb6eb4c6d70 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Mon, 29 Sep 2003 20:26:09 +0000 Subject: [PATCH] added a GimpContainer of tool options presets. 2003-09-29 Michael Natterer * app/core/gimptoolinfo.[ch]: added a GimpContainer of tool options presets. * app/core/gimptooloptions.[ch] (gimp_tool_options_set_property): silently accept setting the *same* tool_info again. (gimp_tool_options_build_filename): is public now. * app/tools/gimp-tools.c (gimp_tools_restore,save): load and save the presets container. * app/gui/tool-options-dialog.[ch]: removed. * app/gui/tool-options-commands.[ch] * app/gui/tool-options-menu.[ch]: new files implementing a menu for the new GimpToolOptionsEditor widget. Has submenus for saving, loading, and deleting tool options to/from the tool_info->options_presets container. * app/gui/Makefile.am * app/gui/dialogs-constructors.c * app/gui/menus.c: changed accordingly. * app/widgets/Makefile.am * app/widgets/widgets-types.h * app/widgets/gimptooloptionseditor.[ch]: the tool options dialog as proper widget. The "Load" and "Save" buttons still do the same stuff as before. Will make them use the new presets since making them do something useful was the reason for this whole change. * app/widgets/gimphelp-ids.h: added missing help IDs for the tool options dialog. --- ChangeLog | 35 ++ app/actions/tool-options-commands.c | 200 +++++++++ app/actions/tool-options-commands.h | 43 ++ app/core/gimptoolinfo.c | 24 +- app/core/gimptoolinfo.h | 2 + app/core/gimptooloptions.c | 18 +- app/core/gimptooloptions.h | 18 +- app/dialogs/dialogs-constructors.c | 7 +- app/gui/Makefile.am | 6 +- app/gui/dialogs-constructors.c | 7 +- app/gui/menus.c | 8 + app/gui/tool-options-commands.c | 200 +++++++++ app/gui/tool-options-commands.h | 43 ++ app/gui/tool-options-dialog.c | 293 ------------- app/gui/tool-options-menu.c | 209 +++++++++ ...l-options-dialog.h => tool-options-menu.h} | 13 +- app/menus/menus.c | 8 + app/menus/tool-options-menu.c | 209 +++++++++ app/menus/tool-options-menu.h | 31 ++ app/tools/gimp-tools.c | 52 ++- app/widgets/Makefile.am | 2 + app/widgets/gimphelp-ids.h | 2 + app/widgets/gimptooloptionseditor.c | 408 ++++++++++-------- app/widgets/gimptooloptionseditor.h | 66 +++ app/widgets/widgets-types.h | 1 + 25 files changed, 1395 insertions(+), 510 deletions(-) create mode 100644 app/actions/tool-options-commands.c create mode 100644 app/actions/tool-options-commands.h create mode 100644 app/gui/tool-options-commands.c create mode 100644 app/gui/tool-options-commands.h delete mode 100644 app/gui/tool-options-dialog.c create mode 100644 app/gui/tool-options-menu.c rename app/gui/{tool-options-dialog.h => tool-options-menu.h} (71%) create mode 100644 app/menus/tool-options-menu.c create mode 100644 app/menus/tool-options-menu.h create mode 100644 app/widgets/gimptooloptionseditor.h diff --git a/ChangeLog b/ChangeLog index 18f55dff1e..5cdc9854f9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,38 @@ +2003-09-29 Michael Natterer + + * app/core/gimptoolinfo.[ch]: added a GimpContainer of tool + options presets. + + * app/core/gimptooloptions.[ch] (gimp_tool_options_set_property): + silently accept setting the *same* tool_info again. + + (gimp_tool_options_build_filename): is public now. + + * app/tools/gimp-tools.c (gimp_tools_restore,save): load and save + the presets container. + + * app/gui/tool-options-dialog.[ch]: removed. + + * app/gui/tool-options-commands.[ch] + * app/gui/tool-options-menu.[ch]: new files implementing a menu + for the new GimpToolOptionsEditor widget. Has submenus for saving, + loading, and deleting tool options to/from the + tool_info->options_presets container. + + * app/gui/Makefile.am + * app/gui/dialogs-constructors.c + * app/gui/menus.c: changed accordingly. + + * app/widgets/Makefile.am + * app/widgets/widgets-types.h + * app/widgets/gimptooloptionseditor.[ch]: the tool options dialog + as proper widget. The "Load" and "Save" buttons still do the same + stuff as before. Will make them use the new presets since making + them do something useful was the reason for this whole change. + + * app/widgets/gimphelp-ids.h: added missing help IDs for the tool + options dialog. + 2003-09-29 Michael Natterer Fixed handling of G_PARAM_CONSTRUCT_ONLY properties: diff --git a/app/actions/tool-options-commands.c b/app/actions/tool-options-commands.c new file mode 100644 index 0000000000..13f21b1524 --- /dev/null +++ b/app/actions/tool-options-commands.c @@ -0,0 +1,200 @@ +/* The GIMP -- an image manipulation program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "config.h" + +#include + +#include + +#include "libgimpwidgets/gimpwidgets.h" + +#include "gui-types.h" + +#include "config/gimpconfig.h" +#include "config/gimpconfig-utils.h" + +#include "core/gimp.h" +#include "core/gimplist.h" +#include "core/gimptoolinfo.h" +#include "core/gimptooloptions.h" + +#include "widgets/gimpeditor.h" +#include "widgets/gimphelp-ids.h" +#include "widgets/gimpitemfactory.h" + +#include "tool-options-commands.h" + +#include "gimp-intl.h" + + +/* local function prototypes */ + +static void tool_options_save_callback (GtkWidget *widget, + const gchar *name, + gpointer data); +static void tool_options_reset_all_callback (GtkWidget *widget, + gboolean reset_all, + gpointer data); + + +/* public functions */ + +void +tool_options_save_to_cmd_callback (GtkWidget *widget, + gpointer data, + guint action) +{ + GimpToolOptions *options = GIMP_TOOL_OPTIONS (data); + + gimp_config_copy_properties (G_OBJECT (options->tool_info->tool_options), + G_OBJECT (options)); +} + +void +tool_options_save_new_cmd_callback (GtkWidget *widget, + gpointer data, + guint action) +{ + GimpEditor *editor; + GimpContext *context; + GimpToolInfo *tool_info; + GtkWidget *qbox; + + editor = GIMP_EDITOR (data); + + context = gimp_get_user_context (editor->item_factory->gimp); + tool_info = gimp_context_get_tool (context); + + qbox = gimp_query_string_box (_("Save Tool Options"), + 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 (qbox); +} + +void +tool_options_restore_from_cmd_callback (GtkWidget *widget, + gpointer data, + guint action) +{ + GimpToolOptions *options = GIMP_TOOL_OPTIONS (data); + + gimp_config_copy_properties (G_OBJECT (options), + G_OBJECT (options->tool_info->tool_options)); +} + +void +tool_options_delete_saved_cmd_callback (GtkWidget *widget, + gpointer data, + guint action) +{ + GimpToolOptions *options = GIMP_TOOL_OPTIONS (data); + + gimp_container_remove (options->tool_info->options_presets, + GIMP_OBJECT (options)); +} + +void +tool_options_reset_cmd_callback (GtkWidget *widget, + gpointer data, + guint action) +{ + GimpEditor *editor; + GimpContext *context; + GimpToolInfo *tool_info; + + editor = GIMP_EDITOR (data); + + context = gimp_get_user_context (editor->item_factory->gimp); + tool_info = gimp_context_get_tool (context); + + gimp_tool_options_reset (tool_info->tool_options); +} + +void +tool_options_reset_all_cmd_callback (GtkWidget *widget, + gpointer data, + guint action) +{ + GimpEditor *editor; + GtkWidget *qbox; + + editor = GIMP_EDITOR (data); + + qbox = gimp_query_boolean_box (_("Reset Tool Options"), + gimp_standard_help_func, + GIMP_HELP_TOOL_OPTIONS_RESET, + GTK_STOCK_DIALOG_QUESTION, + _("Do you really want to reset all\n" + "tool options to default values?"), + GIMP_STOCK_RESET, GTK_STOCK_CANCEL, + G_OBJECT (editor), "unmap", + tool_options_reset_all_callback, + editor->item_factory->gimp); + gtk_widget_show (qbox); +} + + +/* private functions */ + +static void +tool_options_save_callback (GtkWidget *widget, + const gchar *name, + gpointer data) +{ + GimpToolInfo *tool_info = GIMP_TOOL_INFO (data); + GObject *copy; + + if (! name || ! strlen (name)) + name = _("Saved Options"); + + copy = gimp_config_duplicate (G_OBJECT (tool_info->tool_options)); + + gimp_object_set_name (GIMP_OBJECT (copy), name); + gimp_list_uniquefy_name (GIMP_LIST (tool_info->options_presets), + GIMP_OBJECT (copy), TRUE); + + gimp_container_insert (tool_info->options_presets, GIMP_OBJECT (copy), -1); + g_object_unref (copy); +} + +static void +tool_options_reset_all_callback (GtkWidget *widget, + gboolean reset_all, + gpointer data) +{ + Gimp *gimp = GIMP (data); + + if (reset_all) + { + GList *list; + + for (list = GIMP_LIST (gimp->tool_info_list)->list; + list; + list = g_list_next (list)) + { + GimpToolInfo *tool_info = list->data; + + gimp_tool_options_reset (tool_info->tool_options); + } + } +} diff --git a/app/actions/tool-options-commands.h b/app/actions/tool-options-commands.h new file mode 100644 index 0000000000..70de5774d0 --- /dev/null +++ b/app/actions/tool-options-commands.h @@ -0,0 +1,43 @@ +/* The GIMP -- an image manipulation program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __TOOL_OPTIONS_COMMANDS_H__ +#define __TOOL_OPTIONS_COMMANDS_H__ + + +void tool_options_save_to_cmd_callback (GtkWidget *widget, + gpointer data, + guint action); +void tool_options_save_new_cmd_callback (GtkWidget *widget, + gpointer data, + guint action); +void tool_options_restore_from_cmd_callback (GtkWidget *widget, + gpointer data, + guint action); +void tool_options_delete_saved_cmd_callback (GtkWidget *widget, + gpointer data, + guint action); +void tool_options_reset_cmd_callback (GtkWidget *widget, + gpointer data, + guint action); +void tool_options_reset_all_cmd_callback (GtkWidget *widget, + gpointer data, + guint action); + + +#endif /* __TOOL_OPTIONS_COMMANDS_H__ */ diff --git a/app/core/gimptoolinfo.c b/app/core/gimptoolinfo.c index a08376f48e..7a2d7efb8d 100644 --- a/app/core/gimptoolinfo.c +++ b/app/core/gimptoolinfo.c @@ -29,16 +29,18 @@ #include "gimp.h" #include "gimpcontainer.h" #include "gimpcontext.h" +#include "gimplist.h" #include "gimppaintinfo.h" #include "gimptoolinfo.h" +#include "gimptooloptions.h" -static void gimp_tool_info_class_init (GimpToolInfoClass *klass); -static void gimp_tool_info_init (GimpToolInfo *tool_info); +static void gimp_tool_info_class_init (GimpToolInfoClass *klass); +static void gimp_tool_info_init (GimpToolInfo *tool_info); -static void gimp_tool_info_finalize (GObject *object); -static gchar * gimp_tool_info_get_description (GimpViewable *viewable, - gchar **tooltip); +static void gimp_tool_info_finalize (GObject *object); +static gchar * gimp_tool_info_get_description (GimpViewable *viewable, + gchar **tooltip); static GimpDataClass *parent_class = NULL; @@ -157,6 +159,12 @@ gimp_tool_info_finalize (GObject *object) tool_info->tool_options = NULL; } + if (tool_info->options_presets) + { + g_object_unref (tool_info->options_presets); + tool_info->options_presets = NULL; + } + G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -242,6 +250,12 @@ gimp_tool_info_new (Gimp *gimp, g_object_set (tool_info->tool_options, "tool-info", tool_info, NULL); + if (tool_info->tool_options_type != GIMP_TYPE_TOOL_OPTIONS) + { + tool_info->options_presets = gimp_list_new (tool_info->tool_options_type, + GIMP_CONTAINER_POLICY_STRONG); + } + return tool_info; } diff --git a/app/core/gimptoolinfo.h b/app/core/gimptoolinfo.h index f409888c4a..156d15aede 100644 --- a/app/core/gimptoolinfo.h +++ b/app/core/gimptoolinfo.h @@ -55,6 +55,8 @@ struct _GimpToolInfo gboolean in_toolbox; GimpToolOptions *tool_options; GimpPaintInfo *paint_info; + + GimpContainer *options_presets; }; struct _GimpToolInfoClass diff --git a/app/core/gimptooloptions.c b/app/core/gimptooloptions.c index d91becccf7..58da6e9295 100644 --- a/app/core/gimptooloptions.c +++ b/app/core/gimptooloptions.c @@ -124,8 +124,15 @@ gimp_tool_options_set_property (GObject *object, switch (property_id) { case PROP_TOOL_INFO: - g_return_if_fail (options->tool_info == NULL); - options->tool_info = GIMP_TOOL_INFO (g_value_dup_object (value)); + { + GimpToolInfo *tool_info = GIMP_TOOL_INFO (g_value_get_object (value)); + + g_return_if_fail (options->tool_info == NULL || + options->tool_info == tool_info); + + if (! options->tool_info) + options->tool_info = GIMP_TOOL_INFO (g_value_dup_object (value)); + } break; default: @@ -170,15 +177,18 @@ gimp_tool_options_reset (GimpToolOptions *tool_options) GIMP_TOOL_OPTIONS_GET_CLASS (tool_options)->reset (tool_options); } -static gchar * +gchar * gimp_tool_options_build_filename (GimpToolOptions *tool_options, const gchar *extension) { - gchar *basename; gchar *filename; + g_return_val_if_fail (GIMP_IS_TOOL_OPTIONS (tool_options), NULL); + if (extension) { + gchar *basename; + basename = g_strconcat (GIMP_OBJECT (tool_options->tool_info)->name, ".", extension, NULL); diff --git a/app/core/gimptooloptions.h b/app/core/gimptooloptions.h index 524cb1e338..2bad02d940 100644 --- a/app/core/gimptooloptions.h +++ b/app/core/gimptooloptions.h @@ -48,16 +48,18 @@ struct _GimpToolOptionsClass }; -GType gimp_tool_options_get_type (void) G_GNUC_CONST; +GType gimp_tool_options_get_type (void) G_GNUC_CONST; -void gimp_tool_options_reset (GimpToolOptions *tool_options); +void gimp_tool_options_reset (GimpToolOptions *tool_options); -gboolean gimp_tool_options_serialize (GimpToolOptions *tool_options, - const gchar *extension, - GError **error); -gboolean gimp_tool_options_deserialize (GimpToolOptions *tool_options, - const gchar *extension, - GError **error); +gchar * gimp_tool_options_build_filename (GimpToolOptions *tool_options, + const gchar *extension); +gboolean gimp_tool_options_serialize (GimpToolOptions *tool_options, + const gchar *extension, + GError **error); +gboolean gimp_tool_options_deserialize (GimpToolOptions *tool_options, + const gchar *extension, + GError **error); #endif /* __GIMP_TOOL_OPTIONS_H__ */ diff --git a/app/dialogs/dialogs-constructors.c b/app/dialogs/dialogs-constructors.c index c4c5175596..80a480ab61 100644 --- a/app/dialogs/dialogs-constructors.c +++ b/app/dialogs/dialogs-constructors.c @@ -66,6 +66,7 @@ #include "widgets/gimpselectioneditor.h" #include "widgets/gimptemplateview.h" #include "widgets/gimptoolbox.h" +#include "widgets/gimptooloptionseditor.h" #include "widgets/gimpundoeditor.h" #include "widgets/gimpvectorstreeview.h" @@ -85,7 +86,6 @@ #include "preferences-dialog.h" #include "templates-commands.h" #include "tips-dialog.h" -#include "tool-options-dialog.h" #include "vectors-commands.h" #include "gimp-intl.h" @@ -251,7 +251,7 @@ dialogs_tool_options_get (GimpDialogFactory *factory, if (view) return NULL; - view = tool_options_dialog_create (context->gimp); + view = gimp_tool_options_editor_new (context->gimp, factory->menu_factory); g_object_add_weak_pointer (G_OBJECT (view), (gpointer *) &view); @@ -260,7 +260,8 @@ dialogs_tool_options_get (GimpDialogFactory *factory, GIMP_STOCK_TOOL_OPTIONS, GIMP_HELP_TOOL_OPTIONS_DIALOG, dialogs_tool_options_preview_func, NULL, - NULL, NULL); + NULL, + dialogs_get_view_menu_func); } GtkWidget * diff --git a/app/gui/Makefile.am b/app/gui/Makefile.am index cfcaf40ca1..c190b985e3 100644 --- a/app/gui/Makefile.am +++ b/app/gui/Makefile.am @@ -59,8 +59,6 @@ dialogs_sources = \ tips-dialog.h \ tips-parser.c \ tips-parser.h \ - tool-options-dialog.c \ - tool-options-dialog.h \ user-install-dialog.c \ user-install-dialog.h @@ -149,6 +147,10 @@ menus_sources = \ qmask-menu.h \ select-commands.c \ select-commands.h \ + tool-options-menu.c \ + tool-options-menu.h \ + tool-options-commands.c \ + tool-options-commands.h \ toolbox-menu.c \ toolbox-menu.h \ tools-commands.c \ diff --git a/app/gui/dialogs-constructors.c b/app/gui/dialogs-constructors.c index c4c5175596..80a480ab61 100644 --- a/app/gui/dialogs-constructors.c +++ b/app/gui/dialogs-constructors.c @@ -66,6 +66,7 @@ #include "widgets/gimpselectioneditor.h" #include "widgets/gimptemplateview.h" #include "widgets/gimptoolbox.h" +#include "widgets/gimptooloptionseditor.h" #include "widgets/gimpundoeditor.h" #include "widgets/gimpvectorstreeview.h" @@ -85,7 +86,6 @@ #include "preferences-dialog.h" #include "templates-commands.h" #include "tips-dialog.h" -#include "tool-options-dialog.h" #include "vectors-commands.h" #include "gimp-intl.h" @@ -251,7 +251,7 @@ dialogs_tool_options_get (GimpDialogFactory *factory, if (view) return NULL; - view = tool_options_dialog_create (context->gimp); + view = gimp_tool_options_editor_new (context->gimp, factory->menu_factory); g_object_add_weak_pointer (G_OBJECT (view), (gpointer *) &view); @@ -260,7 +260,8 @@ dialogs_tool_options_get (GimpDialogFactory *factory, GIMP_STOCK_TOOL_OPTIONS, GIMP_HELP_TOOL_OPTIONS_DIALOG, dialogs_tool_options_preview_func, NULL, - NULL, NULL); + NULL, + dialogs_get_view_menu_func); } GtkWidget * diff --git a/app/gui/menus.c b/app/gui/menus.c index 6eb24fdcaf..dc538d4a37 100644 --- a/app/gui/menus.c +++ b/app/gui/menus.c @@ -58,6 +58,7 @@ #include "patterns-menu.h" #include "qmask-menu.h" #include "templates-menu.h" +#include "tool-options-menu.h" #include "toolbox-menu.h" #include "vectors-menu.h" @@ -254,6 +255,13 @@ menus_init (Gimp *gimp) NULL, error_console_menu_update, TRUE, n_error_console_menu_entries, error_console_menu_entries); + + gimp_menu_factory_menu_register (global_menu_factory, "", + _("Tool Options Menu"), + GIMP_HELP_TOOL_OPTIONS_DIALOG, + NULL, tool_options_menu_update, TRUE, + n_tool_options_menu_entries, + tool_options_menu_entries); } void diff --git a/app/gui/tool-options-commands.c b/app/gui/tool-options-commands.c new file mode 100644 index 0000000000..13f21b1524 --- /dev/null +++ b/app/gui/tool-options-commands.c @@ -0,0 +1,200 @@ +/* The GIMP -- an image manipulation program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "config.h" + +#include + +#include + +#include "libgimpwidgets/gimpwidgets.h" + +#include "gui-types.h" + +#include "config/gimpconfig.h" +#include "config/gimpconfig-utils.h" + +#include "core/gimp.h" +#include "core/gimplist.h" +#include "core/gimptoolinfo.h" +#include "core/gimptooloptions.h" + +#include "widgets/gimpeditor.h" +#include "widgets/gimphelp-ids.h" +#include "widgets/gimpitemfactory.h" + +#include "tool-options-commands.h" + +#include "gimp-intl.h" + + +/* local function prototypes */ + +static void tool_options_save_callback (GtkWidget *widget, + const gchar *name, + gpointer data); +static void tool_options_reset_all_callback (GtkWidget *widget, + gboolean reset_all, + gpointer data); + + +/* public functions */ + +void +tool_options_save_to_cmd_callback (GtkWidget *widget, + gpointer data, + guint action) +{ + GimpToolOptions *options = GIMP_TOOL_OPTIONS (data); + + gimp_config_copy_properties (G_OBJECT (options->tool_info->tool_options), + G_OBJECT (options)); +} + +void +tool_options_save_new_cmd_callback (GtkWidget *widget, + gpointer data, + guint action) +{ + GimpEditor *editor; + GimpContext *context; + GimpToolInfo *tool_info; + GtkWidget *qbox; + + editor = GIMP_EDITOR (data); + + context = gimp_get_user_context (editor->item_factory->gimp); + tool_info = gimp_context_get_tool (context); + + qbox = gimp_query_string_box (_("Save Tool Options"), + 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 (qbox); +} + +void +tool_options_restore_from_cmd_callback (GtkWidget *widget, + gpointer data, + guint action) +{ + GimpToolOptions *options = GIMP_TOOL_OPTIONS (data); + + gimp_config_copy_properties (G_OBJECT (options), + G_OBJECT (options->tool_info->tool_options)); +} + +void +tool_options_delete_saved_cmd_callback (GtkWidget *widget, + gpointer data, + guint action) +{ + GimpToolOptions *options = GIMP_TOOL_OPTIONS (data); + + gimp_container_remove (options->tool_info->options_presets, + GIMP_OBJECT (options)); +} + +void +tool_options_reset_cmd_callback (GtkWidget *widget, + gpointer data, + guint action) +{ + GimpEditor *editor; + GimpContext *context; + GimpToolInfo *tool_info; + + editor = GIMP_EDITOR (data); + + context = gimp_get_user_context (editor->item_factory->gimp); + tool_info = gimp_context_get_tool (context); + + gimp_tool_options_reset (tool_info->tool_options); +} + +void +tool_options_reset_all_cmd_callback (GtkWidget *widget, + gpointer data, + guint action) +{ + GimpEditor *editor; + GtkWidget *qbox; + + editor = GIMP_EDITOR (data); + + qbox = gimp_query_boolean_box (_("Reset Tool Options"), + gimp_standard_help_func, + GIMP_HELP_TOOL_OPTIONS_RESET, + GTK_STOCK_DIALOG_QUESTION, + _("Do you really want to reset all\n" + "tool options to default values?"), + GIMP_STOCK_RESET, GTK_STOCK_CANCEL, + G_OBJECT (editor), "unmap", + tool_options_reset_all_callback, + editor->item_factory->gimp); + gtk_widget_show (qbox); +} + + +/* private functions */ + +static void +tool_options_save_callback (GtkWidget *widget, + const gchar *name, + gpointer data) +{ + GimpToolInfo *tool_info = GIMP_TOOL_INFO (data); + GObject *copy; + + if (! name || ! strlen (name)) + name = _("Saved Options"); + + copy = gimp_config_duplicate (G_OBJECT (tool_info->tool_options)); + + gimp_object_set_name (GIMP_OBJECT (copy), name); + gimp_list_uniquefy_name (GIMP_LIST (tool_info->options_presets), + GIMP_OBJECT (copy), TRUE); + + gimp_container_insert (tool_info->options_presets, GIMP_OBJECT (copy), -1); + g_object_unref (copy); +} + +static void +tool_options_reset_all_callback (GtkWidget *widget, + gboolean reset_all, + gpointer data) +{ + Gimp *gimp = GIMP (data); + + if (reset_all) + { + GList *list; + + for (list = GIMP_LIST (gimp->tool_info_list)->list; + list; + list = g_list_next (list)) + { + GimpToolInfo *tool_info = list->data; + + gimp_tool_options_reset (tool_info->tool_options); + } + } +} diff --git a/app/gui/tool-options-commands.h b/app/gui/tool-options-commands.h new file mode 100644 index 0000000000..70de5774d0 --- /dev/null +++ b/app/gui/tool-options-commands.h @@ -0,0 +1,43 @@ +/* The GIMP -- an image manipulation program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __TOOL_OPTIONS_COMMANDS_H__ +#define __TOOL_OPTIONS_COMMANDS_H__ + + +void tool_options_save_to_cmd_callback (GtkWidget *widget, + gpointer data, + guint action); +void tool_options_save_new_cmd_callback (GtkWidget *widget, + gpointer data, + guint action); +void tool_options_restore_from_cmd_callback (GtkWidget *widget, + gpointer data, + guint action); +void tool_options_delete_saved_cmd_callback (GtkWidget *widget, + gpointer data, + guint action); +void tool_options_reset_cmd_callback (GtkWidget *widget, + gpointer data, + guint action); +void tool_options_reset_all_cmd_callback (GtkWidget *widget, + gpointer data, + guint action); + + +#endif /* __TOOL_OPTIONS_COMMANDS_H__ */ diff --git a/app/gui/tool-options-dialog.c b/app/gui/tool-options-dialog.c deleted file mode 100644 index 1cc7a0d934..0000000000 --- a/app/gui/tool-options-dialog.c +++ /dev/null @@ -1,293 +0,0 @@ -/* The GIMP -- an image manipulation program - * Copyright (C) 1995 Spencer Kimball and Peter Mattis - * - * 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 2 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include "config.h" - -#include - -#include "libgimpwidgets/gimpwidgets.h" - -#include "gui-types.h" - -#include "core/gimp.h" -#include "core/gimpcontext.h" -#include "core/gimptoolinfo.h" -#include "core/gimptooloptions.h" - -#include "widgets/gimpdnd.h" -#include "widgets/gimpeditor.h" -#include "widgets/gimphelp-ids.h" - -#include "tool-options-dialog.h" - -#include "gimp-intl.h" - - -/* local function prototypes */ - -static void tool_options_dialog_destroy (GtkWidget *widget, - gpointer data); -static void tool_options_dialog_tool_changed (GimpContext *context, - GimpToolInfo *tool_info, - gpointer data); -static void tool_options_dialog_drop_tool (GtkWidget *widget, - GimpViewable *viewable, - gpointer data); -static void tool_options_dialog_save_callback (GtkWidget *widget, - GimpContext *context); -static void tool_options_dialog_restore_callback (GtkWidget *widget, - GimpContext *context); -static void tool_options_dialog_reset_callback (GtkWidget *widget, - GimpContext *context); - - -/* private variables */ - -static GtkWidget *options_shell = NULL; -static GtkWidget *options_vbox = NULL; - -static GtkWidget *options_save_button = NULL; -static GtkWidget *options_revert_button = NULL; -static GtkWidget *options_reset_button = NULL; - -static GimpToolOptions *visible_tool_options = NULL; - - -/* public functions */ - -GtkWidget * -tool_options_dialog_create (Gimp *gimp) -{ - GimpContext *user_context; - GtkWidget *editor; - GtkWidget *scrolled_win; - - g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL); - - if (options_shell) - return options_shell; - - user_context = gimp_get_user_context (gimp); - - editor = g_object_new (GIMP_TYPE_EDITOR, NULL); - - gtk_widget_set_size_request (editor, -1, 200); - - options_shell = editor; - - g_signal_connect (options_shell, "destroy", - G_CALLBACK (tool_options_dialog_destroy), - NULL); - - options_save_button = - gimp_editor_add_button (GIMP_EDITOR (editor), - GTK_STOCK_SAVE, - _("Save current settings as default values"), - NULL, - G_CALLBACK (tool_options_dialog_save_callback), - NULL, - user_context); - - options_revert_button = - gimp_editor_add_button (GIMP_EDITOR (editor), - GTK_STOCK_REVERT_TO_SAVED, - _("Restore saved default values"), - NULL, - G_CALLBACK (tool_options_dialog_restore_callback), - NULL, - user_context); - - options_reset_button = - gimp_editor_add_button (GIMP_EDITOR (editor), - GIMP_STOCK_RESET, - _("Reset to factory defaults"), - GIMP_HELP_TOOL_OPTIONS_RESET, - G_CALLBACK (tool_options_dialog_reset_callback), - NULL, - user_context); - - scrolled_win = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win), - GTK_POLICY_NEVER, - GTK_POLICY_AUTOMATIC); - gtk_container_add (GTK_CONTAINER (editor), scrolled_win); - gtk_widget_show (scrolled_win); - - /* The vbox containing the tool options */ - options_vbox = gtk_vbox_new (FALSE, 0); - gtk_container_set_border_width (GTK_CONTAINER (options_vbox), 2); - gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_win), - options_vbox); - gtk_widget_show (options_vbox); - - /* dnd stuff */ - gtk_drag_dest_set (options_shell, - GTK_DEST_DEFAULT_ALL, - NULL, 0, - GDK_ACTION_COPY); - gimp_dnd_viewable_dest_add (options_shell, - GIMP_TYPE_TOOL_INFO, - tool_options_dialog_drop_tool, - user_context); - - g_signal_connect_object (user_context, "tool_changed", - G_CALLBACK (tool_options_dialog_tool_changed), - options_shell, - 0); - - tool_options_dialog_tool_changed (user_context, - gimp_context_get_tool (user_context), - options_shell); - - return editor; -} - - -/* private functions */ - -static void -tool_options_dialog_destroy (GtkWidget *widget, - gpointer data) -{ - GList *options; - GList *list; - - options = gtk_container_get_children (GTK_CONTAINER (options_vbox)); - - for (list = options; list; list = g_list_next (list)) - { - g_object_ref (list->data); - gtk_container_remove (GTK_CONTAINER (options_vbox), - GTK_WIDGET (list->data)); - } - - g_list_free (options); - - options_shell = NULL; -} - -static void -tool_options_dialog_tool_changed (GimpContext *context, - GimpToolInfo *tool_info, - gpointer data) -{ - GtkWidget *options_gui; - - if (visible_tool_options && - (! tool_info || tool_info->tool_options != visible_tool_options)) - { - options_gui = g_object_get_data (G_OBJECT (visible_tool_options), - "gimp-tool-options-gui"); - - if (options_gui) - gtk_widget_hide (options_gui); - - visible_tool_options = NULL; - } - - if (tool_info && tool_info->tool_options) - { - options_gui = g_object_get_data (G_OBJECT (tool_info->tool_options), - "gimp-tool-options-gui"); - - if (! options_gui->parent) - gtk_box_pack_start (GTK_BOX (options_vbox), options_gui, - FALSE, FALSE, 0); - - gtk_widget_show (options_gui); - - visible_tool_options = tool_info->tool_options; - - gtk_widget_set_sensitive (options_save_button, TRUE); - gtk_widget_set_sensitive (options_revert_button, TRUE); - gtk_widget_set_sensitive (options_reset_button, TRUE); - } - else - { - gtk_widget_set_sensitive (options_save_button, FALSE); - gtk_widget_set_sensitive (options_revert_button, FALSE); - gtk_widget_set_sensitive (options_reset_button, FALSE); - } -} - -static void -tool_options_dialog_drop_tool (GtkWidget *widget, - GimpViewable *viewable, - gpointer data) -{ - GimpContext *context; - - context = GIMP_CONTEXT (data); - - gimp_context_set_tool (context, GIMP_TOOL_INFO (viewable)); -} - -static void -tool_options_dialog_save_callback (GtkWidget *widget, - GimpContext *context) -{ - GimpToolInfo *tool_info; - GError *error = NULL; - - tool_info = gimp_context_get_tool (context); - - if (! tool_info) - return; - - if (! gimp_tool_options_serialize (tool_info->tool_options, "user", &error)) - { - g_message ("EEK: %s\n", error->message); - g_clear_error (&error); - } -} - -static void -tool_options_dialog_restore_callback (GtkWidget *widget, - GimpContext *context) -{ - GimpToolInfo *tool_info; - - tool_info = gimp_context_get_tool (context); - - if (! tool_info) - return; - - /* Need to reset the tool-options since only the changes - * from the default values are written to disk. - */ - g_object_freeze_notify (G_OBJECT (tool_info->tool_options)); - - gimp_tool_options_reset (tool_info->tool_options); - gimp_tool_options_deserialize (tool_info->tool_options, "user", NULL); - - g_object_thaw_notify (G_OBJECT (tool_info->tool_options)); -} - -static void -tool_options_dialog_reset_callback (GtkWidget *widget, - GimpContext *context) -{ - GimpToolInfo *tool_info; - - tool_info = gimp_context_get_tool (context); - - if (! tool_info) - return; - - gimp_tool_options_reset (tool_info->tool_options); -} diff --git a/app/gui/tool-options-menu.c b/app/gui/tool-options-menu.c new file mode 100644 index 0000000000..fde4cd9837 --- /dev/null +++ b/app/gui/tool-options-menu.c @@ -0,0 +1,209 @@ +/* The GIMP -- an image manipulation program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "config.h" + +#include + +#include "libgimpwidgets/gimpwidgets.h" + +#include "gui-types.h" + +#include "core/gimp.h" +#include "core/gimpcontext.h" +#include "core/gimplist.h" +#include "core/gimptoolinfo.h" + +#include "widgets/gimphelp-ids.h" +#include "widgets/gimpitemfactory.h" + +#include "tool-options-commands.h" +#include "tool-options-menu.h" + +#include "gimp-intl.h" + + +GimpItemFactoryEntry tool_options_menu_entries[] = +{ + { { N_("/Save Options to/New Entry..."), "", + tool_options_save_new_cmd_callback, 0, + "", GTK_STOCK_NEW }, + NULL, + NULL, NULL }, + { { N_("/Save Options to/new-separator"), "", + NULL, 0, + "", NULL }, + NULL, + NULL, NULL }, + + { { N_("/Restore Options from/(None)"), "", + NULL, 0, + "", NULL }, + NULL, + NULL, NULL }, + + { { N_("/Delete Saved Options/(None)"), "", + NULL, 0, + "", NULL }, + NULL, + NULL, NULL }, + + { { "/reset-separator", NULL, NULL, 0, "", NULL }, + NULL, NULL, NULL }, + + { { N_("/Reset Tool Options"), "", + tool_options_reset_cmd_callback, 0, + "", GIMP_STOCK_RESET }, + NULL, + GIMP_HELP_TOOL_OPTIONS_RESET, NULL }, + { { N_("/Reset all Tool Options..."), "", + tool_options_reset_all_cmd_callback, 0, + "", GIMP_STOCK_RESET }, + NULL, + GIMP_HELP_TOOL_OPTIONS_RESET, NULL } +}; + +gint n_tool_options_menu_entries = G_N_ELEMENTS (tool_options_menu_entries); + + +void +tool_options_menu_update (GtkItemFactory *factory, + gpointer data) +{ + GimpContext *context; + GimpToolInfo *tool_info; + GtkWidget *save_menu; + GtkWidget *restore_menu; + GtkWidget *delete_menu; + GList *list; + + context = gimp_get_user_context (GIMP_ITEM_FACTORY (factory)->gimp); + tool_info = gimp_context_get_tool (context); + +#define SET_VISIBLE(menu,condition) \ + gimp_item_factory_set_visible (factory, menu, (condition) != 0) +#define SET_SENSITIVE(menu,condition) \ + gimp_item_factory_set_sensitive (factory, menu, (condition) != 0) + + SET_VISIBLE ("/Save Options to", tool_info->options_presets); + SET_VISIBLE ("/Restore Options from", tool_info->options_presets); + SET_VISIBLE ("/Delete Saved Options", tool_info->options_presets); + SET_VISIBLE ("/reset-separator", tool_info->options_presets); + + SET_SENSITIVE ("/Restore Options from/(None)", FALSE); + SET_SENSITIVE ("/Delete Saved Options/(None)", FALSE); + + if (! tool_info->options_presets) + return; + + save_menu = gtk_item_factory_get_widget (factory, "/Save Options to"); + restore_menu = gtk_item_factory_get_widget (factory, "/Restore Options from"); + delete_menu = gtk_item_factory_get_widget (factory, "/Delete Saved Options"); + + list = g_list_nth (GTK_MENU_SHELL (save_menu)->children, 1); + + while (g_list_next (list)) + gtk_widget_destroy (list->next->data); + + list = g_list_nth (GTK_MENU_SHELL (restore_menu)->children, 0); + + while (g_list_next (list)) + gtk_widget_destroy (list->next->data); + + list = g_list_nth (GTK_MENU_SHELL (delete_menu)->children, 0); + + while (g_list_next (list)) + gtk_widget_destroy (list->next->data); + + if (gimp_container_num_children (tool_info->options_presets)) + { + GimpItemFactoryEntry entry; + GimpToolOptions *options; + + SET_VISIBLE ("/Save Options to/new-separator", TRUE); + SET_VISIBLE ("/Restore Options from/(None)", FALSE); + SET_VISIBLE ("/Delete Saved Options/(None)", FALSE); + + entry.entry.path = NULL; + entry.entry.accelerator = ""; + entry.entry.callback = tool_options_save_to_cmd_callback; + entry.entry.callback_action = 0; + entry.entry.item_type = ""; + entry.entry.extra_data = GTK_STOCK_SAVE; + entry.quark_string = NULL; + entry.help_id = NULL; + entry.description = NULL; + + for (list = GIMP_LIST (tool_info->options_presets)->list; + list; + list = g_list_next (list)) + { + options = list->data; + + entry.entry.path = g_strdup_printf ("/Save Options to/%s", + GIMP_OBJECT (options)->name); + gimp_item_factory_create_item (GIMP_ITEM_FACTORY (factory), + &entry, NULL, + options, 2, FALSE, FALSE); + g_free (entry.entry.path); + } + + entry.entry.callback = tool_options_restore_from_cmd_callback; + entry.entry.extra_data = GTK_STOCK_REVERT_TO_SAVED; + + for (list = GIMP_LIST (tool_info->options_presets)->list; + list; + list = g_list_next (list)) + { + options = list->data; + + entry.entry.path = g_strdup_printf ("/Restore Options from/%s", + GIMP_OBJECT (options)->name); + gimp_item_factory_create_item (GIMP_ITEM_FACTORY (factory), + &entry, NULL, + options, 2, FALSE, FALSE); + g_free (entry.entry.path); + } + + entry.entry.callback = tool_options_delete_saved_cmd_callback; + entry.entry.extra_data = GTK_STOCK_DELETE; + + for (list = GIMP_LIST (tool_info->options_presets)->list; + list; + list = g_list_next (list)) + { + options = list->data; + + entry.entry.path = g_strdup_printf ("/Delete Saved Options/%s", + GIMP_OBJECT (options)->name); + gimp_item_factory_create_item (GIMP_ITEM_FACTORY (factory), + &entry, NULL, + options, 2, FALSE, FALSE); + g_free (entry.entry.path); + } + } + else + { + SET_VISIBLE ("/Save Options to/new-separator", FALSE); + SET_VISIBLE ("/Restore Options from/(None)", TRUE); + SET_VISIBLE ("/Delete Saved Options/(None)", TRUE); + } + +#undef SET_VISIBLE +#undef SET_SENSITIVE +} diff --git a/app/gui/tool-options-dialog.h b/app/gui/tool-options-menu.h similarity index 71% rename from app/gui/tool-options-dialog.h rename to app/gui/tool-options-menu.h index 4a90a1ea32..29e6fd23fe 100644 --- a/app/gui/tool-options-dialog.h +++ b/app/gui/tool-options-menu.h @@ -16,11 +16,16 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef __TOOL_OPTIONS_DIALOG_H__ -#define __TOOL_OPTIONS_DIALOG_H__ +#ifndef __TOOL_OPTIONS_MENU_H__ +#define __TOOL_OPTIONS_MENU_H__ -GtkWidget * tool_options_dialog_create (Gimp *gimp); +extern GimpItemFactoryEntry tool_options_menu_entries[]; +extern gint n_tool_options_menu_entries; -#endif /* __TOOL_OPTIONS_DIALOG_H__ */ +void tool_options_menu_update (GtkItemFactory *factory, + gpointer data); + + +#endif /* __TOOL_OPTIONS_MENU_H__ */ diff --git a/app/menus/menus.c b/app/menus/menus.c index 6eb24fdcaf..dc538d4a37 100644 --- a/app/menus/menus.c +++ b/app/menus/menus.c @@ -58,6 +58,7 @@ #include "patterns-menu.h" #include "qmask-menu.h" #include "templates-menu.h" +#include "tool-options-menu.h" #include "toolbox-menu.h" #include "vectors-menu.h" @@ -254,6 +255,13 @@ menus_init (Gimp *gimp) NULL, error_console_menu_update, TRUE, n_error_console_menu_entries, error_console_menu_entries); + + gimp_menu_factory_menu_register (global_menu_factory, "", + _("Tool Options Menu"), + GIMP_HELP_TOOL_OPTIONS_DIALOG, + NULL, tool_options_menu_update, TRUE, + n_tool_options_menu_entries, + tool_options_menu_entries); } void diff --git a/app/menus/tool-options-menu.c b/app/menus/tool-options-menu.c new file mode 100644 index 0000000000..fde4cd9837 --- /dev/null +++ b/app/menus/tool-options-menu.c @@ -0,0 +1,209 @@ +/* The GIMP -- an image manipulation program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "config.h" + +#include + +#include "libgimpwidgets/gimpwidgets.h" + +#include "gui-types.h" + +#include "core/gimp.h" +#include "core/gimpcontext.h" +#include "core/gimplist.h" +#include "core/gimptoolinfo.h" + +#include "widgets/gimphelp-ids.h" +#include "widgets/gimpitemfactory.h" + +#include "tool-options-commands.h" +#include "tool-options-menu.h" + +#include "gimp-intl.h" + + +GimpItemFactoryEntry tool_options_menu_entries[] = +{ + { { N_("/Save Options to/New Entry..."), "", + tool_options_save_new_cmd_callback, 0, + "", GTK_STOCK_NEW }, + NULL, + NULL, NULL }, + { { N_("/Save Options to/new-separator"), "", + NULL, 0, + "", NULL }, + NULL, + NULL, NULL }, + + { { N_("/Restore Options from/(None)"), "", + NULL, 0, + "", NULL }, + NULL, + NULL, NULL }, + + { { N_("/Delete Saved Options/(None)"), "", + NULL, 0, + "", NULL }, + NULL, + NULL, NULL }, + + { { "/reset-separator", NULL, NULL, 0, "", NULL }, + NULL, NULL, NULL }, + + { { N_("/Reset Tool Options"), "", + tool_options_reset_cmd_callback, 0, + "", GIMP_STOCK_RESET }, + NULL, + GIMP_HELP_TOOL_OPTIONS_RESET, NULL }, + { { N_("/Reset all Tool Options..."), "", + tool_options_reset_all_cmd_callback, 0, + "", GIMP_STOCK_RESET }, + NULL, + GIMP_HELP_TOOL_OPTIONS_RESET, NULL } +}; + +gint n_tool_options_menu_entries = G_N_ELEMENTS (tool_options_menu_entries); + + +void +tool_options_menu_update (GtkItemFactory *factory, + gpointer data) +{ + GimpContext *context; + GimpToolInfo *tool_info; + GtkWidget *save_menu; + GtkWidget *restore_menu; + GtkWidget *delete_menu; + GList *list; + + context = gimp_get_user_context (GIMP_ITEM_FACTORY (factory)->gimp); + tool_info = gimp_context_get_tool (context); + +#define SET_VISIBLE(menu,condition) \ + gimp_item_factory_set_visible (factory, menu, (condition) != 0) +#define SET_SENSITIVE(menu,condition) \ + gimp_item_factory_set_sensitive (factory, menu, (condition) != 0) + + SET_VISIBLE ("/Save Options to", tool_info->options_presets); + SET_VISIBLE ("/Restore Options from", tool_info->options_presets); + SET_VISIBLE ("/Delete Saved Options", tool_info->options_presets); + SET_VISIBLE ("/reset-separator", tool_info->options_presets); + + SET_SENSITIVE ("/Restore Options from/(None)", FALSE); + SET_SENSITIVE ("/Delete Saved Options/(None)", FALSE); + + if (! tool_info->options_presets) + return; + + save_menu = gtk_item_factory_get_widget (factory, "/Save Options to"); + restore_menu = gtk_item_factory_get_widget (factory, "/Restore Options from"); + delete_menu = gtk_item_factory_get_widget (factory, "/Delete Saved Options"); + + list = g_list_nth (GTK_MENU_SHELL (save_menu)->children, 1); + + while (g_list_next (list)) + gtk_widget_destroy (list->next->data); + + list = g_list_nth (GTK_MENU_SHELL (restore_menu)->children, 0); + + while (g_list_next (list)) + gtk_widget_destroy (list->next->data); + + list = g_list_nth (GTK_MENU_SHELL (delete_menu)->children, 0); + + while (g_list_next (list)) + gtk_widget_destroy (list->next->data); + + if (gimp_container_num_children (tool_info->options_presets)) + { + GimpItemFactoryEntry entry; + GimpToolOptions *options; + + SET_VISIBLE ("/Save Options to/new-separator", TRUE); + SET_VISIBLE ("/Restore Options from/(None)", FALSE); + SET_VISIBLE ("/Delete Saved Options/(None)", FALSE); + + entry.entry.path = NULL; + entry.entry.accelerator = ""; + entry.entry.callback = tool_options_save_to_cmd_callback; + entry.entry.callback_action = 0; + entry.entry.item_type = ""; + entry.entry.extra_data = GTK_STOCK_SAVE; + entry.quark_string = NULL; + entry.help_id = NULL; + entry.description = NULL; + + for (list = GIMP_LIST (tool_info->options_presets)->list; + list; + list = g_list_next (list)) + { + options = list->data; + + entry.entry.path = g_strdup_printf ("/Save Options to/%s", + GIMP_OBJECT (options)->name); + gimp_item_factory_create_item (GIMP_ITEM_FACTORY (factory), + &entry, NULL, + options, 2, FALSE, FALSE); + g_free (entry.entry.path); + } + + entry.entry.callback = tool_options_restore_from_cmd_callback; + entry.entry.extra_data = GTK_STOCK_REVERT_TO_SAVED; + + for (list = GIMP_LIST (tool_info->options_presets)->list; + list; + list = g_list_next (list)) + { + options = list->data; + + entry.entry.path = g_strdup_printf ("/Restore Options from/%s", + GIMP_OBJECT (options)->name); + gimp_item_factory_create_item (GIMP_ITEM_FACTORY (factory), + &entry, NULL, + options, 2, FALSE, FALSE); + g_free (entry.entry.path); + } + + entry.entry.callback = tool_options_delete_saved_cmd_callback; + entry.entry.extra_data = GTK_STOCK_DELETE; + + for (list = GIMP_LIST (tool_info->options_presets)->list; + list; + list = g_list_next (list)) + { + options = list->data; + + entry.entry.path = g_strdup_printf ("/Delete Saved Options/%s", + GIMP_OBJECT (options)->name); + gimp_item_factory_create_item (GIMP_ITEM_FACTORY (factory), + &entry, NULL, + options, 2, FALSE, FALSE); + g_free (entry.entry.path); + } + } + else + { + SET_VISIBLE ("/Save Options to/new-separator", FALSE); + SET_VISIBLE ("/Restore Options from/(None)", TRUE); + SET_VISIBLE ("/Delete Saved Options/(None)", TRUE); + } + +#undef SET_VISIBLE +#undef SET_SENSITIVE +} diff --git a/app/menus/tool-options-menu.h b/app/menus/tool-options-menu.h new file mode 100644 index 0000000000..29e6fd23fe --- /dev/null +++ b/app/menus/tool-options-menu.h @@ -0,0 +1,31 @@ +/* The GIMP -- an image manipulation program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __TOOL_OPTIONS_MENU_H__ +#define __TOOL_OPTIONS_MENU_H__ + + +extern GimpItemFactoryEntry tool_options_menu_entries[]; +extern gint n_tool_options_menu_entries; + + +void tool_options_menu_update (GtkItemFactory *factory, + gpointer data); + + +#endif /* __TOOL_OPTIONS_MENU_H__ */ diff --git a/app/tools/gimp-tools.c b/app/tools/gimp-tools.c index 4a7fda3b97..02e8d9737f 100644 --- a/app/tools/gimp-tools.c +++ b/app/tools/gimp-tools.c @@ -24,6 +24,8 @@ #include "tools-types.h" +#include "config/gimpconfig.h" + #include "core/gimp.h" #include "core/gimplist.h" #include "core/gimptoolinfo.h" @@ -182,7 +184,6 @@ gimp_tools_exit (Gimp *gimp) void gimp_tools_restore (Gimp *gimp) { - GimpToolInfo *tool_info; GList *list; g_return_if_fail (GIMP_IS_GIMP (gimp)); @@ -191,6 +192,7 @@ gimp_tools_restore (Gimp *gimp) list; list = g_list_next (list)) { + GimpToolInfo *tool_info; GimpToolOptionsGUIFunc options_gui_func; GtkWidget *options_gui; @@ -218,13 +220,34 @@ gimp_tools_restore (Gimp *gimp) g_object_set_data (G_OBJECT (tool_info->tool_options), "gimp-tool-options-gui", options_gui); + + if (tool_info->options_presets) + { + gchar *filename; + GList *list; + + filename = gimp_tool_options_build_filename (tool_info->tool_options, + "presets"); + gimp_config_deserialize_file (G_OBJECT (tool_info->options_presets), + filename, + gimp, NULL); + g_free (filename); + + gimp_list_reverse (GIMP_LIST (tool_info->options_presets)); + + for (list = GIMP_LIST (tool_info->options_presets)->list; + list; + list = g_list_next (list)) + { + g_object_set (list->data, "tool-info", tool_info, NULL); + } + } } } void gimp_tools_save (Gimp *gimp) { - GimpToolInfo *tool_info; GList *list; g_return_if_fail (GIMP_IS_GIMP (gimp)); @@ -233,9 +256,32 @@ gimp_tools_save (Gimp *gimp) list; list = g_list_next (list)) { - tool_info = GIMP_TOOL_INFO (list->data); + GimpToolInfo *tool_info = GIMP_TOOL_INFO (list->data); gimp_tool_options_serialize (tool_info->tool_options, NULL, NULL); + + if (tool_info->options_presets) + { + gchar *filename; + gchar *header; + gchar *footer; + + filename = gimp_tool_options_build_filename (tool_info->tool_options, + "presets"); + + header = g_strdup_printf ("GIMP %s options presets", + GIMP_OBJECT (tool_info)->name); + footer = g_strdup_printf ("end of %s options presets", + GIMP_OBJECT (tool_info)->name); + + gimp_config_serialize_to_file (G_OBJECT (tool_info->options_presets), + filename, header, footer, + NULL, NULL); + + g_free (filename); + g_free (header); + g_free (footer); + } } } diff --git a/app/widgets/Makefile.am b/app/widgets/Makefile.am index ebb58e85f8..affd340217 100644 --- a/app/widgets/Makefile.am +++ b/app/widgets/Makefile.am @@ -162,6 +162,8 @@ libappwidgets_a_sources = \ gimptoolbox-dnd.h \ gimptoolbox-indicator-area.c \ gimptoolbox-indicator-area.h \ + gimptooloptionseditor.c \ + gimptooloptionseditor.h \ gimpundoeditor.c \ gimpundoeditor.h \ gimpvectorstreeview.c \ diff --git a/app/widgets/gimphelp-ids.h b/app/widgets/gimphelp-ids.h index bb503f1d2c..f69edafc01 100644 --- a/app/widgets/gimphelp-ids.h +++ b/app/widgets/gimphelp-ids.h @@ -325,6 +325,8 @@ #define GIMP_HELP_TEMPLATE_DELETE "gimp-template-delete" #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_RESET "gimp-tool-options-reset" #define GIMP_HELP_ERRORS_DIALOG "gimp-errors-dialog" diff --git a/app/widgets/gimptooloptionseditor.c b/app/widgets/gimptooloptionseditor.c index 1cc7a0d934..8343a10982 100644 --- a/app/widgets/gimptooloptionseditor.c +++ b/app/widgets/gimptooloptionseditor.c @@ -1,6 +1,9 @@ /* The GIMP -- an image manipulation program * Copyright (C) 1995 Spencer Kimball and Peter Mattis * + * gimptooloptionseditor.c + * Copyright (C) 2003 Michael Natterer + * * 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 2 of the License, or @@ -22,104 +25,113 @@ #include "libgimpwidgets/gimpwidgets.h" -#include "gui-types.h" +#include "widgets-types.h" #include "core/gimp.h" #include "core/gimpcontext.h" #include "core/gimptoolinfo.h" #include "core/gimptooloptions.h" -#include "widgets/gimpdnd.h" -#include "widgets/gimpeditor.h" -#include "widgets/gimphelp-ids.h" - -#include "tool-options-dialog.h" +#include "gimpdnd.h" +#include "gimphelp-ids.h" +#include "gimpmenufactory.h" +#include "gimptooloptionseditor.h" #include "gimp-intl.h" -/* local function prototypes */ +static void gimp_tool_options_editor_class_init (GimpToolOptionsEditorClass *klass); +static void gimp_tool_options_editor_init (GimpToolOptionsEditor *editor); -static void tool_options_dialog_destroy (GtkWidget *widget, - gpointer data); -static void tool_options_dialog_tool_changed (GimpContext *context, - GimpToolInfo *tool_info, - gpointer data); -static void tool_options_dialog_drop_tool (GtkWidget *widget, - GimpViewable *viewable, - gpointer data); -static void tool_options_dialog_save_callback (GtkWidget *widget, - GimpContext *context); -static void tool_options_dialog_restore_callback (GtkWidget *widget, - GimpContext *context); -static void tool_options_dialog_reset_callback (GtkWidget *widget, - GimpContext *context); +static void gimp_tool_options_editor_destroy (GtkObject *object); + +static void gimp_tool_options_editor_save_clicked (GtkWidget *widget, + GimpToolOptionsEditor *editor); +static void gimp_tool_options_editor_restore_clicked (GtkWidget *widget, + GimpToolOptionsEditor *editor); +static void gimp_tool_options_editor_reset_clicked (GtkWidget *widget, + GimpToolOptionsEditor *editor); + +static void gimp_tool_options_editor_drop_tool (GtkWidget *widget, + GimpViewable *viewable, + gpointer data); + +static void gimp_tool_options_editor_tool_changed (GimpContext *context, + GimpToolInfo *tool_info, + GimpToolOptionsEditor *editor); -/* private variables */ - -static GtkWidget *options_shell = NULL; -static GtkWidget *options_vbox = NULL; - -static GtkWidget *options_save_button = NULL; -static GtkWidget *options_revert_button = NULL; -static GtkWidget *options_reset_button = NULL; - -static GimpToolOptions *visible_tool_options = NULL; +static GimpEditorClass *parent_class = NULL; -/* public functions */ - -GtkWidget * -tool_options_dialog_create (Gimp *gimp) +GType +gimp_tool_options_editor_get_type (void) { - GimpContext *user_context; - GtkWidget *editor; - GtkWidget *scrolled_win; + static GType editor_type = 0; - g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL); + if (! editor_type) + { + static const GTypeInfo editor_info = + { + sizeof (GimpToolOptionsEditorClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) gimp_tool_options_editor_class_init, + NULL, /* class_finalize */ + NULL, /* class_tool */ + sizeof (GimpToolOptionsEditor), + 0, /* n_preallocs */ + (GInstanceInitFunc) gimp_tool_options_editor_init, + }; - if (options_shell) - return options_shell; + editor_type = g_type_register_static (GIMP_TYPE_EDITOR, + "GimpToolOptionsEditor", + &editor_info, 0); + } - user_context = gimp_get_user_context (gimp); + return editor_type; +} - editor = g_object_new (GIMP_TYPE_EDITOR, NULL); +static void +gimp_tool_options_editor_class_init (GimpToolOptionsEditorClass *klass) +{ + GtkObjectClass *object_class; - gtk_widget_set_size_request (editor, -1, 200); + object_class = GTK_OBJECT_CLASS (klass); - options_shell = editor; + parent_class = g_type_class_peek_parent (klass); - g_signal_connect (options_shell, "destroy", - G_CALLBACK (tool_options_dialog_destroy), - NULL); + object_class->destroy = gimp_tool_options_editor_destroy; +} - options_save_button = - gimp_editor_add_button (GIMP_EDITOR (editor), - GTK_STOCK_SAVE, +static void +gimp_tool_options_editor_init (GimpToolOptionsEditor *editor) +{ + GtkWidget *scrolled_win; + + editor->save_button = + gimp_editor_add_button (GIMP_EDITOR (editor), GTK_STOCK_SAVE, _("Save current settings as default values"), + GIMP_HELP_TOOL_OPTIONS_SAVE, + G_CALLBACK (gimp_tool_options_editor_save_clicked), NULL, - G_CALLBACK (tool_options_dialog_save_callback), - NULL, - user_context); + editor); - options_revert_button = - gimp_editor_add_button (GIMP_EDITOR (editor), - GTK_STOCK_REVERT_TO_SAVED, + editor->restore_button = + gimp_editor_add_button (GIMP_EDITOR (editor), GTK_STOCK_REVERT_TO_SAVED, _("Restore saved default values"), + GIMP_HELP_TOOL_OPTIONS_RESTORE, + G_CALLBACK (gimp_tool_options_editor_restore_clicked), NULL, - G_CALLBACK (tool_options_dialog_restore_callback), - NULL, - user_context); + editor); - options_reset_button = - gimp_editor_add_button (GIMP_EDITOR (editor), - GIMP_STOCK_RESET, + editor->reset_button = + gimp_editor_add_button (GIMP_EDITOR (editor), GIMP_STOCK_RESET, _("Reset to factory defaults"), GIMP_HELP_TOOL_OPTIONS_RESET, - G_CALLBACK (tool_options_dialog_reset_callback), + G_CALLBACK (gimp_tool_options_editor_reset_clicked), NULL, - user_context); + editor); scrolled_win = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win), @@ -129,75 +141,170 @@ tool_options_dialog_create (Gimp *gimp) gtk_widget_show (scrolled_win); /* The vbox containing the tool options */ - options_vbox = gtk_vbox_new (FALSE, 0); - gtk_container_set_border_width (GTK_CONTAINER (options_vbox), 2); + editor->options_vbox = gtk_vbox_new (FALSE, 0); + gtk_container_set_border_width (GTK_CONTAINER (editor->options_vbox), 2); gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_win), - options_vbox); - gtk_widget_show (options_vbox); + editor->options_vbox); + gtk_widget_show (editor->options_vbox); /* dnd stuff */ - gtk_drag_dest_set (options_shell, + gtk_drag_dest_set (GTK_WIDGET (editor), GTK_DEST_DEFAULT_ALL, NULL, 0, GDK_ACTION_COPY); - gimp_dnd_viewable_dest_add (options_shell, + gimp_dnd_viewable_dest_add (GTK_WIDGET (editor), GIMP_TYPE_TOOL_INFO, - tool_options_dialog_drop_tool, - user_context); - - g_signal_connect_object (user_context, "tool_changed", - G_CALLBACK (tool_options_dialog_tool_changed), - options_shell, - 0); - - tool_options_dialog_tool_changed (user_context, - gimp_context_get_tool (user_context), - options_shell); - - return editor; + gimp_tool_options_editor_drop_tool, + editor); } - -/* private functions */ - static void -tool_options_dialog_destroy (GtkWidget *widget, - gpointer data) +gimp_tool_options_editor_destroy (GtkObject *object) { - GList *options; - GList *list; + GimpToolOptionsEditor *editor = GIMP_TOOL_OPTIONS_EDITOR (object); - options = gtk_container_get_children (GTK_CONTAINER (options_vbox)); - - for (list = options; list; list = g_list_next (list)) + if (editor->options_vbox) { - g_object_ref (list->data); - gtk_container_remove (GTK_CONTAINER (options_vbox), - GTK_WIDGET (list->data)); + GList *options; + GList *list; + + options = + gtk_container_get_children (GTK_CONTAINER (editor->options_vbox)); + + for (list = options; list; list = g_list_next (list)) + { + g_object_ref (list->data); + gtk_container_remove (GTK_CONTAINER (editor->options_vbox), + GTK_WIDGET (list->data)); + } + + g_list_free (options); + editor->options_vbox = NULL; } - g_list_free (options); + GTK_OBJECT_CLASS (parent_class)->destroy (object); +} - options_shell = NULL; +GtkWidget * +gimp_tool_options_editor_new (Gimp *gimp, + GimpMenuFactory *menu_factory) +{ + GimpToolOptionsEditor *editor; + GimpContext *user_context; + + g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL); + g_return_val_if_fail (GIMP_IS_MENU_FACTORY (menu_factory), NULL); + + user_context = gimp_get_user_context (gimp); + + editor = g_object_new (GIMP_TYPE_TOOL_OPTIONS_EDITOR, NULL); + + editor->gimp = gimp; + + gtk_widget_set_size_request (GTK_WIDGET (editor), -1, 200); + + gimp_editor_create_menu (GIMP_EDITOR (editor), + menu_factory, "", + editor); + + g_signal_connect_object (user_context, "tool_changed", + G_CALLBACK (gimp_tool_options_editor_tool_changed), + editor, + 0); + + gimp_tool_options_editor_tool_changed (user_context, + gimp_context_get_tool (user_context), + editor); + + return GTK_WIDGET (editor); } static void -tool_options_dialog_tool_changed (GimpContext *context, - GimpToolInfo *tool_info, - gpointer data) +gimp_tool_options_editor_save_clicked (GtkWidget *widget, + GimpToolOptionsEditor *editor) +{ + GimpToolInfo *tool_info; + + tool_info = gimp_context_get_tool (gimp_get_user_context (editor->gimp)); + + if (tool_info) + { + GError *error = NULL; + + if (! gimp_tool_options_serialize (tool_info->tool_options, "user", + &error)) + { + g_message ("EEK: %s\n", error->message); + g_clear_error (&error); + } + } +} + +static void +gimp_tool_options_editor_restore_clicked (GtkWidget *widget, + GimpToolOptionsEditor *editor) +{ + GimpToolInfo *tool_info; + + tool_info = gimp_context_get_tool (gimp_get_user_context (editor->gimp)); + + if (tool_info) + { + /* Need to reset the tool-options since only the changes + * from the default values are written to disk. + */ + g_object_freeze_notify (G_OBJECT (tool_info->tool_options)); + + gimp_tool_options_reset (tool_info->tool_options); + gimp_tool_options_deserialize (tool_info->tool_options, "user", NULL); + + g_object_thaw_notify (G_OBJECT (tool_info->tool_options)); + } +} + +static void +gimp_tool_options_editor_reset_clicked (GtkWidget *widget, + GimpToolOptionsEditor *editor) +{ + GimpToolInfo *tool_info; + + tool_info = gimp_context_get_tool (gimp_get_user_context (editor->gimp)); + + if (tool_info) + gimp_tool_options_reset (tool_info->tool_options); +} + +static void +gimp_tool_options_editor_drop_tool (GtkWidget *widget, + GimpViewable *viewable, + gpointer data) +{ + GimpToolOptionsEditor *editor = GIMP_TOOL_OPTIONS_EDITOR (data); + GimpContext *context; + + context = gimp_get_user_context (editor->gimp); + + gimp_context_set_tool (context, GIMP_TOOL_INFO (viewable)); +} + +static void +gimp_tool_options_editor_tool_changed (GimpContext *context, + GimpToolInfo *tool_info, + GimpToolOptionsEditor *editor) { GtkWidget *options_gui; + gboolean sensitive; - if (visible_tool_options && - (! tool_info || tool_info->tool_options != visible_tool_options)) + if (editor->visible_tool_options && + (! tool_info || tool_info->tool_options != editor->visible_tool_options)) { - options_gui = g_object_get_data (G_OBJECT (visible_tool_options), + options_gui = g_object_get_data (G_OBJECT (editor->visible_tool_options), "gimp-tool-options-gui"); if (options_gui) gtk_widget_hide (options_gui); - visible_tool_options = NULL; + editor->visible_tool_options = NULL; } if (tool_info && tool_info->tool_options) @@ -206,88 +313,19 @@ tool_options_dialog_tool_changed (GimpContext *context, "gimp-tool-options-gui"); if (! options_gui->parent) - gtk_box_pack_start (GTK_BOX (options_vbox), options_gui, + gtk_box_pack_start (GTK_BOX (editor->options_vbox), options_gui, FALSE, FALSE, 0); gtk_widget_show (options_gui); - visible_tool_options = tool_info->tool_options; - - gtk_widget_set_sensitive (options_save_button, TRUE); - gtk_widget_set_sensitive (options_revert_button, TRUE); - gtk_widget_set_sensitive (options_reset_button, TRUE); - } - else - { - gtk_widget_set_sensitive (options_save_button, FALSE); - gtk_widget_set_sensitive (options_revert_button, FALSE); - gtk_widget_set_sensitive (options_reset_button, FALSE); + editor->visible_tool_options = tool_info->tool_options; } -} - -static void -tool_options_dialog_drop_tool (GtkWidget *widget, - GimpViewable *viewable, - gpointer data) -{ - GimpContext *context; - - context = GIMP_CONTEXT (data); - - gimp_context_set_tool (context, GIMP_TOOL_INFO (viewable)); -} - -static void -tool_options_dialog_save_callback (GtkWidget *widget, - GimpContext *context) -{ - GimpToolInfo *tool_info; - GError *error = NULL; - - tool_info = gimp_context_get_tool (context); - - if (! tool_info) - return; - - if (! gimp_tool_options_serialize (tool_info->tool_options, "user", &error)) - { - g_message ("EEK: %s\n", error->message); - g_clear_error (&error); - } -} - -static void -tool_options_dialog_restore_callback (GtkWidget *widget, - GimpContext *context) -{ - GimpToolInfo *tool_info; - - tool_info = gimp_context_get_tool (context); - - if (! tool_info) - return; - - /* Need to reset the tool-options since only the changes - * from the default values are written to disk. - */ - g_object_freeze_notify (G_OBJECT (tool_info->tool_options)); - - gimp_tool_options_reset (tool_info->tool_options); - gimp_tool_options_deserialize (tool_info->tool_options, "user", NULL); - - g_object_thaw_notify (G_OBJECT (tool_info->tool_options)); -} - -static void -tool_options_dialog_reset_callback (GtkWidget *widget, - GimpContext *context) -{ - GimpToolInfo *tool_info; - - tool_info = gimp_context_get_tool (context); - - if (! tool_info) - return; - - gimp_tool_options_reset (tool_info->tool_options); + + sensitive = (editor->visible_tool_options && + G_TYPE_FROM_INSTANCE (editor->visible_tool_options) != + GIMP_TYPE_TOOL_OPTIONS); + + gtk_widget_set_sensitive (editor->save_button, sensitive); + gtk_widget_set_sensitive (editor->restore_button, sensitive); + gtk_widget_set_sensitive (editor->reset_button, sensitive); } diff --git a/app/widgets/gimptooloptionseditor.h b/app/widgets/gimptooloptionseditor.h new file mode 100644 index 0000000000..2c744b1d9e --- /dev/null +++ b/app/widgets/gimptooloptionseditor.h @@ -0,0 +1,66 @@ +/* The GIMP -- an image manipulation program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * gimptooloptionseditor.h + * Copyright (C) 2003 Michael Natterer + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __GIMP_TOOL_OPTIONS_EDITOR_H__ +#define __GIMP_TOOL_OPTIONS_EDITOR_H__ + + +#include "gimpeditor.h" + + +#define GIMP_TYPE_TOOL_OPTIONS_EDITOR (gimp_tool_options_editor_get_type ()) +#define GIMP_TOOL_OPTIONS_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_TOOL_OPTIONS_EDITOR, GimpToolOptionsEditor)) +#define GIMP_TOOL_OPTIONS_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_TOOL_OPTIONS_EDITOR, GimpToolOptionsEditorClass)) +#define GIMP_IS_TOOL_OPTIONS_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_TOOL_OPTIONS_EDITOR)) +#define GIMP_IS_TOOL_OPTIONS_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_TOOL_OPTIONS_EDITOR)) +#define GIMP_TOOL_OPTIONS_EDITOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_TOOL_OPTIONS_EDITOR, GimpToolOptionsEditorClass)) + + +typedef struct _GimpToolOptionsEditorClass GimpToolOptionsEditorClass; + +struct _GimpToolOptionsEditor +{ + GimpEditor parent_instance; + + Gimp *gimp; + + GtkWidget *options_vbox; + + GtkWidget *save_button; + GtkWidget *restore_button; + GtkWidget *reset_button; + + GimpToolOptions *visible_tool_options; +}; + +struct _GimpToolOptionsEditorClass +{ + GimpEditorClass parent_class; +}; + + +GType gimp_tool_options_editor_get_type (void) G_GNUC_CONST; + +GtkWidget * gimp_tool_options_editor_new (Gimp *gimp, + GimpMenuFactory *menu_factory); + + +#endif /* __GIMP_TOOL_OPTIONS_EDITOR_H__ */ diff --git a/app/widgets/widgets-types.h b/app/widgets/widgets-types.h index 8dc9f76beb..91b2937b67 100644 --- a/app/widgets/widgets-types.h +++ b/app/widgets/widgets-types.h @@ -71,6 +71,7 @@ typedef struct _GimpPaletteEditor GimpPaletteEditor; typedef struct _GimpSelectionEditor GimpSelectionEditor; typedef struct _GimpStrokeEditor GimpStrokeEditor; typedef struct _GimpTemplateEditor GimpTemplateEditor; +typedef struct _GimpToolOptionsEditor GimpToolOptionsEditor; typedef struct _GimpUndoEditor GimpUndoEditor; typedef struct _GimpContainerView GimpContainerView;