Commit 4e6b7990 authored by Paolo Bacchilega's avatar Paolo Bacchilega

image viewer: converted accelerators to customizable shortcuts

parent 0049e44b
......@@ -27,15 +27,31 @@
#include "preferences.h"
static GthImageViewerPage *
get_image_viewer_page (GthBrowser *browser)
{
GthViewerPage *viewer_page = gth_browser_get_viewer_page (browser);
if ((viewer_page != NULL) && GTH_IS_IMAGE_VIEWER_PAGE (viewer_page))
return GTH_IMAGE_VIEWER_PAGE (viewer_page);
else
return NULL;
}
void
gth_browser_activate_image_zoom_in (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
GthBrowser *browser = user_data;
GthImageViewerPage *self = GTH_IMAGE_VIEWER_PAGE (gth_browser_get_viewer_page (browser));
GthImageViewerPage *viewer_page = get_image_viewer_page (browser);
if (viewer_page == NULL)
return;
gth_image_viewer_zoom_in (GTH_IMAGE_VIEWER (gth_image_viewer_page_get_image_viewer (self)));
gth_image_viewer_zoom_in (GTH_IMAGE_VIEWER (gth_image_viewer_page_get_image_viewer (viewer_page)));
}
......@@ -45,9 +61,12 @@ gth_browser_activate_image_zoom_out (GSimpleAction *action,
gpointer user_data)
{
GthBrowser *browser = user_data;
GthImageViewerPage *self = GTH_IMAGE_VIEWER_PAGE (gth_browser_get_viewer_page (browser));
GthImageViewerPage *viewer_page = get_image_viewer_page (browser);
if (viewer_page == NULL)
return;
gth_image_viewer_zoom_out (GTH_IMAGE_VIEWER (gth_image_viewer_page_get_image_viewer (self)));
gth_image_viewer_zoom_out (GTH_IMAGE_VIEWER (gth_image_viewer_page_get_image_viewer (viewer_page)));
}
......@@ -57,9 +76,42 @@ gth_browser_activate_image_zoom_100 (GSimpleAction *action,
gpointer user_data)
{
GthBrowser *browser = user_data;
GthImageViewerPage *self = GTH_IMAGE_VIEWER_PAGE (gth_browser_get_viewer_page (browser));
GthImageViewerPage *viewer_page = get_image_viewer_page (browser);
if (viewer_page == NULL)
return;
gth_image_viewer_set_zoom (GTH_IMAGE_VIEWER (gth_image_viewer_page_get_image_viewer (viewer_page)), 1.0);
}
void
gth_browser_activate_image_zoom_200 (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
GthBrowser *browser = user_data;
GthImageViewerPage *viewer_page = get_image_viewer_page (browser);
if (viewer_page == NULL)
return;
gth_image_viewer_set_zoom (GTH_IMAGE_VIEWER (gth_image_viewer_page_get_image_viewer (self)), 1.0);
gth_image_viewer_set_zoom (GTH_IMAGE_VIEWER (gth_image_viewer_page_get_image_viewer (viewer_page)), 2.0);
}
void
gth_browser_activate_image_zoom_300 (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
GthBrowser *browser = user_data;
GthImageViewerPage *viewer_page = get_image_viewer_page (browser);
if (viewer_page == NULL)
return;
gth_image_viewer_set_zoom (GTH_IMAGE_VIEWER (gth_image_viewer_page_get_image_viewer (viewer_page)), 3.0);
}
......@@ -69,9 +121,12 @@ gth_browser_activate_image_zoom_fit (GSimpleAction *action,
gpointer user_data)
{
GthBrowser *browser = user_data;
GthImageViewerPage *self = GTH_IMAGE_VIEWER_PAGE (gth_browser_get_viewer_page (browser));
GthImageViewerPage *viewer_page = get_image_viewer_page (browser);
if (viewer_page == NULL)
return;
gth_image_viewer_set_fit_mode (GTH_IMAGE_VIEWER (gth_image_viewer_page_get_image_viewer (self)), GTH_FIT_SIZE);
gth_image_viewer_set_fit_mode (GTH_IMAGE_VIEWER (gth_image_viewer_page_get_image_viewer (viewer_page)), GTH_FIT_SIZE);
}
......@@ -81,9 +136,12 @@ gth_browser_activate_image_zoom_fit_if_larger (GSimpleAction *action,
gpointer user_data)
{
GthBrowser *browser = user_data;
GthImageViewerPage *self = GTH_IMAGE_VIEWER_PAGE (gth_browser_get_viewer_page (browser));
GthImageViewerPage *viewer_page = get_image_viewer_page (browser);
gth_image_viewer_set_fit_mode (GTH_IMAGE_VIEWER (gth_image_viewer_page_get_image_viewer (self)), GTH_FIT_SIZE_IF_LARGER);
if (viewer_page == NULL)
return;
gth_image_viewer_set_fit_mode (GTH_IMAGE_VIEWER (gth_image_viewer_page_get_image_viewer (viewer_page)), GTH_FIT_SIZE_IF_LARGER);
}
......@@ -93,9 +151,27 @@ gth_browser_activate_image_zoom_fit_width (GSimpleAction *action,
gpointer user_data)
{
GthBrowser *browser = user_data;
GthImageViewerPage *self = GTH_IMAGE_VIEWER_PAGE (gth_browser_get_viewer_page (browser));
GthImageViewerPage *viewer_page = get_image_viewer_page (browser);
gth_image_viewer_set_fit_mode (GTH_IMAGE_VIEWER (gth_image_viewer_page_get_image_viewer (self)), GTH_FIT_WIDTH);
if (viewer_page == NULL)
return;
gth_image_viewer_set_fit_mode (GTH_IMAGE_VIEWER (gth_image_viewer_page_get_image_viewer (viewer_page)), GTH_FIT_WIDTH);
}
void
gth_browser_activate_image_zoom_fit_width_if_larger (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
GthBrowser *browser = user_data;
GthImageViewerPage *viewer_page = get_image_viewer_page (browser);
if (viewer_page == NULL)
return;
gth_image_viewer_set_fit_mode (GTH_IMAGE_VIEWER (gth_image_viewer_page_get_image_viewer (viewer_page)), GTH_FIT_WIDTH_IF_LARGER);
}
......@@ -105,9 +181,27 @@ gth_browser_activate_image_zoom_fit_height (GSimpleAction *action,
gpointer user_data)
{
GthBrowser *browser = user_data;
GthImageViewerPage *self = GTH_IMAGE_VIEWER_PAGE (gth_browser_get_viewer_page (browser));
GthImageViewerPage *viewer_page = get_image_viewer_page (browser);
gth_image_viewer_set_fit_mode (GTH_IMAGE_VIEWER (gth_image_viewer_page_get_image_viewer (self)), GTH_FIT_HEIGHT);
if (viewer_page == NULL)
return;
gth_image_viewer_set_fit_mode (GTH_IMAGE_VIEWER (gth_image_viewer_page_get_image_viewer (viewer_page)), GTH_FIT_HEIGHT);
}
void
gth_browser_activate_image_zoom_fit_height_if_larger (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
GthBrowser *browser = user_data;
GthImageViewerPage *viewer_page = get_image_viewer_page (browser);
if (viewer_page == NULL)
return;
gth_image_viewer_set_fit_mode (GTH_IMAGE_VIEWER (gth_image_viewer_page_get_image_viewer (viewer_page)), GTH_FIT_HEIGHT_IF_LARGER);
}
......@@ -116,8 +210,13 @@ gth_browser_activate_image_undo (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
GthBrowser *browser = user_data;
gth_image_viewer_page_undo (GTH_IMAGE_VIEWER_PAGE (gth_browser_get_viewer_page (browser)));
GthBrowser *browser = user_data;
GthImageViewerPage *viewer_page = get_image_viewer_page (browser);
if (viewer_page == NULL)
return;
gth_image_viewer_page_undo (viewer_page);
}
......@@ -126,8 +225,13 @@ gth_browser_activate_image_redo (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
GthBrowser *browser = user_data;
gth_image_viewer_page_redo (GTH_IMAGE_VIEWER_PAGE (gth_browser_get_viewer_page (browser)));
GthBrowser *browser = user_data;
GthImageViewerPage *viewer_page = get_image_viewer_page (browser);
if (viewer_page == NULL)
return;
gth_image_viewer_page_redo (viewer_page);
}
......@@ -136,8 +240,13 @@ gth_browser_activate_copy_image (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
GthBrowser *browser = user_data;
gth_image_viewer_page_copy_image (GTH_IMAGE_VIEWER_PAGE (gth_browser_get_viewer_page (browser)));
GthBrowser *browser = user_data;
GthImageViewerPage *viewer_page = get_image_viewer_page (browser);
if (viewer_page == NULL)
return;
gth_image_viewer_page_copy_image (viewer_page);
}
......@@ -146,8 +255,13 @@ gth_browser_activate_paste_image (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
GthBrowser *browser = user_data;
gth_image_viewer_page_paste_image (GTH_IMAGE_VIEWER_PAGE (gth_browser_get_viewer_page (browser)));
GthBrowser *browser = user_data;
GthImageViewerPage *viewer_page = get_image_viewer_page (browser);
if (viewer_page == NULL)
return;
gth_image_viewer_page_paste_image (viewer_page);
}
......@@ -156,10 +270,14 @@ gth_browser_activate_apply_icc_profile (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
GthBrowser *browser = user_data;
GthBrowser *browser = user_data;
GthImageViewerPage *viewer_page = get_image_viewer_page (browser);
if (viewer_page == NULL)
return;
g_simple_action_set_state (action, state);
gth_image_viewer_page_apply_icc_profile (GTH_IMAGE_VIEWER_PAGE (gth_browser_get_viewer_page (browser)), g_variant_get_boolean (state));
gth_image_viewer_page_apply_icc_profile (viewer_page, g_variant_get_boolean (state));
}
......@@ -168,10 +286,15 @@ gth_browser_activate_transparency_style (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
GthBrowser *browser = user_data;
GthImageViewerPage *viewer_page = get_image_viewer_page (browser);
const char *state;
GthTransparencyStyle style;
GSettings *settings;
if (viewer_page == NULL)
return;
state = g_variant_get_string (parameter, NULL);
if (state == NULL)
return;
......@@ -199,9 +322,13 @@ gth_browser_activate_image_zoom (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
GthBrowser *browser = user_data;
const char *state;
GthImageViewer *image_viewer;
GthBrowser *browser = user_data;
GthImageViewerPage *viewer_page = get_image_viewer_page (browser);
const char *state;
GthImageViewer *image_viewer;
if (viewer_page == NULL)
return;
state = g_variant_get_string (parameter, NULL);
g_simple_action_set_state (action, g_variant_new_string (state));
......@@ -209,7 +336,7 @@ gth_browser_activate_image_zoom (GSimpleAction *action,
if (state == NULL)
return;
image_viewer = GTH_IMAGE_VIEWER (gth_image_viewer_page_get_image_viewer (GTH_IMAGE_VIEWER_PAGE (gth_browser_get_viewer_page (browser))));
image_viewer = GTH_IMAGE_VIEWER (gth_image_viewer_page_get_image_viewer (viewer_page));
if (strcmp (state, "automatic") == 0)
gth_image_viewer_set_fit_mode (image_viewer, GTH_FIT_SIZE_IF_LARGER);
else if (strcmp (state, "fit") == 0)
......@@ -234,20 +361,22 @@ gth_browser_activate_toggle_animation (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
GthBrowser *browser = user_data;
GthViewerPage *viewer_page;
GthImageViewer *image_viewer;
GthBrowser *browser = user_data;
GthImageViewerPage *viewer_page = get_image_viewer_page (browser);
GthImageViewer *image_viewer;
if (viewer_page == NULL)
return;
g_simple_action_set_state (action, state);
viewer_page = gth_browser_get_viewer_page (browser);
image_viewer = GTH_IMAGE_VIEWER (gth_image_viewer_page_get_image_viewer (GTH_IMAGE_VIEWER_PAGE (viewer_page)));
image_viewer = GTH_IMAGE_VIEWER (gth_image_viewer_page_get_image_viewer (viewer_page));
if (gth_image_viewer_is_playing_animation (image_viewer))
gth_image_viewer_stop_animation (image_viewer);
else
gth_image_viewer_start_animation (image_viewer);
gth_viewer_page_update_sensitivity (viewer_page);
gth_viewer_page_update_sensitivity (GTH_VIEWER_PAGE (viewer_page));
}
......@@ -256,11 +385,13 @@ gth_browser_activate_step_animation (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
GthBrowser *browser = user_data;
GthViewerPage *viewer_page;
GthImageViewer *image_viewer;
GthBrowser *browser = user_data;
GthImageViewerPage *viewer_page = get_image_viewer_page (browser);
GthImageViewer *image_viewer;
if (viewer_page == NULL)
return;
viewer_page = gth_browser_get_viewer_page (browser);
image_viewer = GTH_IMAGE_VIEWER (gth_image_viewer_page_get_image_viewer (GTH_IMAGE_VIEWER_PAGE (viewer_page)));
image_viewer = GTH_IMAGE_VIEWER (gth_image_viewer_page_get_image_viewer (viewer_page));
gth_image_viewer_step_animation (image_viewer);
}
......@@ -27,10 +27,14 @@
DEF_ACTION_CALLBACK (gth_browser_activate_image_zoom_in)
DEF_ACTION_CALLBACK (gth_browser_activate_image_zoom_out)
DEF_ACTION_CALLBACK (gth_browser_activate_image_zoom_100)
DEF_ACTION_CALLBACK (gth_browser_activate_image_zoom_200)
DEF_ACTION_CALLBACK (gth_browser_activate_image_zoom_300)
DEF_ACTION_CALLBACK (gth_browser_activate_image_zoom_fit)
DEF_ACTION_CALLBACK (gth_browser_activate_image_zoom_fit_if_larger)
DEF_ACTION_CALLBACK (gth_browser_activate_image_zoom_fit_width)
DEF_ACTION_CALLBACK (gth_browser_activate_image_zoom_fit_width_if_larger)
DEF_ACTION_CALLBACK (gth_browser_activate_image_zoom_fit_height)
DEF_ACTION_CALLBACK (gth_browser_activate_image_zoom_fit_height_if_larger)
DEF_ACTION_CALLBACK (gth_browser_activate_image_undo)
DEF_ACTION_CALLBACK (gth_browser_activate_image_redo)
DEF_ACTION_CALLBACK (gth_browser_activate_copy_image)
......
/* -*- 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 <glib/gi18n.h>
#include <glib-object.h>
#include <gthumb.h>
#include "callbacks.h"
static const GthShortcut shortcuts[] = {
{ "image-zoom-in", N_("Zoom In"), GTH_SHORTCUT_CONTEXT_VIEWER, GTH_SHORTCUT_CATEGORY_IMAGE_VIEW, "plus" },
{ "image-zoom-out", N_("Zoom Out"), GTH_SHORTCUT_CONTEXT_VIEWER, GTH_SHORTCUT_CATEGORY_IMAGE_VIEW, "minus" },
{ "image-zoom-100", N_("Zoom 100%"), GTH_SHORTCUT_CONTEXT_VIEWER, GTH_SHORTCUT_CATEGORY_IMAGE_VIEW, "1" },
{ "image-zoom-200", N_("Zoom 200%"), GTH_SHORTCUT_CONTEXT_VIEWER, GTH_SHORTCUT_CATEGORY_IMAGE_VIEW, "2" },
{ "image-zoom-300", N_("Zoom 300%"), GTH_SHORTCUT_CONTEXT_VIEWER, GTH_SHORTCUT_CATEGORY_IMAGE_VIEW, "3" },
{ "image-zoom-fit", N_("Zoom To Fit"), GTH_SHORTCUT_CONTEXT_VIEWER, GTH_SHORTCUT_CATEGORY_IMAGE_VIEW, "<shift>X" },
{ "image-zoom-fit-if-larger", N_("Zoom To Fit If Larger"), GTH_SHORTCUT_CONTEXT_VIEWER, GTH_SHORTCUT_CATEGORY_IMAGE_VIEW, "X" },
{ "image-zoom-fit-width", N_("Zoom To Fit Width"), GTH_SHORTCUT_CONTEXT_VIEWER, GTH_SHORTCUT_CATEGORY_IMAGE_VIEW, "<shift>W" },
{ "image-zoom-fit-width-if-larger", N_("Zoom To Fit Width If Larger"), GTH_SHORTCUT_CONTEXT_VIEWER, GTH_SHORTCUT_CATEGORY_IMAGE_VIEW, "W" },
{ "image-zoom-fit-height", N_("Zoom To Fit Height"), GTH_SHORTCUT_CONTEXT_VIEWER, GTH_SHORTCUT_CATEGORY_IMAGE_VIEW, "<shift>H" },
{ "image-zoom-fit-height-if-larger", N_("Zoom To Fit Height If Larger"), GTH_SHORTCUT_CONTEXT_VIEWER, GTH_SHORTCUT_CATEGORY_IMAGE_VIEW, "H" },
{ "image-undo", N_("Undo Edit"), GTH_SHORTCUT_CONTEXT_VIEWER, GTH_SHORTCUT_CATEGORY_IMAGE_VIEW, "<control>Z" },
{ "image-redo", N_("Redo Edit"), GTH_SHORTCUT_CONTEXT_VIEWER, GTH_SHORTCUT_CATEGORY_IMAGE_VIEW, "<shift><control>Z" },
};
void
image_viewer__gth_browser_construct_cb (GthBrowser *browser)
{
g_return_if_fail (GTH_IS_BROWSER (browser));
gth_window_add_shortcuts (GTH_WINDOW (browser),
shortcuts,
G_N_ELEMENTS (shortcuts));
}
/* -*- 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 CALLBACKS_H
#define CALLBACKS_H
#include <gthumb.h>
void image_viewer__gth_browser_construct_cb (GthBrowser *browser);
#endif /* CALLBACKS_H */
......@@ -50,10 +50,14 @@ static const GActionEntry actions[] = {
{ "image-zoom-in", gth_browser_activate_image_zoom_in },
{ "image-zoom-out", gth_browser_activate_image_zoom_out },
{ "image-zoom-100", gth_browser_activate_image_zoom_100 },
{ "image-zoom-200", gth_browser_activate_image_zoom_200 },
{ "image-zoom-300", gth_browser_activate_image_zoom_300 },
{ "image-zoom-fit", gth_browser_activate_image_zoom_fit },
{ "image-zoom-fit-if-larger", gth_browser_activate_image_zoom_fit_if_larger },
{ "image-zoom-fit-width", gth_browser_activate_image_zoom_fit_width },
{ "image-zoom-fit-width-if-larger", gth_browser_activate_image_zoom_fit_width_if_larger },
{ "image-zoom-fit-height", gth_browser_activate_image_zoom_fit_height },
{ "image-zoom-fit-height-if-larger", gth_browser_activate_image_zoom_fit_height_if_larger },
{ "image-undo", gth_browser_activate_image_undo },
{ "image-redo", gth_browser_activate_image_redo },
{ "copy-image", gth_browser_activate_copy_image },
......@@ -66,15 +70,6 @@ static const GActionEntry actions[] = {
};
static const GthAccelerator accelerators[] = {
{ "image-zoom-in", "<control>plus" },
{ "image-zoom-out", "<control>minus" },
{ "image-zoom-100", "<control>0" },
{ "image-undo", "<control>z" },
{ "image-redo", "<shift><control>z" },
};
static const GthMenuEntry file_popup_entries[] = {
{ N_("Copy Image"), "win.copy-image" },
{ N_("Paste Image"), "win.paste-image" },
......@@ -1191,8 +1186,6 @@ gth_image_viewer_page_real_activate (GthViewerPage *base,
_("Transparency"),
_gtk_builder_get_widget (self->priv->builder, "transparency_popover"));
gth_window_add_accelerators (GTH_WINDOW (browser), accelerators, G_N_ELEMENTS (accelerators));
self->priv->preloader = gth_browser_get_image_preloader (browser);
self->priv->viewer = gth_image_viewer_new ();
......@@ -2234,6 +2227,7 @@ gth_image_viewer_page_reset_viewer_tool (GthImageViewerPage *self)
g_settings_get_enum (self->priv->settings, PREF_IMAGE_VIEWER_ZOOM_CHANGE));
gth_image_viewer_set_reset_scrollbars (GTH_IMAGE_VIEWER (self->priv->viewer),
g_settings_get_boolean (self->priv->settings, PREF_IMAGE_VIEWER_RESET_SCROLLBARS));
gth_image_viewer_enable_key_bindings (GTH_IMAGE_VIEWER (self->priv->viewer), FALSE);
pref_transparency_style_changed (self->priv->settings, NULL, self);
_gth_image_viewer_page_enable_drag_source (self, TRUE);
}
......
......@@ -26,6 +26,7 @@
#include "gth-image-histogram.h"
#include "gth-image-viewer-page.h"
#include "gth-metadata-provider-image.h"
#include "callbacks.h"
#include "preferences.h"
......@@ -36,6 +37,7 @@ gthumb_extension_activate (void)
gth_main_register_object (GTH_TYPE_VIEWER_PAGE, NULL, GTH_TYPE_IMAGE_VIEWER_PAGE, NULL);
gth_main_register_type ("file-properties", GTH_TYPE_IMAGE_HISTOGRAM);
gth_hook_add_callback ("dlg-preferences-construct", 10, G_CALLBACK (image_viewer__dlg_preferences_construct_cb), NULL);
gth_hook_add_callback ("gth-browser-construct", 7, G_CALLBACK (image_viewer__gth_browser_construct_cb), NULL);
}
......
source_files = files(
'actions.c',
'callbacks.c',
'gth-image-histogram.c',
'gth-image-viewer-page.c',
'gth-image-viewer-page-tool.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