From 3d1c5641f79d65b2145fb22b6ddeed01fbd80c8b Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Wed, 12 Oct 2016 23:51:24 +0200 Subject: [PATCH] Bug 731279 - Tool Preset Editor not working correctly Have "Save" and "Restore" buttons in both the tool preset list/grid and the tool preset editor. The save button stores the active tool's options in the preset, if possible. --- app/actions/Makefile.am | 2 + app/actions/tool-preset-editor-actions.c | 22 +++++- app/actions/tool-preset-editor-commands.c | 88 +++++++++++++++++++++++ app/actions/tool-preset-editor-commands.h | 28 ++++++++ app/actions/tool-presets-actions.c | 8 +++ app/actions/tool-presets-commands.c | 42 +++++++++++ app/actions/tool-presets-commands.h | 2 + app/widgets/gimphelp-ids.h | 2 + app/widgets/gimptoolpreseteditor.c | 8 +++ app/widgets/gimptoolpresetfactoryview.c | 7 +- menus/tool-preset-editor-menu.xml | 3 + menus/tool-presets-menu.xml | 1 + po/POTFILES.in | 2 + 13 files changed, 211 insertions(+), 4 deletions(-) create mode 100644 app/actions/tool-preset-editor-commands.c create mode 100644 app/actions/tool-preset-editor-commands.h diff --git a/app/actions/Makefile.am b/app/actions/Makefile.am index b4c708d81a..1c144c051f 100644 --- a/app/actions/Makefile.am +++ b/app/actions/Makefile.am @@ -172,6 +172,8 @@ libappactions_a_SOURCES = \ tool-presets-commands.h \ tool-preset-editor-actions.c \ tool-preset-editor-actions.h \ + tool-preset-editor-commands.c \ + tool-preset-editor-commands.h \ tools-actions.c \ tools-actions.h \ tools-commands.c \ diff --git a/app/actions/tool-preset-editor-actions.c b/app/actions/tool-preset-editor-actions.c index 08b532ba52..0b9d12ed44 100644 --- a/app/actions/tool-preset-editor-actions.c +++ b/app/actions/tool-preset-editor-actions.c @@ -33,6 +33,7 @@ #include "data-editor-commands.h" #include "tool-preset-editor-actions.h" +#include "tool-preset-editor-commands.h" #include "gimp-intl.h" @@ -41,7 +42,20 @@ static const GimpActionEntry tool_preset_editor_actions[] = { { "tool-preset-editor-popup", GIMP_STOCK_TOOL_PRESET, NC_("tool-preset-editor-action", "Tool Preset Editor Menu"), NULL, NULL, NULL, - GIMP_HELP_BRUSH_EDITOR_DIALOG } + GIMP_HELP_TOOL_PRESET_EDITOR_DIALOG }, + + { "tool-preset-editor-save", "document-save", + NC_("tool-preset-editor-action", "_Save Tool Options to Preset"), NULL, + NC_("tool-preset-editor-action", "Save the active tool options to this " + "tool preset"), + G_CALLBACK (tool_preset_editor_save_cmd_callback), + GIMP_HELP_TOOL_PRESET_SAVE }, + + { "tool-preset-editor-restore", "document-revert", + NC_("tool-preset-editor-action", "_Restore Tool Preset"), NULL, + NC_("tool-preset-editor-action", "Restore this tool preset"), + G_CALLBACK (tool_preset_editor_restore_cmd_callback), + GIMP_HELP_TOOL_PRESET_RESTORE } }; @@ -51,7 +65,7 @@ static const GimpToggleActionEntry tool_preset_editor_toggle_actions[] = NC_("tool-preset-editor-action", "Edit Active Tool Preset"), NULL, NULL, G_CALLBACK (data_editor_edit_active_cmd_callback), FALSE, - GIMP_HELP_BRUSH_EDITOR_EDIT_ACTIVE } + GIMP_HELP_TOOL_PRESET_EDITOR_EDIT_ACTIVE } }; @@ -82,7 +96,9 @@ tool_preset_editor_actions_update (GimpActionGroup *group, #define SET_ACTIVE(action,condition) \ gimp_action_group_set_action_active (group, action, (condition) != 0) - SET_ACTIVE ("tool-preset-editor-edit-active", edit_active); + SET_SENSITIVE ("tool-preset-editor-save", data_editor->data); + SET_SENSITIVE ("tool-preset-editor-restore", data_editor->data); + SET_ACTIVE ("tool-preset-editor-edit-active", edit_active); #undef SET_SENSITIVE #undef SET_ACTIVE diff --git a/app/actions/tool-preset-editor-commands.c b/app/actions/tool-preset-editor-commands.c new file mode 100644 index 0000000000..21a7c05d86 --- /dev/null +++ b/app/actions/tool-preset-editor-commands.c @@ -0,0 +1,88 @@ +/* GIMP - The GNU 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 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 "libgimpconfig/gimpconfig.h" +#include "libgimpwidgets/gimpwidgets.h" + +#include "actions-types.h" + +#include "core/gimp.h" +#include "core/gimpcontext.h" +#include "core/gimptoolinfo.h" +#include "core/gimptoolpreset.h" + +#include "widgets/gimpdataeditor.h" + +#include "tool-preset-editor-commands.h" + +#include "gimp-intl.h" + + +/* public functions */ + +void +tool_preset_editor_save_cmd_callback (GtkAction *action, + gpointer data) +{ + GimpDataEditor *editor = GIMP_DATA_EDITOR (data); + GimpContext *context = editor->context; + GimpToolPreset *preset; + GimpToolInfo *tool_info; + + preset = GIMP_TOOL_PRESET (gimp_data_editor_get_data (editor)); + tool_info = gimp_context_get_tool (gimp_get_user_context (context->gimp)); + + if (tool_info && preset) + { + GimpToolInfo *preset_tool; + + preset_tool = gimp_context_get_tool (GIMP_CONTEXT (preset->tool_options)); + + if (tool_info != preset_tool) + { + gimp_message (context->gimp, + G_OBJECT (editor), GIMP_MESSAGE_WARNING, + _("Can't save '%s' tool options to an " + "existing '%s' tool preset."), + tool_info->blurb, + preset_tool->blurb); + return; + } + + gimp_config_sync (G_OBJECT (tool_info->tool_options), + G_OBJECT (preset->tool_options), 0); + } +} + +void +tool_preset_editor_restore_cmd_callback (GtkAction *action, + gpointer data) +{ + GimpDataEditor *editor = GIMP_DATA_EDITOR (data); + GimpContext *context = editor->context; + GimpToolPreset *preset; + + preset = GIMP_TOOL_PRESET (gimp_data_editor_get_data (editor)); + + if (preset) + gimp_context_tool_preset_changed (context); +} diff --git a/app/actions/tool-preset-editor-commands.h b/app/actions/tool-preset-editor-commands.h new file mode 100644 index 0000000000..324c31c9d9 --- /dev/null +++ b/app/actions/tool-preset-editor-commands.h @@ -0,0 +1,28 @@ +/* GIMP - The GNU 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 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 __TOOL_PRESET_EDITOR_COMMANDS_H__ +#define __TOOL_PRESET_EDITOR_COMMANDS_H__ + + +void tool_preset_editor_save_cmd_callback (GtkAction *action, + gpointer data); +void tool_preset_editor_restore_cmd_callback (GtkAction *action, + gpointer data); + + +#endif /* __TOOL_PRESET_EDITOR_COMMANDS_H__ */ diff --git a/app/actions/tool-presets-actions.c b/app/actions/tool-presets-actions.c index 8b20dcbe4d..4870955b94 100644 --- a/app/actions/tool-presets-actions.c +++ b/app/actions/tool-presets-actions.c @@ -70,6 +70,13 @@ static const GimpActionEntry tool_presets_actions[] = G_CALLBACK (data_show_in_file_manager_cmd_callback), GIMP_HELP_TOOL_PRESET_SHOW_IN_FILE_MANAGER }, + { "tool-presets-save", "document-save", + NC_("tool-presets-action", "_Save Tool Options to Preset"), NULL, + NC_("tool-presets-action", "Save the active tool options to this " + "tool preset"), + G_CALLBACK (tool_presets_save_cmd_callback), + GIMP_HELP_TOOL_PRESET_SAVE }, + { "tool-presets-restore", "document-revert", NC_("tool-presets-action", "_Restore Tool Preset"), NULL, NC_("tool-presets-action", "Restore this tool preset"), @@ -140,6 +147,7 @@ tool_presets_actions_update (GimpActionGroup *group, SET_SENSITIVE ("tool-presets-duplicate", tool_preset && GIMP_DATA_GET_CLASS (data)->duplicate); SET_SENSITIVE ("tool-presets-copy-location", file); SET_SENSITIVE ("tool-presets-show-in-file-manager", file); + SET_SENSITIVE ("tool-presets-save", tool_preset); SET_SENSITIVE ("tool-presets-restore", tool_preset); SET_SENSITIVE ("tool-presets-delete", tool_preset && gimp_data_is_deletable (data)); diff --git a/app/actions/tool-presets-commands.c b/app/actions/tool-presets-commands.c index 7ac7decdf8..816d227d45 100644 --- a/app/actions/tool-presets-commands.c +++ b/app/actions/tool-presets-commands.c @@ -20,20 +20,62 @@ #include #include +#include "libgimpconfig/gimpconfig.h" #include "libgimpwidgets/gimpwidgets.h" #include "actions-types.h" +#include "core/gimp.h" #include "core/gimpcontext.h" +#include "core/gimptoolinfo.h" +#include "core/gimptoolpreset.h" #include "widgets/gimpcontainereditor.h" #include "widgets/gimpcontainerview.h" #include "tool-presets-commands.h" +#include "gimp-intl.h" + /* public functions */ +void +tool_presets_save_cmd_callback (GtkAction *action, + gpointer data) +{ + GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (data); + GimpContext *context; + GimpToolPreset *preset; + GimpToolInfo *tool_info; + + context = gimp_container_view_get_context (editor->view); + + preset = gimp_context_get_tool_preset (context); + tool_info = gimp_context_get_tool (gimp_get_user_context (context->gimp)); + + if (tool_info && preset) + { + GimpToolInfo *preset_tool; + + preset_tool = gimp_context_get_tool (GIMP_CONTEXT (preset->tool_options)); + + if (tool_info != preset_tool) + { + gimp_message (context->gimp, + G_OBJECT (editor), GIMP_MESSAGE_WARNING, + _("Can't save '%s' tool options to an " + "existing '%s' tool preset."), + tool_info->blurb, + preset_tool->blurb); + return; + } + + gimp_config_sync (G_OBJECT (tool_info->tool_options), + G_OBJECT (preset->tool_options), 0); + } +} + void tool_presets_restore_cmd_callback (GtkAction *action, gpointer data) diff --git a/app/actions/tool-presets-commands.h b/app/actions/tool-presets-commands.h index e985931a08..3fd0548d2d 100644 --- a/app/actions/tool-presets-commands.h +++ b/app/actions/tool-presets-commands.h @@ -19,6 +19,8 @@ #define __TOOL_PRESETS_COMMANDS_H__ +void tool_presets_save_cmd_callback (GtkAction *action, + gpointer data); void tool_presets_restore_cmd_callback (GtkAction *action, gpointer data); diff --git a/app/widgets/gimphelp-ids.h b/app/widgets/gimphelp-ids.h index 58233e9413..8bfa8c05e5 100644 --- a/app/widgets/gimphelp-ids.h +++ b/app/widgets/gimphelp-ids.h @@ -352,6 +352,7 @@ #define GIMP_HELP_DYNAMICS_EDITOR_DIALOG "gimp-dynamics-editor-dialog" #define GIMP_HELP_TOOL_PRESET_EDITOR_DIALOG "gimp-tool-preset-editor-dialog" +#define GIMP_HELP_TOOL_PRESET_EDITOR_EDIT_ACTIVE "gimp-tool-preset-editor-edit-active" #define GIMP_HELP_DYNAMICS_DIALOG "gimp-dynamics-dialog" #define GIMP_HELP_DYNAMICS_EDIT "gimp-dynamics-edit" @@ -452,6 +453,7 @@ #define GIMP_HELP_TOOL_PRESET_DUPLICATE "gimp-tool-preset-duplicate" #define GIMP_HELP_TOOL_PRESET_COPY_LOCATION "gimp-tool-preset-copy-location" #define GIMP_HELP_TOOL_PRESET_SHOW_IN_FILE_MANAGER "gimp-tool-preset-show-in-file-manager" +#define GIMP_HELP_TOOL_PRESET_SAVE "gimp-tool-preset-save" #define GIMP_HELP_TOOL_PRESET_RESTORE "gimp-tool-preset-restore" #define GIMP_HELP_TOOL_PRESET_DELETE "gimp-tool-preset-delete" #define GIMP_HELP_TOOL_PRESET_REFRESH "gimp-tool-preset-refresh" diff --git a/app/widgets/gimptoolpreseteditor.c b/app/widgets/gimptoolpreseteditor.c index 9321801782..d8082ff572 100644 --- a/app/widgets/gimptoolpreseteditor.c +++ b/app/widgets/gimptoolpreseteditor.c @@ -195,6 +195,14 @@ gimp_tool_preset_editor_constructed (GObject *object) gtk_box_pack_start (GTK_BOX (data_editor), button, FALSE, FALSE, 0); gtk_widget_show (button); + button = gimp_editor_add_action_button (GIMP_EDITOR (editor), + "tool-preset-editor", + "tool-preset-editor-save", NULL); + + button = gimp_editor_add_action_button (GIMP_EDITOR (editor), + "tool-preset-editor", + "tool-preset-editor-restore", NULL); + if (data_editor->data) gimp_tool_preset_editor_sync_data (editor); } diff --git a/app/widgets/gimptoolpresetfactoryview.c b/app/widgets/gimptoolpresetfactoryview.c index d549f3350a..8ccc39c3d3 100644 --- a/app/widgets/gimptoolpresetfactoryview.c +++ b/app/widgets/gimptoolpresetfactoryview.c @@ -90,9 +90,14 @@ gimp_tool_preset_factory_view_new (GimpViewType view_type, editor = GIMP_EDITOR (GIMP_CONTAINER_EDITOR (factory_view)->view); button = gimp_editor_add_action_button (editor, "tool-presets", - "tool-presets-restore", NULL); + "tool-presets-save", NULL); gtk_box_reorder_child (gimp_editor_get_button_box (editor), button, 2); + button = gimp_editor_add_action_button (editor, "tool-presets", + "tool-presets-restore", NULL); + gtk_box_reorder_child (gimp_editor_get_button_box (editor), + button, 3); + return GTK_WIDGET (factory_view); } diff --git a/menus/tool-preset-editor-menu.xml b/menus/tool-preset-editor-menu.xml index b4a8ee05d7..6bb744b0ae 100644 --- a/menus/tool-preset-editor-menu.xml +++ b/menus/tool-preset-editor-menu.xml @@ -3,6 +3,9 @@ + + + diff --git a/menus/tool-presets-menu.xml b/menus/tool-presets-menu.xml index 7e17c5336b..585ebd01b4 100644 --- a/menus/tool-presets-menu.xml +++ b/menus/tool-presets-menu.xml @@ -9,6 +9,7 @@ + diff --git a/po/POTFILES.in b/po/POTFILES.in index 419a2f2490..1c327f2106 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -76,7 +76,9 @@ app/actions/text-tool-commands.c app/actions/tool-options-actions.c app/actions/tool-options-commands.c app/actions/tool-preset-editor-actions.c +app/actions/tool-preset-editor-commands.c app/actions/tool-presets-actions.c +app/actions/tool-presets-commands.c app/actions/tools-actions.c app/actions/vectors-actions.c app/actions/vectors-commands.c