Skip to content

Commit cb60f21

Browse files
committed
Merge pull request #29 from ebbes/tabs
Make tabs detachable and interchangeable between windows
2 parents 2d0dd67 + 04fc27a commit cb60f21

File tree

5 files changed

+141
-2
lines changed

5 files changed

+141
-2
lines changed

src/nemo-notebook.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ nemo_notebook_insert_page (GtkNotebook *gnotebook,
405405
gtk_notebook_set_show_tabs (gnotebook,
406406
gtk_notebook_get_n_pages (gnotebook) > 1);
407407
gtk_notebook_set_tab_reorderable (gnotebook, tab_widget, TRUE);
408+
gtk_notebook_set_tab_detachable (gnotebook, tab_widget, TRUE);
408409

409410
return position;
410411
}

src/nemo-view.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2345,6 +2345,22 @@ slot_inactive (NemoWindowSlot *slot,
23452345
remove_update_menus_timeout_callback (view);
23462346
}
23472347

2348+
static void slot_changed_pane (NemoWindowSlot *slot,
2349+
NemoView *view)
2350+
{
2351+
g_signal_handlers_disconnect_matched (view->details->window,
2352+
G_SIGNAL_MATCH_DATA, 0, 0,
2353+
NULL, NULL, view);
2354+
2355+
view->details->window = nemo_window_slot_get_window (slot);
2356+
schedule_update_menus (view);
2357+
2358+
g_signal_connect_object (view->details->window,
2359+
"hidden-files-mode-changed", G_CALLBACK (hidden_files_mode_changed),
2360+
view, 0);
2361+
hidden_files_mode_changed (view->details->window, view);
2362+
}
2363+
23482364
void
23492365
nemo_view_grab_focus (NemoView *view)
23502366
{
@@ -9542,6 +9558,9 @@ nemo_view_set_property (GObject *object,
95429558
g_signal_connect_object (directory_view->details->slot,
95439559
"inactive", G_CALLBACK (slot_inactive),
95449560
directory_view, 0);
9561+
g_signal_connect_object (directory_view->details->slot,
9562+
"changed-pane", G_CALLBACK (slot_changed_pane),
9563+
directory_view, 0);
95459564

95469565
g_signal_connect_object (directory_view->details->window,
95479566
"hidden-files-mode-changed", G_CALLBACK (hidden_files_mode_changed),

src/nemo-window-pane.c

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "nemo-window-pane.h"
3030

3131
#include "nemo-actions.h"
32+
#include "nemo-application.h"
3233
#include "nemo-location-bar.h"
3334
#include "nemo-notebook.h"
3435
#include "nemo-pathbar.h"
@@ -612,6 +613,103 @@ notebook_switch_page_cb (GtkNotebook *notebook,
612613
return FALSE;
613614
}
614615

616+
static void
617+
notebook_page_removed_cb (GtkNotebook *notebook,
618+
GtkWidget *page,
619+
guint page_num,
620+
gpointer user_data)
621+
{
622+
NemoWindowPane *pane = user_data;
623+
NemoWindowSlot *slot = NEMO_WINDOW_SLOT (page), *next_slot;
624+
gboolean dnd_slot;
625+
626+
dnd_slot = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (slot), "dnd-window-slot"));
627+
if (!dnd_slot) {
628+
return;
629+
}
630+
631+
if (pane->active_slot == slot) {
632+
next_slot = get_first_inactive_slot (pane);
633+
nemo_window_set_active_slot (pane->window, next_slot);
634+
}
635+
636+
nemo_window_manage_views_close_slot (slot);
637+
pane->slots = g_list_remove (pane->slots, slot);
638+
}
639+
640+
static void
641+
notebook_page_added_cb (GtkNotebook *notebook,
642+
GtkWidget *page,
643+
guint page_num,
644+
gpointer user_data)
645+
{
646+
NemoWindowPane *pane;
647+
NemoWindowSlot *slot;
648+
NemoWindowSlot *dummy_slot;
649+
gboolean dnd_slot;
650+
651+
pane = NEMO_WINDOW_PANE (user_data);
652+
slot = NEMO_WINDOW_SLOT (page);
653+
654+
//Slot has been dropped onto another pane (new window or tab bar of other window)
655+
//So reassociate the pane if needed.
656+
if (slot->pane != pane) {
657+
slot->pane->slots = g_list_remove (slot->pane->slots, slot);
658+
slot->pane = pane;
659+
pane->slots = g_list_append (pane->slots, slot);
660+
g_signal_emit_by_name (slot, "changed-pane");
661+
nemo_window_set_active_slot (nemo_window_slot_get_window (slot), slot);
662+
}
663+
664+
dnd_slot = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (slot), "dnd-window-slot"));
665+
666+
if (!dnd_slot) {
667+
//Slot does not come from dnd window creation.
668+
return;
669+
}
670+
671+
g_object_set_data (G_OBJECT (page), "dnd-window-slot",
672+
GINT_TO_POINTER (FALSE));
673+
674+
dummy_slot = g_list_nth_data (pane->slots, 0);
675+
if (dummy_slot != NULL) {
676+
nemo_window_pane_close_slot (dummy_slot->pane, dummy_slot);
677+
}
678+
679+
gtk_widget_show (GTK_WIDGET (pane));
680+
gtk_widget_show (GTK_WIDGET (pane->window));
681+
}
682+
683+
static GtkNotebook *
684+
notebook_create_window_cb (GtkNotebook *notebook,
685+
GtkWidget *page,
686+
gint x,
687+
gint y,
688+
gpointer user_data)
689+
{
690+
NemoApplication *app;
691+
NemoWindow *new_window;
692+
NemoWindowPane *new_pane;
693+
NemoWindowSlot *slot;
694+
695+
if (!NEMO_IS_WINDOW_SLOT (page)) {
696+
return NULL;
697+
}
698+
699+
app = NEMO_APPLICATION (g_application_get_default ());
700+
new_window = nemo_application_create_window
701+
(app, gtk_widget_get_screen (GTK_WIDGET (notebook)));
702+
703+
slot = NEMO_WINDOW_SLOT (page);
704+
g_object_set_data (G_OBJECT (slot), "dnd-window-slot",
705+
GINT_TO_POINTER (TRUE));
706+
707+
gtk_window_set_position (GTK_WINDOW (new_window), GTK_WIN_POS_MOUSE);
708+
709+
new_pane = nemo_window_get_active_pane (new_window);
710+
return GTK_NOTEBOOK (new_pane->notebook);
711+
}
712+
615713
static void
616714
action_show_hide_search_callback (GtkAction *action,
617715
gpointer user_data)
@@ -820,9 +918,19 @@ nemo_window_pane_constructed (GObject *obj)
820918
"switch-page",
821919
G_CALLBACK (notebook_switch_page_cb),
822920
pane);
921+
g_signal_connect (pane->notebook, "create-window",
922+
G_CALLBACK (notebook_create_window_cb),
923+
pane);
924+
g_signal_connect (pane->notebook, "page-added",
925+
G_CALLBACK (notebook_page_added_cb),
926+
pane);
927+
g_signal_connect (pane->notebook, "page-removed",
928+
G_CALLBACK (notebook_page_removed_cb),
929+
pane);
823930

824931
gtk_notebook_set_show_tabs (GTK_NOTEBOOK (pane->notebook), FALSE);
825932
gtk_notebook_set_show_border (GTK_NOTEBOOK (pane->notebook), FALSE);
933+
gtk_notebook_set_group_name (GTK_NOTEBOOK (pane->notebook), "nemo-slots");
826934
gtk_widget_show (pane->notebook);
827935
gtk_container_set_border_width (GTK_CONTAINER (pane->notebook), 0);
828936

src/nemo-window-slot.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ G_DEFINE_TYPE (NemoWindowSlot, nemo_window_slot, GTK_TYPE_BOX);
4141
enum {
4242
ACTIVE,
4343
INACTIVE,
44+
CHANGED_PANE,
4445
LAST_SIGNAL
4546
};
4647

@@ -296,6 +297,15 @@ nemo_window_slot_class_init (NemoWindowSlotClass *klass)
296297
NULL, NULL,
297298
g_cclosure_marshal_VOID__VOID,
298299
G_TYPE_NONE, 0);
300+
301+
signals[CHANGED_PANE] =
302+
g_signal_new ("changed-pane",
303+
G_TYPE_FROM_CLASS (klass),
304+
G_SIGNAL_RUN_LAST,
305+
G_STRUCT_OFFSET (NemoWindowSlotClass, changed_pane),
306+
NULL, NULL,
307+
g_cclosure_marshal_VOID__VOID,
308+
G_TYPE_NONE, 0);
299309
}
300310

301311
GFile *

src/nemo-window-slot.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ struct NemoWindowSlotClass {
4747
GtkBoxClass parent_class;
4848

4949
/* wrapped NemoWindowInfo signals, for overloading */
50-
void (* active) (NemoWindowSlot *slot);
51-
void (* inactive) (NemoWindowSlot *slot);
50+
void (* active) (NemoWindowSlot *slot);
51+
void (* inactive) (NemoWindowSlot *slot);
52+
void (* changed_pane) (NemoWindowSlot *slot);
5253
};
5354

5455
/* Each NemoWindowSlot corresponds to

0 commit comments

Comments
 (0)