[Xfce4-commits] <midori:master> Add MidoriBrowser::move-tab and use it in Tab Panel
Christian Dywan
noreply at xfce.org
Mon Mar 7 22:58:01 CET 2011
Updating branch refs/heads/master
to f237c30e06efca3b0204c650f1388956138b5467 (commit)
from e1f5c6cf9585bd8e58a3d08d1e3f13424e3d6fd6 (commit)
commit f237c30e06efca3b0204c650f1388956138b5467
Author: Alexander Friesen <a_06357 at fastmail.fm>
Date: Mon Mar 7 22:56:20 2011 +0100
Add MidoriBrowser::move-tab and use it in Tab Panel
extensions/tab-panel.c | 38 +++++++++++++++++++++++++++++++++++++
midori/marshal.list | 1 +
midori/midori-browser.c | 48 +++++++++++++++++++++++++++++++++++++++-------
3 files changed, 79 insertions(+), 8 deletions(-)
diff --git a/extensions/tab-panel.c b/extensions/tab-panel.c
index b71aa1a..aeedd13 100644
--- a/extensions/tab-panel.c
+++ b/extensions/tab-panel.c
@@ -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)
{
diff --git a/midori/marshal.list b/midori/marshal.list
index 0b7de0a..10da797 100644
--- a/midori/marshal.list
+++ b/midori/marshal.list
@@ -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
diff --git a/midori/midori-browser.c b/midori/midori-browser.c
index 9c37502..d4dce14 100644
--- a/midori/midori-browser.c
+++ b/midori/midori-browser.c
@@ -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
More information about the Xfce4-commits
mailing list