Commit d02c5d93 authored by Paolo Bacchilega's avatar Paolo Bacchilega

file tools: converted accelerators to customizable shortcuts

parent 4e6b7990
/* -*- 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);
}
}
/* -*- 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 */
......@@ -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));
}
......@@ -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 */
......@@ -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
......
......@@ -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',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment