diff --git a/src/lxterminal.c b/src/lxterminal.c index a6dc0b36..b926d1e7 100644 --- a/src/lxterminal.c +++ b/src/lxterminal.c @@ -72,6 +72,7 @@ static void terminal_about_activate_event(GtkAction * action, LXTerminal * termi /* Window creation, destruction, and control. */ static void terminal_switch_page_event(GtkNotebook * notebook, GtkWidget * page, guint num, LXTerminal * terminal); +static void terminal_page_reordered_event(GtkNotebook * notebook, GtkWidget * page, guint num, LXTerminal * terminal); static void terminal_vte_size_allocate_event(GtkWidget *widget, GtkAllocation *allocation, Term *term); static void terminal_window_title_changed_event(GtkWidget * vte, Term * term); static gboolean terminal_close_window_confirmation_event(GtkWidget * widget, GdkEventButton * event, LXTerminal * terminal); @@ -430,6 +431,7 @@ static void terminal_new_tab(LXTerminal * terminal, const gchar * label) /* Add a tab to the notebook and the "terms" array. */ gtk_notebook_append_page(GTK_NOTEBOOK(terminal->notebook), term->box, term->tab); + gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(terminal->notebook), term->box, TRUE); term->index = gtk_notebook_get_n_pages(GTK_NOTEBOOK(terminal->notebook)) - 1; g_ptr_array_add(terminal->terms, term); @@ -799,6 +801,28 @@ static void terminal_switch_page_event(GtkNotebook * notebook, GtkWidget * page, } } +/* Handler for "page-reordered" event on the tab notebook. */ +static void terminal_page_reordered_event(GtkNotebook * notebook, GtkWidget * page, guint num, LXTerminal * terminal) +{ + guint i; + Term * term; + gint term_page_number; + GPtrArray * new_terms = g_ptr_array_new(); + + for (i = 0; i < terminal->terms->len; i++) + { + term = g_ptr_array_index(terminal->terms, i); + term_page_number = gtk_notebook_page_num(notebook, GTK_WIDGET(term->box)); + term->index = term_page_number; + g_ptr_array_add(new_terms, term); + } + + g_ptr_array_free(terminal->terms, TRUE); + terminal->terms = new_terms; + + terminal_update_alt(terminal); +} + /* Handler for "window-title-changed" signal on a Term. */ static void terminal_window_title_changed_event(GtkWidget * vte, Term * term) { @@ -1560,6 +1584,8 @@ LXTerminal * lxterminal_initialize(LXTermWindow * lxtermwin, CommandArguments * G_CALLBACK(terminal_settings_apply), terminal); g_signal_connect(G_OBJECT(terminal->notebook), "switch-page", G_CALLBACK(terminal_switch_page_event), terminal); + g_signal_connect(G_OBJECT(terminal->notebook), "page-reordered", + G_CALLBACK(terminal_page_reordered_event), terminal); g_signal_connect(G_OBJECT(terminal->window), "delete-event", G_CALLBACK(terminal_close_window_confirmation_event), terminal); @@ -1589,6 +1615,7 @@ LXTerminal * lxterminal_initialize(LXTermWindow * lxtermwin, CommandArguments * /* Add the first terminal to the notebook and the data structures. */ gtk_notebook_append_page(GTK_NOTEBOOK(terminal->notebook), term->box, term->tab); + gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(terminal->notebook), term->box, TRUE); term->index = gtk_notebook_get_n_pages(GTK_NOTEBOOK(terminal->notebook)) - 1; g_ptr_array_add(terminal->terms, term);