From 23eede529178e3dc058d777f35c34d8de2d8cbab Mon Sep 17 00:00:00 2001 From: Colomban Wendling Date: Fri, 16 Dec 2011 19:16:20 +0100 Subject: [PATCH] Make switch to MRU upon tab close configurable Add configuration option tab_close_switch_to_mru to allow the user to choose whether to switch to the most recently used tab or to the next one after closing the current tab. --- data/geany.glade | 12 ++++++++++++ src/document.h | 1 + src/keybindings.c | 25 ++++++++++++++++++------- src/keyfile.c | 2 ++ 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/data/geany.glade b/data/geany.glade index 580467ac..2f36ab9b 100644 --- a/data/geany.glade +++ b/data/geany.glade @@ -2117,6 +2117,18 @@ 3 + + + Switch to last used document after closing a tab + True + True + False + True + + + 4 + + diff --git a/src/document.h b/src/document.h index 28d7bd39..e87d83a4 100644 --- a/src/document.h +++ b/src/document.h @@ -62,6 +62,7 @@ typedef struct GeanyFilePrefs gboolean gio_unsafe_save_backup; gboolean use_gio_unsafe_file_saving; /* whether to use GIO as the unsafe backend */ gchar *extract_filetype_regex; /* regex to extract filetype on opening */ + gboolean tab_close_switch_to_mru; } GeanyFilePrefs; diff --git a/src/keybindings.c b/src/keybindings.c index bb690f20..5b5424ef 100644 --- a/src/keybindings.c +++ b/src/keybindings.c @@ -632,15 +632,26 @@ static void on_document_close(GObject *obj, GeanyDocument *doc) { if (! main_status.quitting) { - GeanyDocument *last_doc; - - last_doc = g_queue_peek_nth(mru_docs, 1); - - if (DOC_VALID(last_doc) && document_get_current() == doc) + /* switch to appropriate page when closing current doc */ + if (document_get_current() == doc) { - gtk_notebook_set_current_page(GTK_NOTEBOOK(main_widgets.notebook), - document_get_notebook_page(last_doc)); + gint page; + + page = gtk_notebook_get_current_page(GTK_NOTEBOOK(main_widgets.notebook)) + + (file_prefs.tab_order_ltr ? 1 : -1); + + if (file_prefs.tab_close_switch_to_mru) + { + GeanyDocument *last_doc; + + last_doc = g_queue_peek_nth(mru_docs, 1); + if (DOC_VALID(last_doc)) + page = document_get_notebook_page(last_doc); + } + + gtk_notebook_set_current_page(GTK_NOTEBOOK(main_widgets.notebook), page); } + g_queue_remove(mru_docs, doc); /* this prevents the pop up window from showing when there's a single * document */ diff --git a/src/keyfile.c b/src/keyfile.c index b6c55f6a..4d0f7840 100644 --- a/src/keyfile.c +++ b/src/keyfile.c @@ -139,6 +139,8 @@ static void init_pref_groups(void) stash_group_add_toggle_button(group, &interface_prefs.notebook_double_click_hides_widgets, "notebook_double_click_hides_widgets", FALSE, "check_double_click_hides_widgets"); + stash_group_add_toggle_button(group, &file_prefs.tab_close_switch_to_mru, + "tab_close_switch_to_mru", FALSE, "check_tab_close_switch_to_mru"); stash_group_add_integer(group, &interface_prefs.tab_pos_sidebar, "tab_pos_sidebar", GTK_POS_TOP); stash_group_add_radio_buttons(group, &interface_prefs.sidebar_pos, "sidebar_pos", GTK_POS_LEFT,