[gthumb] shortcuts: fixed actions for image edit tools



commit 86837700d0585205122e5b92958ad58ac295b131
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Fri Nov 22 10:07:38 2019 +0100

    shortcuts: fixed actions for image edit tools
    
    Shortcuts do not support actions with a parameter, convert to
    actions without parameters.

 extensions/file_tools/actions.c   | 98 +++++++++++++++++++++++++++++----------
 extensions/file_tools/actions.h   |  8 +++-
 extensions/file_tools/callbacks.c | 14 +++---
 3 files changed, 88 insertions(+), 32 deletions(-)
---
diff --git a/extensions/file_tools/actions.c b/extensions/file_tools/actions.c
index 03a2dc2a..c65fd6d3 100644
--- a/extensions/file_tools/actions.c
+++ b/extensions/file_tools/actions.c
@@ -33,16 +33,13 @@
 #include "gth-file-tool-rotate-right.h"
 
 
-void
-gth_browser_activate_file_tool (GSimpleAction *action,
-                               GVariant      *parameter,
-                               gpointer       user_data)
+static void
+gth_browser_activate_file_tool (GthBrowser *browser,
+                               GType       tool_type)
 {
-       GthBrowser    *browser = user_data;
        GtkWidget     *sidebar;
        GtkWidget     *toolbox;
        GthViewerPage *page;
-       const char    *tool_name;
        GthFileTool   *tool;
 
        sidebar = gth_browser_get_viewer_sidebar (browser);
@@ -54,27 +51,80 @@ gth_browser_activate_file_tool (GSimpleAction *action,
        if (! GTH_IS_IMAGE_VIEWER_PAGE (page))
                return;
 
-       tool_name = g_variant_get_string (parameter, NULL);
-
-       tool = NULL;
-       if (g_strcmp0 (tool_name, "adjust-contrast") == 0)
-               tool = (GthFileTool *) gth_toolbox_get_tool (GTH_TOOLBOX (toolbox), 
GTH_TYPE_FILE_TOOL_ADJUST_CONTRAST);
-       if (g_strcmp0 (tool_name, "flip") == 0)
-               tool = (GthFileTool *) gth_toolbox_get_tool (GTH_TOOLBOX (toolbox), GTH_TYPE_FILE_TOOL_FLIP);
-       if (g_strcmp0 (tool_name, "mirror") == 0)
-               tool = (GthFileTool *) gth_toolbox_get_tool (GTH_TOOLBOX (toolbox), 
GTH_TYPE_FILE_TOOL_MIRROR);
-       if (g_strcmp0 (tool_name, "rotate-right") == 0)
-               tool = (GthFileTool *) gth_toolbox_get_tool (GTH_TOOLBOX (toolbox), 
GTH_TYPE_FILE_TOOL_ROTATE_RIGHT);
-       if (g_strcmp0 (tool_name, "rotate-left") == 0)
-               tool = (GthFileTool *) gth_toolbox_get_tool (GTH_TOOLBOX (toolbox), 
GTH_TYPE_FILE_TOOL_ROTATE_LEFT);
-       if (g_strcmp0 (tool_name, "crop") == 0)
-               tool = (GthFileTool *) gth_toolbox_get_tool (GTH_TOOLBOX (toolbox), GTH_TYPE_FILE_TOOL_CROP);
-       if (g_strcmp0 (tool_name, "resize") == 0)
-               tool = (GthFileTool *) gth_toolbox_get_tool (GTH_TOOLBOX (toolbox), 
GTH_TYPE_FILE_TOOL_RESIZE);
-
+       tool = (GthFileTool *) gth_toolbox_get_tool (GTH_TOOLBOX (toolbox), tool_type);
        if (tool != NULL) {
                if (gth_window_get_current_page (GTH_WINDOW (browser)) == GTH_BROWSER_PAGE_BROWSER)
                        gth_window_set_current_page (GTH_WINDOW (browser), GTH_BROWSER_PAGE_VIEWER);
                gth_file_tool_activate (tool);
        }
 }
+
+
+void
+gth_browser_activate_tool_adjust_contrast (GSimpleAction *action,
+                                          GVariant      *parameter,
+                                          gpointer       user_data)
+{
+       gth_browser_activate_file_tool (GTH_BROWSER (user_data),
+                                       GTH_TYPE_FILE_TOOL_ADJUST_CONTRAST);
+}
+
+
+void
+gth_browser_activate_tool_flip (GSimpleAction *action,
+                                          GVariant      *parameter,
+                                          gpointer       user_data)
+{
+       gth_browser_activate_file_tool (GTH_BROWSER (user_data),
+                                       GTH_TYPE_FILE_TOOL_FLIP);
+}
+
+
+void
+gth_browser_activate_tool_mirror (GSimpleAction *action,
+                                 GVariant      *parameter,
+                                 gpointer       user_data)
+{
+       gth_browser_activate_file_tool (GTH_BROWSER (user_data),
+                                       GTH_TYPE_FILE_TOOL_MIRROR);
+}
+
+
+void
+gth_browser_activate_tool_rotate_right (GSimpleAction *action,
+                                       GVariant      *parameter,
+                                       gpointer       user_data)
+{
+       gth_browser_activate_file_tool (GTH_BROWSER (user_data),
+                                       GTH_TYPE_FILE_TOOL_ROTATE_RIGHT);
+}
+
+
+void
+gth_browser_activate_tool_rotate_left (GSimpleAction *action,
+                                      GVariant      *parameter,
+                                      gpointer       user_data)
+{
+       gth_browser_activate_file_tool (GTH_BROWSER (user_data),
+                                       GTH_TYPE_FILE_TOOL_ROTATE_LEFT);
+}
+
+
+void
+gth_browser_activate_tool_crop (GSimpleAction *action,
+                               GVariant      *parameter,
+                               gpointer       user_data)
+{
+       gth_browser_activate_file_tool (GTH_BROWSER (user_data),
+                                       GTH_TYPE_FILE_TOOL_CROP);
+}
+
+
+void
+gth_browser_activate_tool_resize (GSimpleAction *action,
+                                 GVariant      *parameter,
+                                 gpointer       user_data)
+{
+       gth_browser_activate_file_tool (GTH_BROWSER (user_data),
+                                       GTH_TYPE_FILE_TOOL_RESIZE);
+}
diff --git a/extensions/file_tools/actions.h b/extensions/file_tools/actions.h
index 652bedcb..f6f5c90a 100644
--- a/extensions/file_tools/actions.h
+++ b/extensions/file_tools/actions.h
@@ -24,6 +24,12 @@
 
 #include <gthumb.h>
 
-DEF_ACTION_CALLBACK (gth_browser_activate_file_tool)
+DEF_ACTION_CALLBACK (gth_browser_activate_tool_adjust_contrast)
+DEF_ACTION_CALLBACK (gth_browser_activate_tool_flip)
+DEF_ACTION_CALLBACK (gth_browser_activate_tool_mirror)
+DEF_ACTION_CALLBACK (gth_browser_activate_tool_rotate_right)
+DEF_ACTION_CALLBACK (gth_browser_activate_tool_rotate_left)
+DEF_ACTION_CALLBACK (gth_browser_activate_tool_crop)
+DEF_ACTION_CALLBACK (gth_browser_activate_tool_resize)
 
 #endif /* ACTIONS_H */
diff --git a/extensions/file_tools/callbacks.c b/extensions/file_tools/callbacks.c
index 6873f5e4..bacdeecc 100644
--- a/extensions/file_tools/callbacks.c
+++ b/extensions/file_tools/callbacks.c
@@ -39,13 +39,13 @@
 
 
 static const GActionEntry actions[] = {
-       { "file-tool-adjust-contrast", gth_browser_activate_file_tool, "s", "'adjust-contrast'" },
-       { "file-tool-flip", gth_browser_activate_file_tool, "s", "'flip'" },
-       { "file-tool-mirror", gth_browser_activate_file_tool, "s", "'mirror'" },
-       { "file-tool-rotate-right", gth_browser_activate_file_tool, "s", "'rotate-right'" },
-       { "file-tool-rotate-left", gth_browser_activate_file_tool, "s", "'rotate-left'" },
-       { "file-tool-crop", gth_browser_activate_file_tool, "s", "'crop'" },
-       { "file-tool-resize", gth_browser_activate_file_tool, "s", "'resize'" },
+       { "file-tool-adjust-contrast", gth_browser_activate_tool_adjust_contrast },
+       { "file-tool-flip", gth_browser_activate_tool_flip },
+       { "file-tool-mirror", gth_browser_activate_tool_mirror },
+       { "file-tool-rotate-right", gth_browser_activate_tool_rotate_right },
+       { "file-tool-rotate-left", gth_browser_activate_tool_rotate_left },
+       { "file-tool-crop", gth_browser_activate_tool_crop },
+       { "file-tool-resize", gth_browser_activate_tool_resize },
 };
 
 


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