From 17caf45916270b7c49afde0389e9c5537966e259 Mon Sep 17 00:00:00 2001 From: weyfonk Date: Tue, 13 Sep 2016 18:08:57 +0100 Subject: [PATCH] Set keyboard shortcuts for tab navigation - Bug 9585 This is a first attempt at setting keyboard shortcuts to jump to the previous/next tab, with Ctrl+F6 and Ctrl+F7 respectfully. The choice of these keys is not ideal, but Page_Up and Page_Down do not seem to be usable as they are already used by the icon view for cursor selection. --- thunar/thunar-window.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/thunar/thunar-window.c b/thunar/thunar-window.c index 42be0a8..6d3e4f8 100644 --- a/thunar/thunar-window.c +++ b/thunar/thunar-window.c @@ -88,6 +88,7 @@ enum ZOOM_OUT, ZOOM_RESET, TAB_CHANGE, + TAB_PREV_NEXT, LAST_SIGNAL, }; @@ -115,6 +116,8 @@ static gboolean thunar_window_zoom_out (ThunarWindow static gboolean thunar_window_zoom_reset (ThunarWindow *window); static gboolean thunar_window_tab_change (ThunarWindow *window, gint nth); +static gboolean thunar_window_tab_prev_next (ThunarWindow *window, + gboolean forward); static void thunar_window_realize (GtkWidget *widget); static void thunar_window_unrealize (GtkWidget *widget); static gboolean thunar_window_configure_event (GtkWidget *widget, @@ -267,6 +270,8 @@ struct _ThunarWindowClass gboolean (*zoom_reset) (ThunarWindow *window); gboolean (*tab_change) (ThunarWindow *window, gint idx); + gboolean (*tab_prev_next) (ThunarWindow *window, + gboolean forward); }; struct _ThunarWindow @@ -427,6 +432,7 @@ thunar_window_class_init (ThunarWindowClass *klass) klass->zoom_out = thunar_window_zoom_out; klass->zoom_reset = thunar_window_zoom_reset; klass->tab_change = thunar_window_tab_change; + klass->tab_prev_next = thunar_window_tab_prev_next; /** * ThunarWindow:current-directory: @@ -620,6 +626,23 @@ thunar_window_class_init (ThunarWindowClass *klass) G_TYPE_BOOLEAN, 1, G_TYPE_INT); + /** + * ThunarWindow::tab-prev-next: + * @window : a #ThunarWindow instance. + * + * Emitted whenever the user uses a Ctrl+F(6|7) combination to + * switch tabs. + **/ + window_signals[TAB_PREV_NEXT] = + g_signal_new (I_("tab-prev-next"), + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (ThunarWindowClass, tab_prev_next), + g_signal_accumulator_true_handled, NULL, + _thunar_marshal_BOOLEAN__BOOLEAN, + G_TYPE_BOOLEAN, 1, + G_TYPE_BOOLEAN); + /* setup the key bindings for the windows */ binding_set = gtk_binding_set_by_class (klass); gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, 0, "back", 0); @@ -637,6 +660,12 @@ thunar_window_class_init (ThunarWindowClass *klass) gtk_binding_entry_add_signal (binding_set, GDK_0 + i, GDK_MOD1_MASK, "tab-change", 1, G_TYPE_UINT, i - 1); } + + /* setup the key bindings for Ctrl+F6 and Ctrl+F7 */ + gtk_binding_entry_add_signal (binding_set, GDK_KEY_F6, GDK_CONTROL_MASK, + "tab-prev-next", 1, G_TYPE_BOOLEAN, FALSE); + gtk_binding_entry_add_signal (binding_set, GDK_KEY_F7, GDK_CONTROL_MASK, + "tab-prev-next", 1, G_TYPE_BOOLEAN, TRUE); } @@ -1294,6 +1323,23 @@ thunar_window_tab_change (ThunarWindow *window, return TRUE; } +static gboolean +thunar_window_tab_prev_next (ThunarWindow *window, + gboolean forward) +{ + gint current_page_idx; + gint new_page_idx; + + _thunar_return_val_if_fail (THUNAR_IS_WINDOW (window), FALSE); + + current_page_idx = gtk_notebook_get_current_page (GTK_NOTEBOOK (window->notebook)); + new_page_idx = (current_page_idx + (forward ? 1 : -1) ) + % gtk_notebook_get_n_pages (GTK_NOTEBOOK (window->notebook)); + gtk_notebook_set_current_page (GTK_NOTEBOOK (window->notebook), new_page_idx); + + return TRUE; +} + static void -- 2.9.3