[gimp] app: add new action to restore a tool preset from the list



commit 92eed69f1b3b8aa812e9bdbbba5c2b297f042b7b
Author: Michael Natterer <mitch gimp org>
Date:   Wed Oct 14 12:24:15 2015 +0200

    app: add new action to restore a tool preset from the list
    
    In order to make things more obvious here. Before, a tool preset could
    only be rstored from the list by selecting it, which only worked if
    another preset was active before. Now the selected preset can easily
    be restored again.

 app/actions/Makefile.am                 |    2 +
 app/actions/tool-presets-actions.c      |    8 +++++
 app/actions/tool-presets-commands.c     |   51 +++++++++++++++++++++++++++++++
 app/actions/tool-presets-commands.h     |   26 ++++++++++++++++
 app/widgets/gimphelp-ids.h              |    1 +
 app/widgets/gimptoolpresetfactoryview.c |    9 +++++
 menus/tool-presets-menu.xml             |    1 +
 7 files changed, 98 insertions(+), 0 deletions(-)
---
diff --git a/app/actions/Makefile.am b/app/actions/Makefile.am
index 496a1d9..f6c267b 100644
--- a/app/actions/Makefile.am
+++ b/app/actions/Makefile.am
@@ -161,6 +161,8 @@ libappactions_a_SOURCES = \
        tool-options-commands.h         \
        tool-presets-actions.c          \
        tool-presets-actions.h          \
+       tool-presets-commands.c         \
+       tool-presets-commands.h         \
        tool-preset-editor-actions.c    \
        tool-preset-editor-actions.h    \
        tools-actions.c                 \
diff --git a/app/actions/tool-presets-actions.c b/app/actions/tool-presets-actions.c
index bf0f7b3..66c5e28 100644
--- a/app/actions/tool-presets-actions.c
+++ b/app/actions/tool-presets-actions.c
@@ -35,6 +35,7 @@
 #include "actions.h"
 #include "data-commands.h"
 #include "tool-presets-actions.h"
+#include "tool-presets-commands.h"
 
 #include "gimp-intl.h"
 
@@ -69,6 +70,12 @@ 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-restore", "document-revert",
+    NC_("tool-presets-action", "_Restore Tool Preset"), NULL,
+    NC_("tool-presets-action", "Restore this tool preset"),
+    G_CALLBACK (tool_presets_restore_cmd_callback),
+    GIMP_HELP_TOOL_PRESET_RESTORE },
+
   { "tool-presets-delete", "edit-delete",
     NC_("tool-presets-action", "_Delete Tool Preset"), NULL,
     NC_("tool-presets-action", "Delete this tool preset"),
@@ -133,6 +140,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-restore",              tool_preset);
   SET_SENSITIVE ("tool-presets-delete",               tool_preset && gimp_data_is_deletable (data));
 
 #undef SET_SENSITIVE
diff --git a/app/actions/tool-presets-commands.c b/app/actions/tool-presets-commands.c
new file mode 100644
index 0000000..d000716
--- /dev/null
+++ b/app/actions/tool-presets-commands.c
@@ -0,0 +1,51 @@
+/* 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <gegl.h>
+#include <gtk/gtk.h>
+
+#include "libgimpwidgets/gimpwidgets.h"
+
+#include "actions-types.h"
+
+#include "core/gimpcontext.h"
+
+#include "widgets/gimpcontainereditor.h"
+#include "widgets/gimpcontainerview.h"
+
+#include "tool-presets-commands.h"
+
+
+/*  public functions  */
+
+void
+tool_presets_restore_cmd_callback (GtkAction *action,
+                                   gpointer   data)
+{
+  GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (data);
+  GimpContext         *context;
+  GimpToolPreset *preset;
+
+  context = gimp_container_view_get_context (editor->view);
+
+  preset = gimp_context_get_tool_preset (context);
+
+  if (preset)
+    gimp_context_tool_preset_changed (context);
+}
diff --git a/app/actions/tool-presets-commands.h b/app/actions/tool-presets-commands.h
new file mode 100644
index 0000000..e985931
--- /dev/null
+++ b/app/actions/tool-presets-commands.h
@@ -0,0 +1,26 @@
+/* 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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __TOOL_PRESETS_COMMANDS_H__
+#define __TOOL_PRESETS_COMMANDS_H__
+
+
+void   tool_presets_restore_cmd_callback (GtkAction *action,
+                                          gpointer   data);
+
+
+#endif /* __TOOL_PRESETS_COMMANDS_H__ */
diff --git a/app/widgets/gimphelp-ids.h b/app/widgets/gimphelp-ids.h
index 5531b48..481de1c 100644
--- a/app/widgets/gimphelp-ids.h
+++ b/app/widgets/gimphelp-ids.h
@@ -433,6 +433,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_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/gimptoolpresetfactoryview.c b/app/widgets/gimptoolpresetfactoryview.c
index 9552e81..d549f33 100644
--- a/app/widgets/gimptoolpresetfactoryview.c
+++ b/app/widgets/gimptoolpresetfactoryview.c
@@ -60,6 +60,8 @@ gimp_tool_preset_factory_view_new (GimpViewType      view_type,
                                    GimpMenuFactory  *menu_factory)
 {
   GimpToolPresetFactoryView *factory_view;
+  GimpEditor                *editor;
+  GtkWidget                 *button;
 
   g_return_val_if_fail (GIMP_IS_DATA_FACTORY (factory), NULL);
   g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
@@ -85,5 +87,12 @@ gimp_tool_preset_factory_view_new (GimpViewType      view_type,
 
   gtk_widget_hide (gimp_data_factory_view_get_duplicate_button (GIMP_DATA_FACTORY_VIEW (factory_view)));
 
+  editor = GIMP_EDITOR (GIMP_CONTAINER_EDITOR (factory_view)->view);
+
+  button = gimp_editor_add_action_button (editor, "tool-presets",
+                                          "tool-presets-restore", NULL);
+  gtk_box_reorder_child (gimp_editor_get_button_box (editor),
+                         button, 2);
+
   return GTK_WIDGET (factory_view);
 }
diff --git a/menus/tool-presets-menu.xml b/menus/tool-presets-menu.xml
index 33b82b7..7e17c53 100644
--- a/menus/tool-presets-menu.xml
+++ b/menus/tool-presets-menu.xml
@@ -9,6 +9,7 @@
     <menuitem action="tool-presets-duplicate" />
     <menuitem action="tool-presets-copy-location" />
     <menuitem action="tool-presets-show-in-file-manager" />
+    <menuitem action="tool-presets-restore" />
     <menuitem action="tool-presets-delete" />
     <separator />
     <menuitem action="tool-presets-refresh" />


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