]> spindle.queued.net Git - midori/commitdiff
Add MidoriBrowser::move-tab and use it in Tab Panel
authorAlexander Friesen <a_06357@fastmail.fm>
Mon, 7 Mar 2011 21:56:20 +0000 (22:56 +0100)
committerChristian Dywan <christian@twotoasts.de>
Mon, 7 Mar 2011 21:56:20 +0000 (22:56 +0100)
extensions/tab-panel.c
midori/marshal.list
midori/midori-browser.c

index b71aa1a76893d902264789c1ffe44b24c8356c3f..aeedd1305a5e9e53e667209336667ee27e378948 100644 (file)
@@ -38,6 +38,13 @@ static void
 tab_panel_browser_notify_tab_cb (MidoriBrowser* browser,
                                  GParamSpec*    pspec,
                                  GtkTreeView*   treeview);
+static void
+tab_panel_browser_move_tab_cb (MidoriBrowser* browser,
+                               GtkNotebook*   notebook,
+                               gint           cur_pos,
+                               gint           new_pos,
+                               gpointer       user_data);
+
 
 static void
 tab_panel_view_notify_minimized_cb (GtkWidget*       view,
@@ -124,6 +131,8 @@ tab_panel_deactivate_cb (MidoriExtension* extension,
         browser, tab_panel_view_notify_icon_cb, extension);
     g_signal_handlers_disconnect_by_func (
         browser, tab_panel_view_notify_title_cb, extension);
+    g_signal_handlers_disconnect_by_func (
+        browser, tab_panel_browser_move_tab_cb, NULL);
 
     gtk_widget_destroy (treeview);
 }
@@ -598,6 +607,8 @@ tab_panel_app_add_browser_cb (MidoriApp*       app,
         G_CALLBACK (tab_panel_browser_notify_tab_cb), treeview);
     g_signal_connect (extension, "deactivate",
         G_CALLBACK (tab_panel_deactivate_cb), treeview);
+    g_signal_connect (browser, "move-tab",
+        G_CALLBACK (tab_panel_browser_move_tab_cb), NULL);
 }
 
 static void
@@ -615,6 +626,33 @@ tab_panel_activate_cb (MidoriExtension* extension,
         G_CALLBACK (tab_panel_app_add_browser_cb), extension);
 }
 
+static void
+tab_panel_browser_move_tab_cb (MidoriBrowser* browser,
+                               GtkNotebook*   notebook,
+                               gint           cur_pos,
+                               gint           new_pos,
+                               gpointer       user_data)
+{
+    GtkTreeIter cur, new;
+    gint last_page;
+    GtkTreeModel *model;
+
+    last_page = gtk_notebook_get_n_pages (notebook) - 1;
+    model = tab_panel_get_model_for_browser (browser);
+
+    gtk_tree_model_iter_nth_child (model, &cur, NULL, cur_pos);
+
+    if (cur_pos == 0 && new_pos == last_page)
+        gtk_tree_store_move_before (GTK_TREE_STORE (model), &cur, NULL);
+    else if (cur_pos == last_page && new_pos == 0)
+        gtk_tree_store_move_after (GTK_TREE_STORE (model), &cur, NULL);
+    else
+    {
+        gtk_tree_model_iter_nth_child (model, &new, NULL, new_pos);
+        gtk_tree_store_swap (GTK_TREE_STORE (model), &cur, &new);
+    }
+}
+
 MidoriExtension*
 extension_init (void)
 {
index 0b7de0acd4164493a6bc3b75d17acaf827f8e5b8..10da7979a7a37dcdb7223c609388fdfecec426e4 100644 (file)
@@ -5,6 +5,7 @@ BOOLEAN:VOID
 OBJECT:OBJECT
 VOID:BOOLEAN,STRING
 VOID:OBJECT,ENUM
+VOID:OBJECT,INT,INT
 VOID:POINTER,INT
 VOID:STRING,BOOLEAN
 VOID:STRING,INT,STRING
index 9c37502b79dbfc47705ccdf174e151e737ebf732..d4dce14e77e728a5e233a0fd393dbdb1bccb7f3a 100644 (file)
@@ -136,6 +136,7 @@ enum
     NEW_WINDOW,
     ADD_TAB,
     REMOVE_TAB,
+    MOVE_TAB,
     ACTIVATE_ACTION,
     CONTEXT_READY,
     ADD_DOWNLOAD,
@@ -1754,6 +1755,28 @@ midori_browser_class_init (MidoriBrowserClass* class)
         G_TYPE_NONE, 1,
         GTK_TYPE_WIDGET);
 
+    /**
+     * MidoriBrowser::move-tab:
+     * @browser: the object on which the signal is emitted
+     * @notebook: the notebook containing the tabs
+     * @cur_pos: the current position of the tab
+     * @new_pos: the new position of the tab
+     *
+     * Emitted when a tab is moved.
+     *
+     * Since: 0.3.3
+     */
+     signals[MOVE_TAB] = g_signal_new (
+        "move-tab",
+        G_TYPE_FROM_CLASS (class),
+        (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
+        0,
+        0,
+        NULL,
+        midori_cclosure_marshal_VOID__OBJECT_INT_INT,
+        G_TYPE_NONE, 3,
+        GTK_TYPE_NOTEBOOK, G_TYPE_INT, G_TYPE_INT);
+
     signals[ACTIVATE_ACTION] = g_signal_new (
         "activate-action",
         G_TYPE_FROM_CLASS (class),
@@ -4396,21 +4419,30 @@ static void
 _action_tab_move_backward_activate (GtkAction*     action,
                                     MidoriBrowser* browser)
 {
-    gint n = gtk_notebook_get_current_page (GTK_NOTEBOOK (browser->notebook));
-    GtkWidget* widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK (browser->notebook), n);
-    gtk_notebook_reorder_child (GTK_NOTEBOOK (browser->notebook), widget, n - 1);
+    gint new_pos;
+    gint cur_pos = gtk_notebook_get_current_page (GTK_NOTEBOOK (browser->notebook));
+    GtkWidget* widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK (browser->notebook), cur_pos);
+    if (cur_pos > 0)
+        new_pos = cur_pos - 1;
+    else
+        new_pos = gtk_notebook_get_n_pages (GTK_NOTEBOOK (browser->notebook)) - 1;
+    gtk_notebook_reorder_child (GTK_NOTEBOOK (browser->notebook), widget, new_pos);
+    g_signal_emit (browser, signals[MOVE_TAB], 0, browser->notebook, cur_pos, new_pos);
 }
 
 static void
 _action_tab_move_forward_activate (GtkAction*     action,
                                    MidoriBrowser* browser)
 {
-    gint n = gtk_notebook_get_current_page (GTK_NOTEBOOK (browser->notebook));
-    GtkWidget* widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK (browser->notebook), n);
-    if (n == (gtk_notebook_get_n_pages (GTK_NOTEBOOK (browser->notebook)) - 1))
-        gtk_notebook_reorder_child (GTK_NOTEBOOK (browser->notebook), widget, 0);
+    gint new_pos;
+    gint cur_pos = gtk_notebook_get_current_page (GTK_NOTEBOOK (browser->notebook));
+    GtkWidget* widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK (browser->notebook), cur_pos);
+    if (cur_pos == (gtk_notebook_get_n_pages (GTK_NOTEBOOK (browser->notebook)) - 1))
+        new_pos = 0;
     else
-        gtk_notebook_reorder_child (GTK_NOTEBOOK (browser->notebook), widget, n + 1);
+        new_pos = cur_pos + 1;
+    gtk_notebook_reorder_child (GTK_NOTEBOOK (browser->notebook), widget, new_pos);
+    g_signal_emit (browser, signals[MOVE_TAB], 0, browser->notebook, cur_pos, new_pos);
 }
 
 static void