Add MidoriBrowser::move-tab and use it in Tab Panel
This commit is contained in:
parent
e1f5c6cf95
commit
f237c30e06
3 changed files with 79 additions and 8 deletions
|
@ -38,6 +38,13 @@ static void
|
||||||
tab_panel_browser_notify_tab_cb (MidoriBrowser* browser,
|
tab_panel_browser_notify_tab_cb (MidoriBrowser* browser,
|
||||||
GParamSpec* pspec,
|
GParamSpec* pspec,
|
||||||
GtkTreeView* treeview);
|
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
|
static void
|
||||||
tab_panel_view_notify_minimized_cb (GtkWidget* view,
|
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);
|
browser, tab_panel_view_notify_icon_cb, extension);
|
||||||
g_signal_handlers_disconnect_by_func (
|
g_signal_handlers_disconnect_by_func (
|
||||||
browser, tab_panel_view_notify_title_cb, extension);
|
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);
|
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_CALLBACK (tab_panel_browser_notify_tab_cb), treeview);
|
||||||
g_signal_connect (extension, "deactivate",
|
g_signal_connect (extension, "deactivate",
|
||||||
G_CALLBACK (tab_panel_deactivate_cb), treeview);
|
G_CALLBACK (tab_panel_deactivate_cb), treeview);
|
||||||
|
g_signal_connect (browser, "move-tab",
|
||||||
|
G_CALLBACK (tab_panel_browser_move_tab_cb), NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -615,6 +626,33 @@ tab_panel_activate_cb (MidoriExtension* extension,
|
||||||
G_CALLBACK (tab_panel_app_add_browser_cb), 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*
|
MidoriExtension*
|
||||||
extension_init (void)
|
extension_init (void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,6 +5,7 @@ BOOLEAN:VOID
|
||||||
OBJECT:OBJECT
|
OBJECT:OBJECT
|
||||||
VOID:BOOLEAN,STRING
|
VOID:BOOLEAN,STRING
|
||||||
VOID:OBJECT,ENUM
|
VOID:OBJECT,ENUM
|
||||||
|
VOID:OBJECT,INT,INT
|
||||||
VOID:POINTER,INT
|
VOID:POINTER,INT
|
||||||
VOID:STRING,BOOLEAN
|
VOID:STRING,BOOLEAN
|
||||||
VOID:STRING,INT,STRING
|
VOID:STRING,INT,STRING
|
||||||
|
|
|
@ -136,6 +136,7 @@ enum
|
||||||
NEW_WINDOW,
|
NEW_WINDOW,
|
||||||
ADD_TAB,
|
ADD_TAB,
|
||||||
REMOVE_TAB,
|
REMOVE_TAB,
|
||||||
|
MOVE_TAB,
|
||||||
ACTIVATE_ACTION,
|
ACTIVATE_ACTION,
|
||||||
CONTEXT_READY,
|
CONTEXT_READY,
|
||||||
ADD_DOWNLOAD,
|
ADD_DOWNLOAD,
|
||||||
|
@ -1754,6 +1755,28 @@ midori_browser_class_init (MidoriBrowserClass* class)
|
||||||
G_TYPE_NONE, 1,
|
G_TYPE_NONE, 1,
|
||||||
GTK_TYPE_WIDGET);
|
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 (
|
signals[ACTIVATE_ACTION] = g_signal_new (
|
||||||
"activate-action",
|
"activate-action",
|
||||||
G_TYPE_FROM_CLASS (class),
|
G_TYPE_FROM_CLASS (class),
|
||||||
|
@ -4396,21 +4419,30 @@ static void
|
||||||
_action_tab_move_backward_activate (GtkAction* action,
|
_action_tab_move_backward_activate (GtkAction* action,
|
||||||
MidoriBrowser* browser)
|
MidoriBrowser* browser)
|
||||||
{
|
{
|
||||||
gint n = gtk_notebook_get_current_page (GTK_NOTEBOOK (browser->notebook));
|
gint new_pos;
|
||||||
GtkWidget* widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK (browser->notebook), n);
|
gint cur_pos = gtk_notebook_get_current_page (GTK_NOTEBOOK (browser->notebook));
|
||||||
gtk_notebook_reorder_child (GTK_NOTEBOOK (browser->notebook), widget, n - 1);
|
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
|
static void
|
||||||
_action_tab_move_forward_activate (GtkAction* action,
|
_action_tab_move_forward_activate (GtkAction* action,
|
||||||
MidoriBrowser* browser)
|
MidoriBrowser* browser)
|
||||||
{
|
{
|
||||||
gint n = gtk_notebook_get_current_page (GTK_NOTEBOOK (browser->notebook));
|
gint new_pos;
|
||||||
GtkWidget* widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK (browser->notebook), n);
|
gint cur_pos = gtk_notebook_get_current_page (GTK_NOTEBOOK (browser->notebook));
|
||||||
if (n == (gtk_notebook_get_n_pages (GTK_NOTEBOOK (browser->notebook)) - 1))
|
GtkWidget* widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK (browser->notebook), cur_pos);
|
||||||
gtk_notebook_reorder_child (GTK_NOTEBOOK (browser->notebook), widget, 0);
|
if (cur_pos == (gtk_notebook_get_n_pages (GTK_NOTEBOOK (browser->notebook)) - 1))
|
||||||
|
new_pos = 0;
|
||||||
else
|
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
|
static void
|
||||||
|
|
Loading…
Reference in a new issue