]> spindle.queued.net Git - midori/commitdiff
Provide tab overview menu on right-click of empty space
authorChristian Dywan <christian@twotoasts.de>
Wed, 2 Mar 2011 17:03:13 +0000 (18:03 +0100)
committerChristian Dywan <christian@twotoasts.de>
Wed, 2 Mar 2011 21:26:06 +0000 (22:26 +0100)
midori/midori-browser.c

index e7e6f861711463f752cea87ac1703afeae54bcea..9d5e98f18914c6fc93f9aaaa82b64959eca9ee9b 100644 (file)
@@ -4755,6 +4755,14 @@ midori_browser_notebook_page_reordered_cb (GtkNotebook*   notebook,
     g_object_thaw_notify (G_OBJECT (browser));
 }
 
+static void
+midori_browser_switch_tab_cb (GtkWidget*     menuitem,
+                              MidoriBrowser* browser)
+{
+    gint index = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menuitem), "index"));
+    midori_browser_set_current_page (browser, index);
+}
+
 static gboolean
 midori_browser_notebook_button_press_event_after_cb (GtkNotebook*    notebook,
                                                      GdkEventButton* event,
@@ -4774,6 +4782,36 @@ midori_browser_notebook_button_press_event_after_cb (GtkNotebook*    notebook,
 
         return TRUE;
     }
+    else if (event->type == GDK_BUTTON_PRESS && event->button == 3)
+    {
+        GtkWidget* menu = gtk_menu_new ();
+        GList* tabs = gtk_container_get_children (GTK_CONTAINER (notebook));
+        GtkWidget* menuitem = sokoke_action_create_popup_menu_item (
+            gtk_action_group_get_action (browser->action_group, "TabNew"));
+        gint i;
+        gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
+        menuitem = sokoke_action_create_popup_menu_item (
+            gtk_action_group_get_action (browser->action_group, "UndoTabClose"));
+        gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
+        menuitem = gtk_separator_menu_item_new ();
+        gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
+        for (; tabs != NULL; tabs = g_list_next (tabs))
+        {
+            const gchar* title = midori_view_get_display_title (tabs->data);
+            menuitem = katze_image_menu_item_new_ellipsized (title);
+            gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem),
+                gtk_image_new_from_pixbuf (midori_view_get_icon (tabs->data)));
+            gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
+            g_object_set_data (G_OBJECT (menuitem), "index", GINT_TO_POINTER (i));
+            g_signal_connect (menuitem, "activate",
+                G_CALLBACK (midori_browser_switch_tab_cb), browser);
+            i++;
+        }
+        g_list_free (tabs);
+        gtk_widget_show_all (menu);
+        katze_widget_popup (GTK_WIDGET (notebook), GTK_MENU (menu), NULL,
+            event->button == -1 ? KATZE_MENU_POSITION_LEFT : KATZE_MENU_POSITION_CURSOR);
+    }
 
     return FALSE;
 }