From a9722ee94a19919f06fe74c95631782cc791be39 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Thu, 23 Nov 2006 12:23:36 +0000 Subject: [PATCH] Add switching to a notebook tab number using Alt-1 to Alt-9; Alt-0 switches to the last tab. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@1021 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 3 +++ src/keybindings.c | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/ChangeLog b/ChangeLog index d7b7f4c7..71e0a17e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,9 @@ data/filetypes.*: Only use [a-zA-Z0-9] chars for default wordchars, to avoid problems with word matching when using Find & Replace functions. + * src/keybindings.c: + Add switching to a notebook tab number using Alt-1 to Alt-9; Alt-0 + switches to the last tab. 2006-11-22 Frank Lanitz diff --git a/src/keybindings.c b/src/keybindings.c index 3ec97233..8959b6e8 100644 --- a/src/keybindings.c +++ b/src/keybindings.c @@ -41,6 +41,8 @@ #endif +const gboolean swap_alt_tab_order = FALSE; + /* simple convenience function to allocate and fill the struct */ static binding *fill(KBCallback func, guint key, GdkModifierType mod, const gchar *name, @@ -373,11 +375,35 @@ void keybindings_free(void) } +static gboolean check_fixed_kb(GdkEventKey *event) +{ + // check alt-0 to alt-9 for setting current notebook page + if (event->state & GDK_MOD1_MASK && event->keyval >= GDK_0 && event->keyval <= GDK_9) + { + gint page = event->keyval - GDK_0 - 1; + gint npages = gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook)); + + // alt-0 is for the rightmost tab + if (event->keyval == GDK_0) + page = npages - 1; + // invert the order if tabs are added on the other side + if (swap_alt_tab_order && ! app->tab_order_ltr) + page = (npages - 1) - page; + + gtk_notebook_set_current_page(GTK_NOTEBOOK(app->notebook), page); + return TRUE; + } + return FALSE; +} + + /* central keypress event handler, almost all keypress events go to this function */ gboolean keybindings_got_event(GtkWidget *widget, GdkEventKey *event, gpointer user_data) { guint i, k; + if (check_fixed_kb(event)) return TRUE; + for (i = 0; i < GEANY_MAX_KEYS; i++) { // ugly hack to get around that CTRL+Shift+r results in 'R' not 'r'