From: Marco Pesenti Gritti Date: Tue, 10 May 2005 12:09:35 +0000 (+0000) Subject: This is evil... Make space/backspace global accelerators but enable them X-Git-Tag: EVINCE_0_3_1~42 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=dfbedebc6a9968eed8932649e72e80a497dbfed5;p=evince.git This is evil... Make space/backspace global accelerators but enable them 2005-05-10 Marco Pesenti Gritti * 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... :/ --- diff --git a/ChangeLog b/ChangeLog index d72ac1eb..76b0a549 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +2005-05-10 Marco Pesenti Gritti + + * 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 * shell/ev-page-action.c: (ev_page_action_widget_set_page_cache), diff --git a/data/evince-ui.xml b/data/evince-ui.xml index 4df3061b..bd9566d3 100644 --- a/data/evince-ui.xml +++ b/data/evince-ui.xml @@ -65,5 +65,9 @@ + + + + diff --git a/shell/ev-sidebar-links.c b/shell/ev-sidebar-links.c index 80376f2d..80eb610b 100644 --- a/shell/ev-sidebar-links.c +++ b/shell/ev-sidebar-links.c @@ -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) { diff --git a/shell/ev-sidebar-links.h b/shell/ev-sidebar-links.h index b9691e35..c6b21222 100644 --- a/shell/ev-sidebar-links.h +++ b/shell/ev-sidebar-links.h @@ -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 diff --git a/shell/ev-sidebar-thumbnails.c b/shell/ev-sidebar-thumbnails.c index 424d061d..61d3cb83 100644 --- a/shell/ev-sidebar-thumbnails.c +++ b/shell/ev-sidebar-thumbnails.c @@ -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) { diff --git a/shell/ev-sidebar-thumbnails.h b/shell/ev-sidebar-thumbnails.h index ccfc09b9..dc5007c2 100644 --- a/shell/ev-sidebar-thumbnails.h +++ b/shell/ev-sidebar-thumbnails.h @@ -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 diff --git a/shell/ev-view.c b/shell/ev-view.c index cfcc8454..6dfe1815 100644 --- a/shell/ev-view.c +++ b/shell/ev-view.c @@ -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 diff --git a/shell/ev-view.h b/shell/ev-view.h index c0108c59..f0492e33 100644 --- a/shell/ev-view.h +++ b/shell/ev-view.h @@ -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 diff --git a/shell/ev-window.c b/shell/ev-window.c index 489c1cc0..1aba5eb1 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -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, "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, "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 */