|
29 | 29 | #include "nemo-window-pane.h" |
30 | 30 |
|
31 | 31 | #include "nemo-actions.h" |
| 32 | +#include "nemo-application.h" |
32 | 33 | #include "nemo-location-bar.h" |
33 | 34 | #include "nemo-notebook.h" |
34 | 35 | #include "nemo-pathbar.h" |
@@ -612,6 +613,103 @@ notebook_switch_page_cb (GtkNotebook *notebook, |
612 | 613 | return FALSE; |
613 | 614 | } |
614 | 615 |
|
| 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 | + |
615 | 713 | static void |
616 | 714 | action_show_hide_search_callback (GtkAction *action, |
617 | 715 | gpointer user_data) |
@@ -820,9 +918,19 @@ nemo_window_pane_constructed (GObject *obj) |
820 | 918 | "switch-page", |
821 | 919 | G_CALLBACK (notebook_switch_page_cb), |
822 | 920 | 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); |
823 | 930 |
|
824 | 931 | gtk_notebook_set_show_tabs (GTK_NOTEBOOK (pane->notebook), FALSE); |
825 | 932 | gtk_notebook_set_show_border (GTK_NOTEBOOK (pane->notebook), FALSE); |
| 933 | + gtk_notebook_set_group_name (GTK_NOTEBOOK (pane->notebook), "nemo-slots"); |
826 | 934 | gtk_widget_show (pane->notebook); |
827 | 935 | gtk_container_set_border_width (GTK_CONTAINER (pane->notebook), 0); |
828 | 936 |
|
|
0 commit comments