[gthumb] file tools: converted accelerators to customizable shortcuts



commit d02c5d93c362dd5697be970df92b4fb7fcc310cd
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sat Nov 9 18:21:44 2019 +0100

    file tools: converted accelerators to customizable shortcuts

 extensions/file_tools/actions.c   | 80 +++++++++++++++++++++++++++++++++++++++
 extensions/file_tools/actions.h   | 29 ++++++++++++++
 extensions/file_tools/callbacks.c | 80 ++++++++++++++-------------------------
 extensions/file_tools/callbacks.h |  3 +-
 extensions/file_tools/main.c      |  2 +-
 extensions/file_tools/meson.build |  1 +
 6 files changed, 141 insertions(+), 54 deletions(-)
---
diff --git a/extensions/file_tools/actions.c b/extensions/file_tools/actions.c
new file mode 100644
index 00000000..03a2dc2a
--- /dev/null
+++ b/extensions/file_tools/actions.c
@@ -0,0 +1,80 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2019 Free Software Foundation, Inc.
+ *
+ *  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, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include <config.h>
+#include <gthumb.h>
+#include <extensions/image_viewer/gth-image-viewer-page.h>
+#include "actions.h"
+#include "gth-file-tool-adjust-contrast.h"
+#include "gth-file-tool-crop.h"
+#include "gth-file-tool-flip.h"
+#include "gth-file-tool-mirror.h"
+#include "gth-file-tool-resize.h"
+#include "gth-file-tool-rotate-left.h"
+#include "gth-file-tool-rotate-right.h"
+
+
+void
+gth_browser_activate_file_tool (GSimpleAction *action,
+                               GVariant      *parameter,
+                               gpointer       user_data)
+{
+       GthBrowser    *browser = user_data;
+       GtkWidget     *sidebar;
+       GtkWidget     *toolbox;
+       GthViewerPage *page;
+       const char    *tool_name;
+       GthFileTool   *tool;
+
+       sidebar = gth_browser_get_viewer_sidebar (browser);
+       toolbox = gth_sidebar_get_toolbox (GTH_SIDEBAR (sidebar));
+       if (gth_toolbox_tool_is_active (GTH_TOOLBOX (toolbox)))
+               return;
+
+       page = gth_browser_get_viewer_page (browser);
+       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);
+
+       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);
+       }
+}
diff --git a/extensions/file_tools/actions.h b/extensions/file_tools/actions.h
new file mode 100644
index 00000000..652bedcb
--- /dev/null
+++ b/extensions/file_tools/actions.h
@@ -0,0 +1,29 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2019 Free Software Foundation, Inc.
+ *
+ *  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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef ACTIONS_H
+#define ACTIONS_H
+
+#include <gthumb.h>
+
+DEF_ACTION_CALLBACK (gth_browser_activate_file_tool)
+
+#endif /* ACTIONS_H */
diff --git a/extensions/file_tools/callbacks.c b/extensions/file_tools/callbacks.c
index f8a98bfc..af3b2745 100644
--- a/extensions/file_tools/callbacks.c
+++ b/extensions/file_tools/callbacks.c
@@ -26,6 +26,7 @@
 #include <gdk/gdkkeysyms.h>
 #include <gthumb.h>
 #include <extensions/image_viewer/gth-image-viewer-page.h>
+#include "actions.h"
 #include "callbacks.h"
 #include "gth-file-tool-adjust-contrast.h"
 #include "gth-file-tool-crop.h"
@@ -36,60 +37,37 @@
 #include "gth-file-tool-rotate-right.h"
 
 
-gpointer
-file_tools__gth_browser_file_list_key_press_cb (GthBrowser  *browser,
-                                               GdkEventKey *event)
-{
-       gpointer       result = NULL;
-       GtkWidget     *sidebar;
-       GtkWidget     *toolbox;
-       GthFileTool   *tool = NULL;
-       guint          modifiers;
-       GthViewerPage *page;
-
-       sidebar = gth_browser_get_viewer_sidebar (browser);
-       toolbox = gth_sidebar_get_toolbox (GTH_SIDEBAR (sidebar));
-       if (gth_toolbox_tool_is_active (GTH_TOOLBOX (toolbox)))
-               return NULL;
+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'" },
+};
 
-       modifiers = gtk_accelerator_get_default_mod_mask ();
-       if (((event->state & modifiers) != 0) && ((event->state & modifiers) != GDK_SHIFT_MASK))
-               return NULL;
 
-       page = gth_browser_get_viewer_page (browser);
-       if (! GTH_IS_IMAGE_VIEWER_PAGE (page))
-               return NULL;
+static const GthShortcut shortcuts[] = {
+       { "file-tool-adjust-contrast", N_("Adjust Contrast"), GTH_SHORTCUT_CONTEXT_BROWSER_VIEWER, 
GTH_SHORTCUT_CATEGORY_IMAGE_EDIT, "A" },
+       { "file-tool-flip", N_("Flip"), GTH_SHORTCUT_CONTEXT_BROWSER_VIEWER, 
GTH_SHORTCUT_CATEGORY_IMAGE_EDIT, "L" },
+       { "file-tool-mirror", N_("Mirror"), GTH_SHORTCUT_CONTEXT_BROWSER_VIEWER, 
GTH_SHORTCUT_CATEGORY_IMAGE_EDIT, "M" },
+       { "file-tool-rotate-right", N_("Rotate Right"), GTH_SHORTCUT_CONTEXT_BROWSER_VIEWER, 
GTH_SHORTCUT_CATEGORY_IMAGE_EDIT, "R" },
+       { "file-tool-rotate-left", N_("Rotate Left"), GTH_SHORTCUT_CONTEXT_BROWSER_VIEWER, 
GTH_SHORTCUT_CATEGORY_IMAGE_EDIT, "<shift>R" },
+       { "file-tool-crop", N_("Crop"), GTH_SHORTCUT_CONTEXT_BROWSER_VIEWER, 
GTH_SHORTCUT_CATEGORY_IMAGE_EDIT, "<shift>C" },
+       { "file-tool-resize", N_("Resize"), GTH_SHORTCUT_CONTEXT_BROWSER_VIEWER, 
GTH_SHORTCUT_CATEGORY_IMAGE_EDIT, "<shift>S" },
+};
 
-       switch (event->keyval) {
-       case GDK_KEY_a:
-               tool = (GthFileTool *) gth_toolbox_get_tool (GTH_TOOLBOX (toolbox), 
GTH_TYPE_FILE_TOOL_ADJUST_CONTRAST);
-               break;
-       case GDK_KEY_l:
-               tool = (GthFileTool *) gth_toolbox_get_tool (GTH_TOOLBOX (toolbox), GTH_TYPE_FILE_TOOL_FLIP);
-               break;
-       case GDK_KEY_m:
-               tool = (GthFileTool *) gth_toolbox_get_tool (GTH_TOOLBOX (toolbox), 
GTH_TYPE_FILE_TOOL_MIRROR);
-               break;
-       case GDK_KEY_r:
-               tool = (GthFileTool *) gth_toolbox_get_tool (GTH_TOOLBOX (toolbox), 
GTH_TYPE_FILE_TOOL_ROTATE_RIGHT);
-               break;
-       case GDK_KEY_R:
-               tool = (GthFileTool *) gth_toolbox_get_tool (GTH_TOOLBOX (toolbox), 
GTH_TYPE_FILE_TOOL_ROTATE_LEFT);
-               break;
-       case GDK_KEY_C:
-               tool = (GthFileTool *) gth_toolbox_get_tool (GTH_TOOLBOX (toolbox), GTH_TYPE_FILE_TOOL_CROP);
-               break;
-       case GDK_KEY_S:
-               tool = (GthFileTool *) gth_toolbox_get_tool (GTH_TOOLBOX (toolbox), 
GTH_TYPE_FILE_TOOL_RESIZE);
-               break;
-       }
 
-       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);
-               result = GINT_TO_POINTER (1);
-       }
+void
+file_tools__gth_browser_construct_cb (GthBrowser *browser)
+{
+       g_action_map_add_action_entries (G_ACTION_MAP (browser),
+                                        actions,
+                                        G_N_ELEMENTS (actions),
+                                        browser);
 
-       return result;
+       gth_window_add_shortcuts (GTH_WINDOW (browser),
+                                 shortcuts,
+                                 G_N_ELEMENTS (shortcuts));
 }
diff --git a/extensions/file_tools/callbacks.h b/extensions/file_tools/callbacks.h
index d677c0fb..6c2dacf2 100644
--- a/extensions/file_tools/callbacks.h
+++ b/extensions/file_tools/callbacks.h
@@ -24,7 +24,6 @@
 
 #include <gthumb.h>
 
-gpointer  file_tools__gth_browser_file_list_key_press_cb    (GthBrowser  *browser,
-                                                            GdkEventKey *event);
+void file_tools__gth_browser_construct_cb (GthBrowser *browser);
 
 #endif /* CALLBACKS_H */
diff --git a/extensions/file_tools/main.c b/extensions/file_tools/main.c
index 525988b5..f53197cf 100644
--- a/extensions/file_tools/main.c
+++ b/extensions/file_tools/main.c
@@ -74,7 +74,7 @@ gthumb_extension_activate (void)
        gth_main_register_type ("file-tools", GTH_TYPE_FILE_TOOL_RESIZE);
        gth_main_register_type ("file-tools", GTH_TYPE_FILE_TOOL_CROP);
 
-       gth_hook_add_callback ("gth-browser-file-list-key-press", 10, G_CALLBACK 
(file_tools__gth_browser_file_list_key_press_cb), NULL);
+       gth_hook_add_callback ("gth-browser-construct", 10, G_CALLBACK 
(file_tools__gth_browser_construct_cb), NULL);
 
        /**
         * Add a filter to the filter list shown in the Effects tool
diff --git a/extensions/file_tools/meson.build b/extensions/file_tools/meson.build
index 463cd007..04355025 100644
--- a/extensions/file_tools/meson.build
+++ b/extensions/file_tools/meson.build
@@ -38,6 +38,7 @@ header_files = [
 enum_files = gnome.mkenums_simple('file-tools-enum-types', sources: header_files)
 
 source_files = files(
+  'actions.c',
   'cairo-blur.c',
   'cairo-effects.c',
   'cairo-rotate.c',


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