]> www.fi.muni.cz Git - evince.git/commitdiff
This is evil... Make space/backspace global accelerators but enable them
authorMarco Pesenti Gritti <mpg@redhat.com>
Tue, 10 May 2005 12:09:35 +0000 (12:09 +0000)
committerMarco Pesenti Gritti <marco@src.gnome.org>
Tue, 10 May 2005 12:09:35 +0000 (12:09 +0000)
2005-05-10  Marco Pesenti Gritti  <mpg@redhat.com>

        * data/evince-ui.xml:
        * shell/ev-sidebar-links.c: (ev_sidebar_links_get_treeview):
        * shell/ev-sidebar-links.h:
        * shell/ev-sidebar-thumbnails.c:
        (ev_sidebar_thumbnails_get_treeview):
        * shell/ev-sidebar-thumbnails.h:
        * shell/ev-view.c: (ev_view_scroll), (ev_view_scroll_view),
        (ev_view_class_init):
        * shell/ev-view.h:
        * shell/ev-window.c: (update_action_sensitivity),
        (ev_window_cmd_scroll_forward), (ev_window_cmd_scroll_backward),
        (set_view_actions_sensitivity), (view_actions_focus_in_cb),
        (view_actions_focus_out_cb), (enable_view_actions_for_widget),
        (ev_window_init):

        This is evil... Make space/backspace global accelerators but
        enable them only for some widgets (sidebars and view).
        I dont like it, but I dont know a better way... :/

ChangeLog
data/evince-ui.xml
shell/ev-sidebar-links.c
shell/ev-sidebar-links.h
shell/ev-sidebar-thumbnails.c
shell/ev-sidebar-thumbnails.h
shell/ev-view.c
shell/ev-view.h
shell/ev-window.c

index d72ac1eb19132f5ced491befe02d89c4fb8de841..76b0a549ef6040180ac7fc087ea131d5b58c1134 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2005-05-10  Marco Pesenti Gritti  <mpg@redhat.com>
+
+       * data/evince-ui.xml:
+       * shell/ev-sidebar-links.c: (ev_sidebar_links_get_treeview):
+       * shell/ev-sidebar-links.h:
+       * shell/ev-sidebar-thumbnails.c:
+       (ev_sidebar_thumbnails_get_treeview):
+       * shell/ev-sidebar-thumbnails.h:
+       * shell/ev-view.c: (ev_view_scroll), (ev_view_scroll_view),
+       (ev_view_class_init):
+       * shell/ev-view.h:
+       * shell/ev-window.c: (update_action_sensitivity),
+       (ev_window_cmd_scroll_forward), (ev_window_cmd_scroll_backward),
+       (set_view_actions_sensitivity), (view_actions_focus_in_cb),
+       (view_actions_focus_out_cb), (enable_view_actions_for_widget),
+       (ev_window_init):
+
+       This is evil... Make space/backspace global accelerators but
+       enable them only for some widgets (sidebars and view).
+       I dont like it, but I dont know a better way... :/
+
 2005-05-10  Marco Pesenti Gritti  <mpg@redhat.com>
 
        * shell/ev-page-action.c: (ev_page_action_widget_set_page_cache),
index 4df3061b1abe05f412040d18682ce110d1025165..bd9566d3a8b67c5fe53098ec9d80892775698d1a 100644 (file)
@@ -65,5 +65,9 @@
 
   <accelerator name="EscapeAccel" action="Escape"/>
   <accelerator name="SlashAccel" action="Slash"/>
+  <accelerator name="SpaceAccel" action="Space"/>
+  <accelerator name="BackSpaceAccel" action="BackSpace"/>
+  <accelerator name="ShiftSpaceAccel" action="ShiftSpace"/>
+  <accelerator name="ShiftBackSpaceAccel" action="ShiftBackSpace"/>
 
 </ui>
index 80376f2d4c2346083247259ca5d2db1ad3bbf3e6..80eb610b4a1d2699a1f3564991612676aed0917c 100644 (file)
@@ -509,6 +509,12 @@ ev_sidebar_links_get_label (EvSidebarPage *sidebar_page)
     return _("Index");
 }
 
+GtkWidget *
+ev_sidebar_links_get_treeview (EvSidebarLinks *sidebar)
+{
+       return sidebar->priv->tree_view;
+}
+
 static void
 ev_sidebar_links_page_iface_init (EvSidebarPageIface *iface)
 {
index b9691e35a6bcf566ecf4136fd73de24990636d30..c6b212224cdfe2155d795c1acbd6b3523784b5cd 100644 (file)
@@ -52,6 +52,7 @@ struct _EvSidebarLinksClass {
 
 GType      ev_sidebar_links_get_type       (void);
 GtkWidget *ev_sidebar_links_new            (void);
+GtkWidget *ev_sidebar_links_get_treeview   (EvSidebarLinks *sidebar);
 
 G_END_DECLS
 
index 424d061df9b8a1000c95f39e0f12416595740f42..61d3cb838c2eb6e2673c0c64b427e386f8323fc4 100644 (file)
@@ -163,6 +163,12 @@ ev_sidebar_tree_selection_changed (GtkTreeSelection *selection,
        ev_page_cache_set_current_page (page_cache, page);
 }
 
+GtkWidget *
+ev_sidebar_thumbnails_get_treeview (EvSidebarThumbnails *sidebar)
+{
+       return sidebar->priv->tree_view;
+}
+
 static void
 ev_sidebar_thumbnails_init (EvSidebarThumbnails *ev_sidebar_thumbnails)
 {
index ccfc09b98d0733d87028c1691226e6980e10d94b..dc5007c25b6be1009087fd9e71ec628211f0bc90 100644 (file)
@@ -51,8 +51,9 @@ struct _EvSidebarThumbnailsClass {
        GtkVBoxClass base_class;
 };
 
-GType      ev_sidebar_thumbnails_get_type (void);
-GtkWidget *ev_sidebar_thumbnails_new      (void);
+GType      ev_sidebar_thumbnails_get_type     (void);
+GtkWidget *ev_sidebar_thumbnails_new          (void);
+GtkWidget *ev_sidebar_thumbnails_get_treeview (EvSidebarThumbnails *sidebar);
 
 G_END_DECLS
 
index cfcc8454889f69f9dfba28181255cc0644df9ebc..6dfe1815a7a4c6c5ffa39edfaf3fe6c7acaa6592 100644 (file)
@@ -59,11 +59,6 @@ enum {
   TARGET_TEXT_BUFFER_CONTENTS
 };
 
-enum {
-       EV_SCROLL_PAGE_FORWARD,
-       EV_SCROLL_PAGE_BACKWARD
-};
-
 static const GtkTargetEntry targets[] = {
        { "STRING", 0, TARGET_STRING },
        { "TEXT",   0, TARGET_TEXT },
@@ -1553,26 +1548,9 @@ add_scroll_binding_keypad (GtkBindingSet  *binding_set,
                                G_TYPE_BOOLEAN, horizontal);
 }
 
-static void
-add_scroll_binding_shifted (GtkBindingSet  *binding_set,
-                           guint           keyval,
-                           GtkScrollType   scroll_normal,
-                           GtkScrollType   scroll_shifted,
-                           gboolean        horizontal)
-{
-  gtk_binding_entry_add_signal (binding_set, keyval, 0,
-                                "scroll_view", 2,
-                                GTK_TYPE_SCROLL_TYPE, scroll_normal,
-                               G_TYPE_BOOLEAN, horizontal);
-  gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
-                                "scroll_view", 2,
-                                GTK_TYPE_SCROLL_TYPE, scroll_shifted,
-                               G_TYPE_BOOLEAN, horizontal);
-}
-
-static void
-ev_view_jump (EvView        *view,
-             GtkScrollType  scroll)
+void
+ev_view_scroll (EvView        *view,
+               EvScrollType   scroll)
 {
        GtkAdjustment *adjustment;
        double value, increment;
@@ -1633,8 +1611,6 @@ ev_view_scroll_view (EvView *view,
                ev_page_cache_prev_page (view->page_cache);
        } else if (scroll == GTK_SCROLL_PAGE_FORWARD) {
                ev_page_cache_next_page (view->page_cache);
-       } else if (scroll == EV_SCROLL_PAGE_BACKWARD || scroll == EV_SCROLL_PAGE_FORWARD) {
-               ev_view_jump (view, scroll);
        } else {
                GtkAdjustment *adjustment;
                double value;
@@ -1841,9 +1817,6 @@ ev_view_class_init (EvViewClass *class)
 
        add_scroll_binding_keypad (binding_set, GDK_Page_Up,   GTK_SCROLL_PAGE_BACKWARD, FALSE);
        add_scroll_binding_keypad (binding_set, GDK_Page_Down, GTK_SCROLL_PAGE_FORWARD,  FALSE);
-
-       add_scroll_binding_shifted (binding_set, GDK_space, EV_SCROLL_PAGE_FORWARD, EV_SCROLL_PAGE_BACKWARD, FALSE);
-       add_scroll_binding_shifted (binding_set, GDK_BackSpace, EV_SCROLL_PAGE_BACKWARD, EV_SCROLL_PAGE_FORWARD, FALSE);
 }
 
 static void
index c0108c59b16c3d4a01f9024ae7e4bbc8f8f6eba8..f0492e334a5a9c50627bf03eb9337af69dd76f71 100644 (file)
@@ -42,68 +42,73 @@ typedef enum {
        EV_SIZING_FREE,
 } EvSizingMode;
 
-GType          ev_view_get_type        (void) G_GNUC_CONST;
-GType           ev_sizing_mode_get_type (void) G_GNUC_CONST;
-GtkWidget*     ev_view_new             (void);
-void           ev_view_set_document    (EvView     *view,
-                                        EvDocument *document);
+typedef enum {
+       EV_SCROLL_PAGE_FORWARD,
+       EV_SCROLL_PAGE_BACKWARD
+} EvScrollType;
 
-/* Clipboard */
-void           ev_view_copy            (EvView     *view);
-void           ev_view_select_all      (EvView     *view);
+GType          ev_view_get_type          (void) G_GNUC_CONST;
+GType           ev_sizing_mode_get_type   (void) G_GNUC_CONST;
+GtkWidget*     ev_view_new               (void);
+void           ev_view_set_document      (EvView         *view,
+                                          EvDocument     *document);
 
+/* Clipboard */
+void           ev_view_copy              (EvView         *view);
+void           ev_view_select_all        (EvView         *view);
 
 /* sizing and behavior */
 /* These are all orthoganal to each other, except 'presentation' trumps all
  * other behaviors
  */
-void           ev_view_set_continuous          (EvView       *view,
-                                                gboolean      continuous);
-void           ev_view_set_dual_page           (EvView       *view,
-                                                gboolean      dual_page);
-void           ev_view_set_fullscreen          (EvView       *view,
-                                                gboolean      fullscreen);
-gboolean       ev_view_get_fullscreen          (EvView       *view);
-void           ev_view_set_presentation        (EvView       *view,
-                                                gboolean      presentation);
-gboolean       ev_view_get_presentation        (EvView       *view);
-void           ev_view_set_sizing_mode         (EvView       *view,
-                                                EvSizingMode  mode);
-EvSizingMode   ev_view_get_sizing_mode         (EvView       *view);
+void           ev_view_set_continuous    (EvView         *view,
+                                          gboolean        continuous);
+void           ev_view_set_dual_page     (EvView         *view,
+                                          gboolean        dual_page);
+void           ev_view_set_fullscreen    (EvView         *view,
+                                          gboolean        fullscreen);
+gboolean       ev_view_get_fullscreen    (EvView         *view);
+void           ev_view_set_presentation  (EvView         *view,
+                                          gboolean        presentation);
+gboolean       ev_view_get_presentation  (EvView         *view);
+void           ev_view_set_sizing_mode   (EvView         *view,
+                                          EvSizingMode    mode);
+EvSizingMode   ev_view_get_sizing_mode   (EvView         *view);
 
 
 /* Page size */
-gboolean       ev_view_can_zoom_in     (EvView     *view);
-void           ev_view_zoom_in         (EvView     *view);
-gboolean        ev_view_can_zoom_out    (EvView     *view);
-void           ev_view_zoom_out        (EvView     *view);
-void           ev_view_set_zoom        (EvView     *view,
-                                        double      factor,
-                                        gboolean    relative);
-double         ev_view_get_zoom        (EvView      *view);
-
-void           ev_view_set_zoom_for_size (EvView     *view,
-                                          int         width,
-                                          int         height,
-                                          int         vsb_width,
-                                          int         hsb_height);
-void           ev_view_zoom_normal     (EvView     *view);
-void           ev_view_set_size        (EvView     *view,
-                                        int         width,
-                                        int         height);
+gboolean       ev_view_can_zoom_in       (EvView         *view);
+void           ev_view_zoom_in           (EvView         *view);
+gboolean        ev_view_can_zoom_out      (EvView         *view);
+void           ev_view_zoom_out          (EvView         *view);
+void           ev_view_set_zoom          (EvView         *view,
+                                          double          factor,
+                                          gboolean        relative);
+double         ev_view_get_zoom          (EvView         *view);
+
+void           ev_view_set_zoom_for_size (EvView         *view,
+                                          int             width,
+                                          int             height,
+                                          int             vsb_width,
+                                          int             hsb_height);
+void           ev_view_zoom_normal       (EvView         *view);
 
 /* Find */
-gboolean       ev_view_can_find_next   (EvView     *view);
-void            ev_view_find_next       (EvView     *view);
-void            ev_view_find_previous   (EvView     *view);
+gboolean       ev_view_can_find_next     (EvView         *view);
+void            ev_view_find_next         (EvView         *view);
+void            ev_view_find_previous     (EvView         *view);
 
 /* Status */
-const char     *ev_view_get_status      (EvView     *view);
-const char     *ev_view_get_find_status (EvView     *view);
+const char     *ev_view_get_status        (EvView         *view);
+const char     *ev_view_get_find_status   (EvView         *view);
 
 /* Cursor */
-void           ev_view_hide_cursor     (EvView     *view);
-void           ev_view_show_cursor     (EvView     *view);
+void           ev_view_hide_cursor        (EvView         *view);
+void           ev_view_show_cursor        (EvView         *view);
+
+/* Scrolling */
+void          ev_view_scroll             (EvView         *view,
+                                          EvScrollType    scroll);
 
 G_END_DECLS
 
index 489c1cc01b9b3f8efae60077f683041a55e26e82..1aba5eb1c5c93dbf5ccd6a5b49d96401d825c917 100644 (file)
@@ -252,9 +252,6 @@ update_action_sensitivity (EvWindow *ev_window)
                set_action_sensitive (ev_window, "SinglePage", FALSE);
                set_action_sensitive (ev_window, "ContinuousPage", FALSE);
        }
-       /* Help menu */
-       /* "HelpContents": always sensitive */
-       /* "HelpAbout": always sensitive */
 
        /* Toolbar-specific actions: */
        set_action_sensitive (ev_window, PAGE_SELECTOR_ACTION, has_pages);
@@ -341,6 +338,18 @@ update_chrome_flag (EvWindow *window, EvChrome flag, const char *pref, gboolean
        update_chrome_visibility (window);
 }
 
+static void
+ev_window_cmd_scroll_forward (GtkAction *action, EvWindow *window)
+{
+       ev_view_scroll (EV_VIEW (window->priv->view), EV_SCROLL_PAGE_FORWARD);
+}
+
+static void
+ev_window_cmd_scroll_backward (GtkAction *action, EvWindow *window)
+{
+       ev_view_scroll (EV_VIEW (window->priv->view), EV_SCROLL_PAGE_BACKWARD);
+}
+
 static void
 ev_window_cmd_continuous (GtkAction *action, EvWindow *ev_window)
 {
@@ -2375,7 +2384,19 @@ static const GtkActionEntry entries[] = {
          G_CALLBACK (ev_window_cmd_escape) },
         { "Slash", GTK_STOCK_FIND, NULL, "slash",
           N_("Find a word or phrase in the document"),
-          G_CALLBACK (ev_window_cmd_edit_find) }
+          G_CALLBACK (ev_window_cmd_edit_find) },
+        { "Space", GTK_STOCK_FIND, NULL, "space",
+          N_("Scroll one page forward"),
+          G_CALLBACK (ev_window_cmd_scroll_forward) },
+        { "ShiftSpace", GTK_STOCK_FIND, NULL, "<shift>space",
+          N_("Scroll one page backward"),
+          G_CALLBACK (ev_window_cmd_scroll_backward) },
+        { "BackSpace", GTK_STOCK_FIND, NULL, "BackSpace",
+          N_("Scroll one page backward"),
+          G_CALLBACK (ev_window_cmd_scroll_backward) },
+        { "ShiftBackSpace", GTK_STOCK_FIND, NULL, "<shift>BackSpace",
+          N_("Scroll one page forward"),
+          G_CALLBACK (ev_window_cmd_scroll_forward) }
 };
 
 /* Toggle items */
@@ -2589,13 +2610,48 @@ sidebar_widget_model_set (EvSidebarLinks *ev_sidebar_links,
        ev_page_action_set_model (EV_PAGE_ACTION (action), model);
 }
 
+
+static void
+set_view_actions_sensitivity (EvWindow *window, gboolean sensitive)
+{
+       if (window->priv->action_group) {
+               set_action_sensitive (window, "Space", sensitive);
+               set_action_sensitive (window, "ShiftSpace", sensitive);
+               set_action_sensitive (window, "BackSpace", sensitive);
+               set_action_sensitive (window, "ShiftBackSpace", sensitive);
+       }
+}
+
+static void
+view_actions_focus_in_cb (GtkWidget *widget, GdkEventFocus *event, EvWindow *window)
+{
+       set_view_actions_sensitivity (window, TRUE);
+}
+
+static void
+view_actions_focus_out_cb (GtkWidget *widget, GdkEventFocus *event, EvWindow *window)
+{
+       set_view_actions_sensitivity (window, FALSE);
+}
+
+static void
+enable_view_actions_for_widget (EvWindow *window, GtkWidget *widget)
+{
+       g_signal_connect_object (widget, "focus_in_event",
+                                G_CALLBACK (view_actions_focus_in_cb),
+                                window, 0);
+       g_signal_connect_object (widget, "focus_out_event",
+                                G_CALLBACK (view_actions_focus_out_cb),
+                                window, 0);
+}
+
 static void
 ev_window_init (EvWindow *ev_window)
 {
        GtkActionGroup *action_group;
        GtkAccelGroup *accel_group;
        GError *error = NULL;
-       GtkWidget *sidebar_widget, *toolbar_dock;
+       GtkWidget *sidebar_widget, *toolbar_dock, *tree_view;
        GConfValue *value;
        GConfClient *client;
        int sidebar_size;
@@ -2633,6 +2689,8 @@ ev_window_init (EvWindow *ev_window)
                gtk_ui_manager_get_accel_group (ev_window->priv->ui_manager);
        gtk_window_add_accel_group (GTK_WINDOW (ev_window), accel_group);
 
+       set_view_actions_sensitivity (ev_window, FALSE);
+
        g_signal_connect (ev_window->priv->ui_manager, "connect_proxy",
                          G_CALLBACK (connect_proxy_cb), ev_window);
        g_signal_connect (ev_window->priv->ui_manager, "disconnect_proxy",
@@ -2721,11 +2779,17 @@ ev_window_init (EvWindow *ev_window)
                          "notify::model",
                          G_CALLBACK (sidebar_widget_model_set),
                          ev_window);
+       tree_view = ev_sidebar_links_get_treeview
+                       (EV_SIDEBAR_LINKS (sidebar_widget));
+       enable_view_actions_for_widget (ev_window, tree_view);
        gtk_widget_show (sidebar_widget);
        ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
                             sidebar_widget);
 
        sidebar_widget = ev_sidebar_thumbnails_new ();
+       tree_view = ev_sidebar_thumbnails_get_treeview
+                       (EV_SIDEBAR_THUMBNAILS (sidebar_widget));
+       enable_view_actions_for_widget (ev_window, tree_view);
        gtk_widget_show (sidebar_widget);
        ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
                             sidebar_widget);
@@ -2745,8 +2809,8 @@ ev_window_init (EvWindow *ev_window)
                                  "unlock",
                                  G_CALLBACK (ev_window_popup_password_dialog),
                                  ev_window);
+       enable_view_actions_for_widget (ev_window, ev_window->priv->view);
        gtk_widget_show (ev_window->priv->view);
-       //gtk_widget_show (ev_window->priv->page_view);
        gtk_widget_show (ev_window->priv->password_view);
 
        /* We own a ref on these widgets, as we can swap them in and out */