Bind Alt + Number to switching to the according tab from 1 to 0

This commit is contained in:
Christian Dywan 2009-06-12 02:02:55 +02:00
parent 491b89bcb3
commit 696b6eab77

View file

@ -4448,11 +4448,37 @@ midori_browser_set_history (MidoriBrowser* browser,
browser->history, NULL); browser->history, NULL);
} }
static void
midori_browser_accel_switch_tab_activate_cb (GtkAccelGroup* accel_group,
GObject* acceleratable,
guint keyval,
GdkModifierType modifiers)
{
GtkAccelGroupEntry* entry;
if ((entry = gtk_accel_group_query (accel_group, keyval, modifiers, NULL)))
{
gint n;
MidoriBrowser* browser;
GtkWidget* view;
n = keyval - GDK_0;
if (n == 0)
n = 10;
browser = g_object_get_data (G_OBJECT (accel_group), "midori-browser");
if ((view = gtk_notebook_get_nth_page (GTK_NOTEBOOK (browser->notebook),
n - 1)))
midori_browser_set_current_tab (browser, view);
}
}
static void static void
midori_browser_init (MidoriBrowser* browser) midori_browser_init (MidoriBrowser* browser)
{ {
GtkWidget* vbox; GtkWidget* vbox;
GtkUIManager* ui_manager; GtkUIManager* ui_manager;
GtkAccelGroup* accel_group;
guint i;
GError* error; GError* error;
GtkAction* action; GtkAction* action;
GtkWidget* menuitem; GtkWidget* menuitem;
@ -4503,8 +4529,20 @@ midori_browser_init (MidoriBrowser* browser)
toggle_entries, toggle_entries_n, browser); toggle_entries, toggle_entries_n, browser);
ui_manager = gtk_ui_manager_new (); ui_manager = gtk_ui_manager_new ();
gtk_ui_manager_insert_action_group (ui_manager, browser->action_group, 0); gtk_ui_manager_insert_action_group (ui_manager, browser->action_group, 0);
gtk_window_add_accel_group (GTK_WINDOW (browser), accel_group = gtk_ui_manager_get_accel_group (ui_manager);
gtk_ui_manager_get_accel_group (ui_manager)); gtk_window_add_accel_group (GTK_WINDOW (browser), accel_group);
g_object_set_data (G_OBJECT (accel_group), "midori-browser", browser);
for (i = 0; i < 10; i++)
{
gchar* accel_path = g_strdup_printf ("<Manual>/Browser/SwitchTab%d", i);
GClosure* closure = g_cclosure_new (
G_CALLBACK (midori_browser_accel_switch_tab_activate_cb),
browser, NULL);
gtk_accel_map_add_entry (accel_path, GDK_0 + i, GDK_MOD1_MASK);
gtk_accel_group_connect_by_path (accel_group, accel_path, closure);
g_free (accel_path);
}
error = NULL; error = NULL;
if (!gtk_ui_manager_add_ui_from_string (ui_manager, ui_markup, -1, &error)) if (!gtk_ui_manager_add_ui_from_string (ui_manager, ui_markup, -1, &error))