]> www.fi.muni.cz Git - evince.git/commitdiff
[previewer] Add some more keybindings
authorCarlos Garcia Campos <carlosgc@gnome.org>
Wed, 31 Mar 2010 14:18:18 +0000 (16:18 +0200)
committerCarlos Garcia Campos <carlosgc@gnome.org>
Wed, 31 Mar 2010 14:18:18 +0000 (16:18 +0200)
data/evince-previewer-ui.xml
previewer/ev-previewer-window.c

index 2987c5023e9b2ac50efd97b4863239d56154510c..32c75afdf3436e224f9cc24f99397090c6908db8 100644 (file)
     <separator/>
     <toolitem name="PreviewPrint" action="PreviewPrint"/>
   </toolbar>
+
+  <accelerator name="SpaceAccel" action="Space"/>
+  <accelerator name="ReturnAccel" action="Return"/>
+  <accelerator name="BackSpaceAccel" action="BackSpace"/>
+  <accelerator name="ShiftSpaceAccel" action="ShiftSpace"/>
+  <accelerator name="ShiftBackSpaceAccel" action="ShiftBackSpace"/>
+  <accelerator name="pAccel" action="p"/>
+  <accelerator name="nAccel" action="n"/>
+  <accelerator name="ShiftReturnAccel" action="ShiftReturn"/>
+  <accelerator name="FocusPageSelectorAccel" action="FocusPageSelector"/>
+  <accelerator name="PlusAccel" action="Plus"/>
+  <accelerator name="MinusAccel" action="Minus"/>
+  <accelerator name="Equal" action="Equal"/>
+  <accelerator name="CtrlEqualAccel" action="CtrlEqual"/>
+  <accelerator name="KpPlusAccel" action="KpPlus"/>
+  <accelerator name="KpMinusAccel" action="KpMinus"/>
+  <accelerator name="CtrlKpPlusAccel" action="CtrlKpPlus"/>
+  <accelerator name="CtrlKpMinusAccel" action="CtrlKpMinus"/>
 </ui>
index 2c884f67c6f007b70f50d732056face514dd4f77..91e25a8a16800efa70a913d354b221874ddc9d9d 100644 (file)
@@ -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, "", "<shift>space", NULL,
+         G_CALLBACK (ev_previewer_window_scroll_backward) },
+       { "BackSpace", NULL, "", "BackSpace", NULL,
+         G_CALLBACK (ev_previewer_window_scroll_backward) },
+       { "ShiftBackSpace", NULL, "", "<shift>BackSpace", NULL,
+         G_CALLBACK (ev_previewer_window_scroll_forward) },
+       { "Return", NULL, "", "Return", NULL,
+         G_CALLBACK (ev_previewer_window_scroll_forward) },
+       { "ShiftReturn", NULL, "", "<shift>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, "<control>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, "<control>KP_Add", NULL,
+         G_CALLBACK (ev_previewer_window_zoom_in) },
+       { "CtrlKpMinus", GTK_STOCK_ZOOM_OUT, NULL, "<control>KP_Subtract", NULL,
+         G_CALLBACK (ev_previewer_window_zoom_out) },
+       { "FocusPageSelector", NULL, "", "<control>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);