From 4d91ce6a1f547d3a75da7cbc956033fbf65c7c0c Mon Sep 17 00:00:00 2001 From: Carlos Garcia Campos Date: Wed, 31 Mar 2010 16:18:18 +0200 Subject: [PATCH] [previewer] Add some more keybindings --- data/evince-previewer-ui.xml | 18 +++++++ previewer/ev-previewer-window.c | 95 +++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+) diff --git a/data/evince-previewer-ui.xml b/data/evince-previewer-ui.xml index 2987c502..32c75afd 100644 --- a/data/evince-previewer-ui.xml +++ b/data/evince-previewer-ui.xml @@ -12,4 +12,22 @@ + + + + + + + + + + + + + + + + + + diff --git a/previewer/ev-previewer-window.c b/previewer/ev-previewer-window.c index 2c884f67..91e25a8a 100644 --- a/previewer/ev-previewer-window.c +++ b/previewer/ev-previewer-window.c @@ -36,6 +36,7 @@ struct _EvPreviewerWindow { EvDocument *document; GtkActionGroup *action_group; + GtkActionGroup *accels_group; GtkUIManager *ui_manager; GtkWidget *swindow; @@ -152,6 +153,31 @@ ev_previewer_window_action_page_activated (GtkAction *action, gtk_widget_grab_focus (GTK_WIDGET (window->view)); } +static void +ev_previewer_window_focus_page_selector (GtkAction *action, + EvPreviewerWindow *window) +{ + GtkAction *page_action; + + page_action = gtk_action_group_get_action (window->action_group, + "PageSelector"); + ev_page_action_grab_focus (EV_PAGE_ACTION (page_action)); +} + +static void +ev_previewer_window_scroll_forward (GtkAction *action, + EvPreviewerWindow *window) +{ + ev_view_scroll (window->view, GTK_SCROLL_PAGE_FORWARD, FALSE); +} + +static void +ev_previewer_window_scroll_backward (GtkAction *action, + EvPreviewerWindow *window) +{ + ev_view_scroll (window->view, GTK_SCROLL_PAGE_BACKWARD, FALSE); +} + #if GTKUNIXPRINT_ENABLED static void ev_previewer_window_print_finished (GtkPrintJob *print_job, @@ -264,6 +290,44 @@ static const GtkActionEntry action_entries[] = { #endif }; +static const GtkActionEntry accel_entries[] = { + { "Space", NULL, "", "space", NULL, + G_CALLBACK (ev_previewer_window_scroll_forward) }, + { "ShiftSpace", NULL, "", "space", NULL, + G_CALLBACK (ev_previewer_window_scroll_backward) }, + { "BackSpace", NULL, "", "BackSpace", NULL, + G_CALLBACK (ev_previewer_window_scroll_backward) }, + { "ShiftBackSpace", NULL, "", "BackSpace", NULL, + G_CALLBACK (ev_previewer_window_scroll_forward) }, + { "Return", NULL, "", "Return", NULL, + G_CALLBACK (ev_previewer_window_scroll_forward) }, + { "ShiftReturn", NULL, "", "Return", NULL, + G_CALLBACK (ev_previewer_window_scroll_backward) }, + { "p", GTK_STOCK_GO_UP, "", "p", NULL, + G_CALLBACK (ev_previewer_window_previous_page) }, + { "n", GTK_STOCK_GO_DOWN, "", "n", NULL, + G_CALLBACK (ev_previewer_window_next_page) }, + { "Plus", GTK_STOCK_ZOOM_IN, NULL, "plus", NULL, + G_CALLBACK (ev_previewer_window_zoom_in) }, + { "CtrlEqual", GTK_STOCK_ZOOM_IN, NULL, "equal", NULL, + G_CALLBACK (ev_previewer_window_zoom_in) }, + { "Equal", GTK_STOCK_ZOOM_IN, NULL, "equal", NULL, + G_CALLBACK (ev_previewer_window_zoom_in) }, + { "Minus", GTK_STOCK_ZOOM_OUT, NULL, "minus", NULL, + G_CALLBACK (ev_previewer_window_zoom_out) }, + { "KpPlus", GTK_STOCK_ZOOM_IN, NULL, "KP_Add", NULL, + G_CALLBACK (ev_previewer_window_zoom_in) }, + { "KpMinus", GTK_STOCK_ZOOM_OUT, NULL, "KP_Subtract", NULL, + G_CALLBACK (ev_previewer_window_zoom_out) }, + { "CtrlKpPlus", GTK_STOCK_ZOOM_IN, NULL, "KP_Add", NULL, + G_CALLBACK (ev_previewer_window_zoom_in) }, + { "CtrlKpMinus", GTK_STOCK_ZOOM_OUT, NULL, "KP_Subtract", NULL, + G_CALLBACK (ev_previewer_window_zoom_out) }, + { "FocusPageSelector", NULL, "", "l", NULL, + G_CALLBACK (ev_previewer_window_focus_page_selector) } + +}; + static const GtkToggleActionEntry toggle_action_entries[] = { { "ViewBestFit", EV_STOCK_ZOOM_PAGE, N_("_Best Fit"), NULL, N_("Make the current document fill the window"), @@ -273,6 +337,17 @@ static const GtkToggleActionEntry toggle_action_entries[] = { G_CALLBACK (ev_previewer_window_zoom_page_width) } }; +static gboolean +view_focus_changed (GtkWidget *widget, + GdkEventFocus *event, + EvPreviewerWindow *window) +{ + if (window->accels_group) + gtk_action_group_set_sensitive (window->accels_group, event->in); + + return FALSE; +} + static void view_sizing_mode_changed (EvDocumentModel *model, GParamSpec *pspec, @@ -316,6 +391,7 @@ ev_previewer_window_set_document (EvPreviewerWindow *window, window); ev_view_set_loading (window->view, FALSE); gtk_action_group_set_sensitive (window->action_group, TRUE); + gtk_action_group_set_sensitive (window->accels_group, TRUE); } static void @@ -350,6 +426,11 @@ ev_previewer_window_dispose (GObject *object) window->action_group = NULL; } + if (window->accels_group) { + g_object_unref (window->accels_group); + window->accels_group = NULL; + } + if (window->ui_manager) { g_object_unref (window->ui_manager); window->ui_manager = NULL; @@ -476,9 +557,17 @@ ev_previewer_window_constructor (GType type, gtk_action_group_add_action (window->action_group, action); g_object_unref (action); + window->accels_group = gtk_action_group_new ("PreviewerAccelerators"); + gtk_action_group_add_actions (window->accels_group, accel_entries, + G_N_ELEMENTS (accel_entries), + window); + gtk_action_group_set_sensitive (window->accels_group, FALSE); + window->ui_manager = gtk_ui_manager_new (); gtk_ui_manager_insert_action_group (window->ui_manager, window->action_group, 0); + gtk_ui_manager_insert_action_group (window->ui_manager, + window->accels_group, 1); gtk_window_add_accel_group (GTK_WINDOW (window), gtk_ui_manager_get_accel_group (window->ui_manager)); datadir = data_dir (); @@ -509,6 +598,12 @@ ev_previewer_window_constructor (GType type, GTK_POLICY_AUTOMATIC); window->view = EV_VIEW (ev_view_new ()); + g_signal_connect_object (window->view, "focus_in_event", + G_CALLBACK (view_focus_changed), + window, 0); + g_signal_connect_object (window->view, "focus_out_event", + G_CALLBACK (view_focus_changed), + window, 0); ev_view_set_model (window->view, window->model); ev_document_model_set_continuous (window->model, FALSE); ev_view_set_loading (window->view, TRUE); -- 2.43.5