[nautilus] notebook: make tabs detachable
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus] notebook: make tabs detachable
- Date: Sat, 1 Sep 2012 03:04:54 +0000 (UTC)
commit 0de1d3fe1099f7221c846bdbdaec90be29644c88
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Fri Aug 31 21:14:46 2012 -0400
notebook: make tabs detachable
Implement support for detaching a tab with DnD.
https://bugzilla.gnome.org/show_bug.cgi?id=562583
src/nautilus-notebook.c | 1 +
src/nautilus-window.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 93 insertions(+), 0 deletions(-)
---
diff --git a/src/nautilus-notebook.c b/src/nautilus-notebook.c
index 1131ec4..6d41860 100644
--- a/src/nautilus-notebook.c
+++ b/src/nautilus-notebook.c
@@ -403,6 +403,7 @@ nautilus_notebook_insert_page (GtkNotebook *gnotebook,
gtk_notebook_set_show_tabs (gnotebook,
gtk_notebook_get_n_pages (gnotebook) > 1);
gtk_notebook_set_tab_reorderable (gnotebook, tab_widget, TRUE);
+ gtk_notebook_set_tab_detachable (gnotebook, tab_widget, TRUE);
return position;
}
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index 2ed52e8..3327a4c 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -32,6 +32,7 @@
#include "nautilus-window-private.h"
#include "nautilus-actions.h"
+#include "nautilus-application.h"
#include "nautilus-bookmarks-window.h"
#include "nautilus-location-bar.h"
#include "nautilus-mime-actions.h"
@@ -1023,6 +1024,88 @@ create_toolbar (NautilusWindow *window)
return toolbar;
}
+static void
+notebook_page_removed_cb (GtkNotebook *notebook,
+ GtkWidget *page,
+ guint page_num,
+ gpointer user_data)
+{
+ NautilusWindow *window = user_data;
+ NautilusWindowSlot *slot = NAUTILUS_WINDOW_SLOT (page), *next_slot;
+ gboolean dnd_slot;
+
+ dnd_slot = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (slot), "dnd-window-slot"));
+ if (!dnd_slot) {
+ return;
+ }
+
+ if (window->details->active_slot == slot) {
+ next_slot = get_first_inactive_slot (window);
+ nautilus_window_set_active_slot (window, next_slot);
+ }
+
+ close_slot (window, slot, FALSE);
+}
+
+static void
+notebook_page_added_cb (GtkNotebook *notebook,
+ GtkWidget *page,
+ guint page_num,
+ gpointer user_data)
+{
+ NautilusWindow *window = user_data;
+ NautilusWindowSlot *slot = NAUTILUS_WINDOW_SLOT (page);
+ NautilusWindowSlot *dummy_slot;
+ gboolean dnd_slot;
+
+ dnd_slot = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (slot), "dnd-window-slot"));
+ if (!dnd_slot) {
+ return;
+ }
+
+ g_object_set_data (G_OBJECT (page), "dnd-window-slot",
+ GINT_TO_POINTER (FALSE));
+
+ nautilus_window_slot_set_window (slot, window);
+ window->details->slots = g_list_append (window->details->slots, slot);
+ g_signal_emit (window, signals[SLOT_ADDED], 0, slot);
+
+ nautilus_window_set_active_slot (window, slot);
+
+ dummy_slot = g_list_nth_data (window->details->slots, 0);
+ if (dummy_slot != NULL) {
+ close_slot (window, dummy_slot, TRUE);
+ }
+
+ gtk_widget_show (GTK_WIDGET (window));
+}
+
+static GtkNotebook *
+notebook_create_window_cb (GtkNotebook *notebook,
+ GtkWidget *page,
+ gint x,
+ gint y,
+ gpointer user_data)
+{
+ NautilusApplication *app;
+ NautilusWindow *new_window;
+ NautilusWindowSlot *slot;
+
+ if (!NAUTILUS_IS_WINDOW_SLOT (page)) {
+ return NULL;
+ }
+
+ app = NAUTILUS_APPLICATION (g_application_get_default ());
+ new_window = nautilus_application_create_window
+ (app, gtk_widget_get_screen (GTK_WIDGET (notebook)));
+
+ slot = NAUTILUS_WINDOW_SLOT (page);
+ g_object_set_data (G_OBJECT (slot), "dnd-window-slot",
+ GINT_TO_POINTER (TRUE));
+
+ return GTK_NOTEBOOK (new_window->details->notebook);
+}
+
static GtkWidget *
create_notebook (NautilusWindow *window)
{
@@ -1038,6 +1121,15 @@ create_notebook (NautilusWindow *window)
g_signal_connect (notebook, "switch-page",
G_CALLBACK (notebook_switch_page_cb),
window);
+ g_signal_connect (notebook, "create-window",
+ G_CALLBACK (notebook_create_window_cb),
+ window);
+ g_signal_connect (notebook, "page-added",
+ G_CALLBACK (notebook_page_added_cb),
+ window);
+ g_signal_connect (notebook, "page-removed",
+ G_CALLBACK (notebook_page_removed_cb),
+ window);
g_signal_connect_after (notebook, "button-press-event",
G_CALLBACK (notebook_button_press_cb),
window);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]