nautilus r13963 - in branches/multiview: . libnautilus-private src src/file-manager



Author: cneumair
Date: Fri Mar 21 15:51:19 2008
New Revision: 13963
URL: http://svn.gnome.org/viewvc/nautilus?rev=13963&view=rev

Log:
2007-03-21  Christian Neumair  <cneumair gnome org>

	* libnautilus-private/nautilus-window-info.h:
	Add NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB to NautilusWindowOpenFlags.

	* src/nautilus-window-slot.[ch]: 
	* src/nautilus-navigation-window-slot.[ch]:
	* src/*.[ch]:
	Add code for handling back/forward lists, add get_close_successor()
	API for determining which slot will follow the current one before
	close.
	Add nautilus_window_slot_go_to(_location) defines and use them in the
	window "go to" code.
	Properly destroy slots and views when closing slot.
	Add "New Tab" menu item.
	Beginnings of notebook tab handling.
	Some more minor fixes and comments.


Modified:
   branches/multiview/ChangeLog
   branches/multiview/libnautilus-private/nautilus-window-info.h
   branches/multiview/src/file-manager/fm-directory-view.c
   branches/multiview/src/nautilus-navigation-window-menus.c
   branches/multiview/src/nautilus-navigation-window-slot.c
   branches/multiview/src/nautilus-navigation-window-slot.h
   branches/multiview/src/nautilus-navigation-window-ui.xml
   branches/multiview/src/nautilus-navigation-window.c
   branches/multiview/src/nautilus-window-manage-views.c
   branches/multiview/src/nautilus-window-menus.c
   branches/multiview/src/nautilus-window-private.h
   branches/multiview/src/nautilus-window-slot.c
   branches/multiview/src/nautilus-window-slot.h
   branches/multiview/src/nautilus-window.c

Modified: branches/multiview/libnautilus-private/nautilus-window-info.h
==============================================================================
--- branches/multiview/libnautilus-private/nautilus-window-info.h	(original)
+++ branches/multiview/libnautilus-private/nautilus-window-info.h	Fri Mar 21 15:51:19 2008
@@ -50,7 +50,8 @@
 	/* used in spatial mode */
 	NAUTILUS_WINDOW_OPEN_FLAG_CLOSE_BEHIND = 1<<0,
 	/* used in navigation mode */
-	NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW = 1<<1
+	NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW = 1<<1,
+	NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB = 1<<2
 } NautilusWindowOpenFlags;
 
 typedef	enum {

Modified: branches/multiview/src/file-manager/fm-directory-view.c
==============================================================================
--- branches/multiview/src/file-manager/fm-directory-view.c	(original)
+++ branches/multiview/src/file-manager/fm-directory-view.c	Fri Mar 21 15:51:19 2008
@@ -1659,6 +1659,7 @@
 	schedule_update_menus (view);
 
 	/* initialise show hidden mode */
+	/* multiview-TODO this always causes a reload for loaded views. */
 	fm_directory_view_init_show_hidden_files (view);
 }
 
@@ -1902,6 +1903,7 @@
 	fm_directory_view_unmerge_menus (view);
 	
 	/* We don't own the window, so no unref */
+	view->details->slot = NULL;
 	view->details->window = NULL;
 	
 	fm_directory_view_stop (view);
@@ -3684,8 +3686,11 @@
 	view = data->view;
 	new_file = data->new_file;
 
-	EEL_CALL_METHOD (FM_DIRECTORY_VIEW_CLASS, view, start_renaming_file, (view, new_file, FALSE));
-	fm_directory_view_reveal_selection (view);
+	if (view->details->window != NULL &&
+	    view->details->active) {
+		EEL_CALL_METHOD (FM_DIRECTORY_VIEW_CLASS, view, start_renaming_file, (view, new_file, FALSE));
+		fm_directory_view_reveal_selection (view);
+	}
 	
 	g_object_unref (data->view);
 	nautilus_file_unref (data->new_file);
@@ -6628,8 +6633,9 @@
 	view = FM_DIRECTORY_VIEW (user_data);
 	can_paste = FALSE;
 
-	if (view->details->window == NULL) {
-		/* We've been destroyed since call */
+	if (view->details->window == NULL ||
+	    !view->details->active) {
+		/* We've been destroyed or became inactive since call */
 		g_object_unref (view);
 		return;
 	}
@@ -7726,6 +7732,7 @@
 	g_assert (view->details->directory_as_file == file);
 	g_assert (view->details->metadata_for_directory_as_file_pending);
 
+	g_assert (view->details->metadata_for_directory_as_file_pending);
 	view->details->metadata_for_directory_as_file_pending = FALSE;
 	
 	finish_loading_if_all_metadata_loaded (view);
@@ -7744,6 +7751,7 @@
 	g_assert (view->details->model == directory);
 	g_assert (view->details->metadata_for_files_in_directory_pending);
 
+	g_assert (view->details->metadata_for_files_in_directory_pending);
 	view->details->metadata_for_files_in_directory_pending = FALSE;
 	
 	finish_loading_if_all_metadata_loaded (view);

Modified: branches/multiview/src/nautilus-navigation-window-menus.c
==============================================================================
--- branches/multiview/src/nautilus-navigation-window-menus.c	(original)
+++ branches/multiview/src/nautilus-navigation-window-menus.c	Fri Mar 21 15:51:19 2008
@@ -428,6 +428,29 @@
 }
 
 static void
+action_new_tab_callback (GtkAction *action,
+			 gpointer user_data)
+{
+	NautilusWindow *window;
+	NautilusWindowSlot *current_slot;
+	NautilusWindowSlot *new_slot;
+	GFile *current_location;
+
+	window = NAUTILUS_WINDOW (user_data);
+	current_slot = window->details->active_slot;
+	current_location = nautilus_window_slot_get_location (current_slot);
+
+	window = NAUTILUS_WINDOW (current_slot->window);
+
+	if (current_location != NULL) {
+		new_slot = nautilus_window_open_slot (window);
+		nautilus_window_set_active_slot (window, new_slot);
+		nautilus_window_slot_go_to (new_slot, current_location);
+		g_object_unref (current_location);
+	}
+}
+
+static void
 action_folder_window_callback (GtkAction *action,
 			       gpointer user_data)
 {
@@ -477,6 +500,9 @@
   /* name, stock id, label */  { "New Window", "window-new", N_("New _Window"),
                                  "<control>N", N_("Open another Nautilus window for the displayed location"),
                                  G_CALLBACK (action_new_window_callback) },
+  /* name, stock id, label */  { "New Tab", "tab-new", N_("New _Tab"),
+                                 "<control>T", N_("Open another tab for the displayed location"),
+                                 G_CALLBACK (action_new_tab_callback) },
   /* name, stock id, label */  { "Folder Window", "folder", N_("Open Folder W_indow"),
                                  NULL, N_("Open a folder window for the displayed location"),
                                  G_CALLBACK (action_folder_window_callback) },

Modified: branches/multiview/src/nautilus-navigation-window-slot.c
==============================================================================
--- branches/multiview/src/nautilus-navigation-window-slot.c	(original)
+++ branches/multiview/src/nautilus-navigation-window-slot.c	Fri Mar 21 15:51:19 2008
@@ -34,16 +34,92 @@
 G_DEFINE_TYPE (NautilusNavigationWindowSlot, nautilus_navigation_window_slot, NAUTILUS_TYPE_WINDOW_SLOT)
 #define parent_class nautilus_navigation_window_slot_parent_class
 
+void
+nautilus_navigation_window_slot_clear_forward_list (NautilusNavigationWindowSlot *slot)
+{
+	g_assert (NAUTILUS_IS_NAVIGATION_WINDOW_SLOT (slot));
+
+	eel_g_object_list_free (slot->forward_list);
+	slot->forward_list = NULL;
+}
+
+void
+nautilus_navigation_window_slot_clear_back_list (NautilusNavigationWindowSlot *slot)
+{
+	g_assert (NAUTILUS_IS_NAVIGATION_WINDOW_SLOT (slot));
+
+	eel_g_object_list_free (slot->back_list);
+	slot->back_list = NULL;
+}
+
 static void
 nautilus_navigation_window_slot_active (NautilusWindowSlot *slot)
 {
-	NautilusWindow *window;
+	NautilusNavigationWindow *window;
+	NautilusNavigationWindowSlot *navigation_slot;
+	int page_num;
+
+	navigation_slot = NAUTILUS_NAVIGATION_WINDOW_SLOT (slot);
+	window = NAUTILUS_NAVIGATION_WINDOW (slot->window);
+
+	page_num = gtk_notebook_page_num (GTK_NOTEBOOK (window->notebook),
+					  slot->content_box);
+	g_assert (page_num >= 0);
 
-	window = slot->window;
+	gtk_notebook_set_current_page (GTK_NOTEBOOK (window->notebook), page_num);
 
 	EEL_CALL_PARENT (NAUTILUS_WINDOW_SLOT_CLASS, active, (slot));
 
-	nautilus_navigation_window_load_extension_toolbar_items (NAUTILUS_NAVIGATION_WINDOW (window));
+	nautilus_navigation_window_load_extension_toolbar_items (window);
+}
+ 
+static NautilusWindowSlot *
+nautilus_navigation_window_slot_get_close_successor (NautilusWindowSlot *slot)
+{
+	NautilusWindowSlot *successor;
+	NautilusNavigationWindow *window;
+	GtkNotebook *notebook;
+	GtkWidget *widget;
+	int page_num, n_pages;
+
+	window = NAUTILUS_NAVIGATION_WINDOW (slot->window);
+	notebook = GTK_NOTEBOOK (window->notebook);
+
+	n_pages = gtk_notebook_get_n_pages (notebook);
+
+	page_num = gtk_notebook_page_num (notebook, slot->content_box);
+	g_assert (page_num >= 0);
+
+	if (page_num == n_pages - 1) {
+		/* use previous page */
+		page_num--;
+	} else {
+		/* use next page */
+		page_num++;
+	}
+
+	successor = NULL;
+
+	widget = gtk_notebook_get_nth_page (notebook, page_num);
+	if (widget != NULL) {
+		successor = nautilus_window_get_slot_for_content_box (slot->window, widget);
+		if (successor == slot) {
+			successor = NULL;
+		}
+	}
+
+	return successor;
+}
+
+static void
+nautilus_navigation_window_slot_finalize (GObject *object)
+{
+	NautilusNavigationWindowSlot *slot;
+
+	slot = NAUTILUS_NAVIGATION_WINDOW_SLOT (object);
+
+	nautilus_navigation_window_slot_clear_forward_list (slot);
+	nautilus_navigation_window_slot_clear_back_list (slot);
 }
 
 static void
@@ -55,4 +131,7 @@
 nautilus_navigation_window_slot_class_init (NautilusNavigationWindowSlotClass *class)
 {
 	NAUTILUS_WINDOW_SLOT_CLASS (class)->active = nautilus_navigation_window_slot_active; 
+	NAUTILUS_WINDOW_SLOT_CLASS (class)->get_close_successor = nautilus_navigation_window_slot_get_close_successor;
+
+	G_OBJECT_CLASS (class)->finalize = nautilus_navigation_window_slot_finalize;
 }

Modified: branches/multiview/src/nautilus-navigation-window-slot.h
==============================================================================
--- branches/multiview/src/nautilus-navigation-window-slot.h	(original)
+++ branches/multiview/src/nautilus-navigation-window-slot.h	Fri Mar 21 15:51:19 2008
@@ -45,7 +45,6 @@
 } NautilusBarMode;
 
 struct NautilusNavigationWindowSlot {
-	GtkWidget *content_box;
 	NautilusWindowSlot parent;
 
 	NautilusBarMode bar_mode;
@@ -67,5 +66,8 @@
 
 GType nautilus_navigation_window_slot_get_type (void);
 
+void nautilus_navigation_window_slot_clear_forward_list (NautilusNavigationWindowSlot *slot);
+void nautilus_navigation_window_slot_clear_back_list    (NautilusNavigationWindowSlot *slot);
+
 #endif /* NAUTILUS_NAVIGATION_WINDOW_SLOT_H */
 

Modified: branches/multiview/src/nautilus-navigation-window-ui.xml
==============================================================================
--- branches/multiview/src/nautilus-navigation-window-ui.xml	(original)
+++ branches/multiview/src/nautilus-navigation-window-ui.xml	Fri Mar 21 15:51:19 2008
@@ -3,6 +3,7 @@
 	<menu action="File">
 		<placeholder name="New Items Placeholder">
 			<menuitem name="New Window" action="New Window"/>
+			<menuitem name="New Tab" action="New Tab"/>
 			<menuitem name="Folder Window" action="Folder Window"/>
 		</placeholder>
 		

Modified: branches/multiview/src/nautilus-navigation-window.c
==============================================================================
--- branches/multiview/src/nautilus-navigation-window.c	(original)
+++ branches/multiview/src/nautilus-navigation-window.c	Fri Mar 21 15:51:19 2008
@@ -184,6 +184,36 @@
 	return button;
 }
 
+static gboolean
+notebook_switch_page_cb (GtkNotebook *notebook,
+			 GtkNotebookPage *page,
+			 unsigned int page_num,
+			 NautilusNavigationWindow *window)
+{
+	NautilusWindow *nautilus_window;
+	NautilusWindowSlot *slot;
+	GtkWidget *widget;
+	GList *l;
+
+	nautilus_window = NAUTILUS_WINDOW (window);
+
+	widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK (window->notebook), page_num);
+	g_assert (widget != NULL);
+
+	/* find slot corresponding to the target page */
+	for (l = nautilus_window->details->slots; l != NULL; l = l->next) {
+		slot = NAUTILUS_WINDOW_SLOT (l->data);
+		if (slot->content_box == widget) {
+			break;
+		}
+	}
+
+	g_assert (slot != NULL);
+	nautilus_window_set_active_slot (nautilus_window, slot);
+
+	return FALSE;
+}
+
 static void
 nautilus_navigation_window_init (NautilusNavigationWindow *window)
 {
@@ -209,6 +239,10 @@
 	nautilus_horizontal_splitter_pack2 (
 		NAUTILUS_HORIZONTAL_SPLITTER (window->details->content_paned),
 		window->notebook);
+	g_signal_connect (window->notebook,
+			  "switch-page",
+			  G_CALLBACK (notebook_switch_page_cb),
+			  window);
 	gtk_notebook_set_show_tabs (GTK_NOTEBOOK (window->notebook), FALSE);
 	gtk_notebook_set_show_border (GTK_NOTEBOOK (window->notebook), FALSE);
 	gtk_widget_show (window->notebook);
@@ -712,8 +746,6 @@
 	window = NAUTILUS_NAVIGATION_WINDOW (object);
 
 	nautilus_navigation_window_remove_go_menu_callback (window);
-	nautilus_navigation_window_clear_back_list (window);
-	nautilus_navigation_window_clear_forward_list (window);
 
 	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
@@ -1188,30 +1220,6 @@
 	nautilus_query_editor_grab_focus (NAUTILUS_QUERY_EDITOR (query_editor));
 }
 
-void
-nautilus_navigation_window_clear_forward_list (NautilusNavigationWindow *window)
-{
-	NautilusNavigationWindowSlot *slot;
-
-	slot = NAUTILUS_NAVIGATION_WINDOW_SLOT (NAUTILUS_WINDOW (window)->details->active_slot);
-	g_assert (slot != NULL);
-
-	eel_g_object_list_free (slot->forward_list);
-	slot->forward_list = NULL;
-}
-
-void
-nautilus_navigation_window_clear_back_list (NautilusNavigationWindow *window)
-{
-	NautilusNavigationWindowSlot *slot;
-
-	slot = NAUTILUS_NAVIGATION_WINDOW_SLOT (NAUTILUS_WINDOW (window)->details->active_slot);
-	g_assert (slot != NULL);
-
-	eel_g_object_list_free (slot->back_list);
-	slot->back_list = NULL;
-}
-
 static void
 side_panel_image_changed_callback (NautilusSidebar *side_panel,
                                    gpointer callback_data)
@@ -1592,17 +1600,34 @@
 static NautilusWindowSlot *
 real_open_slot (NautilusWindow *window)
 {
+	NautilusNavigationWindow *navigation_window;
 	NautilusWindowSlot *slot;
+	GtkNotebook *notebook;
 
-	/* these will be removed once we have real tab support */
-	g_assert (window->details->active_slot == NULL);
-	g_assert (window->details->slots == NULL);
+	navigation_window = NAUTILUS_NAVIGATION_WINDOW (window);
+	notebook = GTK_NOTEBOOK (navigation_window->notebook);
 
 	slot = (NautilusWindowSlot *) g_object_new (NAUTILUS_TYPE_NAVIGATION_WINDOW_SLOT, NULL);
 	slot->window = window;
-	gtk_notebook_append_page (GTK_NOTEBOOK (NAUTILUS_NAVIGATION_WINDOW (window)->notebook),
+
+	g_signal_handlers_block_by_func (navigation_window->notebook,
+					 G_CALLBACK (notebook_switch_page_cb),
+					 window);
+	/* multiview-TODO add some way to influence the position.
+ 	 * We need
+ 	 *  + "behind active tab" [for views]
+ 	 *  + "at the end" [for loading sessions]
+ 	 */
+	gtk_notebook_append_page (notebook,
 				  slot->content_box,
 				  NULL);
+	g_signal_handlers_unblock_by_func (notebook,
+					   G_CALLBACK (notebook_switch_page_cb),
+					   window);
+
+	gtk_notebook_set_show_tabs (notebook,
+				    gtk_notebook_get_n_pages (notebook) > 1);
+
 	gtk_widget_show (slot->content_box);
 
 	return slot;
@@ -1612,11 +1637,29 @@
 real_close_slot (NautilusWindow *window,
 		 NautilusWindowSlot *slot)
 {
-	/* multiview-TODO these will be removed once we have real tab support */
-	g_assert (window->details->active_slot == slot);
-	g_assert (g_list_length (window->details->slots) == 1);
+	NautilusNavigationWindow *navigation_window;
+	GtkNotebook *notebook;
+	int page_num;
+
+	navigation_window = NAUTILUS_NAVIGATION_WINDOW (window);
+	notebook = GTK_NOTEBOOK (navigation_window->notebook);
+
+	page_num = gtk_notebook_page_num (notebook, slot->content_box);
+	g_assert (page_num >= 0);
 
-	/* multiview-TODO remove notebook tab */
+	g_signal_handlers_block_by_func (notebook,
+					 G_CALLBACK (notebook_switch_page_cb),
+					 window);
+	gtk_notebook_remove_page (notebook, page_num);
+	g_signal_handlers_unblock_by_func (notebook,
+					   G_CALLBACK (notebook_switch_page_cb),
+					   window);
+
+	gtk_notebook_set_show_tabs (notebook,
+				    gtk_notebook_get_n_pages (notebook) > 1);
+
+	EEL_CALL_PARENT (NAUTILUS_WINDOW_CLASS,
+			 close_slot, (window, slot));
 }
 
 static void

Modified: branches/multiview/src/nautilus-window-manage-views.c
==============================================================================
--- branches/multiview/src/nautilus-window-manage-views.c	(original)
+++ branches/multiview/src/nautilus-window-manage-views.c	Fri Mar 21 15:51:19 2008
@@ -274,6 +274,9 @@
         g_list_free_1 (link);
 }
 
+/*
+ * multiview-TODO: handle this on a per-slot basis
+ */
 static void
 handle_go_elsewhere (NautilusWindow *window, GFile *location)
 {
@@ -286,7 +289,7 @@
 		navigation_slot = (NautilusNavigationWindowSlot *) slot;
 
                 /* Clobber the entire forward list, and move displayed location to back list */
-                nautilus_navigation_window_clear_forward_list (NAUTILUS_NAVIGATION_WINDOW (window));
+                nautilus_navigation_window_slot_clear_forward_list (navigation_slot);
                 
                 if (slot->location != NULL) {
                         /* If we're returning to the same uri somehow, don't put this uri on back list. 
@@ -340,7 +343,6 @@
         g_assert (NAUTILUS_IS_FILE (file));
 	g_assert (NAUTILUS_IS_WINDOW (window));
 
-	slot = window->details->active_slot;
 	g_assert (file == slot->viewed_file);
 
         if (!nautilus_file_is_not_yet_confirmed (file)) {
@@ -499,6 +501,7 @@
 {
 	NautilusWindow *window;
         NautilusWindow *target_window;
+        NautilusWindowSlot *target_slot;
         gboolean do_load_location = TRUE;
 	GFile *old_location;
 	char *old_uri, *new_uri;
@@ -506,6 +509,7 @@
 	window = slot->window;
         
         target_window = NULL;
+	target_slot = NULL;
 
 	old_uri = nautilus_window_slot_get_location_uri (slot);
 	if (old_uri == NULL) {
@@ -586,6 +590,12 @@
 
         g_assert (target_window != NULL);
 
+	if ((flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB) != 0 &&
+	    NAUTILUS_IS_NAVIGATION_WINDOW (window)) {
+		g_assert (target_window == window);
+		target_slot = nautilus_window_open_slot (window);
+	}
+
         if ((flags & NAUTILUS_WINDOW_OPEN_FLAG_CLOSE_BEHIND) != 0) {
                 if (NAUTILUS_IS_SPATIAL_WINDOW (window) && !NAUTILUS_IS_DESKTOP_WINDOW (window)) {
                         if (GTK_WIDGET_VISIBLE (target_window)) {
@@ -611,7 +621,11 @@
 		g_object_unref (old_location);
 	}
 
-        begin_location_change (target_window->details->active_slot, location, new_selection,
+	if (target_slot == NULL) {
+		target_slot = target_window->details->active_slot;
+	}
+
+        begin_location_change (target_slot, location, new_selection,
                                NAUTILUS_LOCATION_CHANGE_STANDARD, 0, NULL);
 }
 
@@ -1115,6 +1129,11 @@
 			/* Clean up state of already-showing window */
 			end_location_change (slot);
 
+			/* TODO? shouldn't we call
+			 *   cancel_viewed_file_changed_callback (slot);
+			 * at this point, or in end_location_change()
+			 */
+
 			/* We disconnected this, so we need to re-connect it */
 			viewed_file = nautilus_file_get (slot->location);
 			nautilus_window_slot_set_viewed_file (slot, viewed_file);
@@ -1282,6 +1301,10 @@
 
 	slot = nautilus_window_get_slot_for_view (window, view);
 	g_assert (slot != NULL);
+	if (slot == NULL) {
+		/* maybe the slot was immediately closed after opening it. */
+		return;
+	}
 
         if (view == slot->new_content_view) {
 		location_has_really_changed (slot);

Modified: branches/multiview/src/nautilus-window-menus.c
==============================================================================
--- branches/multiview/src/nautilus-window-menus.c	(original)
+++ branches/multiview/src/nautilus-window-menus.c	Fri Mar 21 15:51:19 2008
@@ -191,7 +191,17 @@
 action_close_window_callback (GtkAction *action, 
 			      gpointer user_data)
 {
-	nautilus_window_close (NAUTILUS_WINDOW (user_data));
+	NautilusWindow *window;
+	NautilusWindowSlot *slot;
+
+	/* multiview-TODO rename this action, decide
+ 	 * whether we need a "close all" action
+ 	 */
+
+	window = NAUTILUS_WINDOW (user_data);
+	slot = window->details->active_slot;
+
+	nautilus_window_slot_close (slot);
 }
 
 static void

Modified: branches/multiview/src/nautilus-window-private.h
==============================================================================
--- branches/multiview/src/nautilus-window-private.h	(original)
+++ branches/multiview/src/nautilus-window-private.h	Fri Mar 21 15:51:19 2008
@@ -181,6 +181,8 @@
 
 NautilusWindowSlot *nautilus_window_get_slot_for_view                    (NautilusWindow *window,
 									  NautilusView   *view);
+NautilusWindowSlot *nautilus_window_get_slot_for_content_box             (NautilusWindow *window,
+									  GtkWidget *content_box);
 
 NautilusWindowSlot * nautilus_window_get_active_slot                     (NautilusWindow    *window);
 void                 nautilus_window_set_active_slot                     (NautilusWindow     *window,

Modified: branches/multiview/src/nautilus-window-slot.c
==============================================================================
--- branches/multiview/src/nautilus-window-slot.c	(original)
+++ branches/multiview/src/nautilus-window-slot.c	Fri Mar 21 15:51:19 2008
@@ -71,6 +71,7 @@
 	g_assert (NAUTILUS_IS_WINDOW_SLOT (slot));
 
 	window = NAUTILUS_WINDOW (slot->window);
+	g_assert (g_list_find (window->details->slots, slot) != NULL);
 	g_assert (slot == window->details->active_slot);
 
 	EEL_CALL_METHOD (NAUTILUS_WINDOW_SLOT_CLASS, slot,
@@ -94,6 +95,9 @@
 	NautilusWindow *window;
 
 	g_assert (NAUTILUS_IS_WINDOW_SLOT (slot));
+
+	window = NAUTILUS_WINDOW (slot->window);
+	g_assert (g_list_find (window->details->slots, slot) != NULL);
 	g_assert (slot == window->details->active_slot);
 
 	EEL_CALL_METHOD (NAUTILUS_WINDOW_SLOT_CLASS, slot,
@@ -125,11 +129,19 @@
 	gtk_widget_show (slot->view_box);
 }
 
+static NautilusWindowSlot *
+real_get_close_successor (NautilusWindowSlot *slot)
+{
+	return NULL;
+}
+
 static void
 nautilus_window_slot_class_init (NautilusWindowSlotClass *class)
 {
 	class->active = real_active;
 	class->inactive = real_inactive;
+	class->get_close_successor = real_get_close_successor;
+
 	G_OBJECT_CLASS (class)->finalize = nautilus_window_slot_finalize;
 }
 
@@ -321,10 +333,24 @@
 	gtk_widget_show (slot->extra_location_widgets);
 }
 
+/* gets the slot that is supposed to be displayed after closing
+ * the active slot.
+ */
+NautilusWindowSlot *
+nautilus_window_slot_get_close_successor (NautilusWindowSlot *slot)
+{
+	return EEL_CALL_METHOD_WITH_RETURN_VALUE (NAUTILUS_WINDOW_SLOT_CLASS, slot,
+						  get_close_successor, (slot));
+}
+
+
 static void
 nautilus_window_slot_finalize (GObject *object)
 {
-	NautilusWindowSlot *slot = NAUTILUS_WINDOW_SLOT (object);
+	NautilusWindowSlot *slot;
+	GtkWidget *widget;
+
+	slot = NAUTILUS_WINDOW_SLOT (object);
 
 	nautilus_window_slot_set_viewed_file (slot, NULL);
 	/* TODO? why do we unref here? the file is NULL.
@@ -350,6 +376,20 @@
 		slot->find_mount_cancellable = NULL;
 	}
 
+	if (slot->content_view) {
+		widget = nautilus_view_get_widget (slot->content_view);
+		gtk_widget_destroy (widget);
+		g_object_unref (slot->content_view);
+		slot->content_view = NULL;
+	}
+
+	if (slot->new_content_view) {
+		widget = nautilus_view_get_widget (slot->new_content_view);
+		gtk_widget_destroy (widget);
+		g_object_unref (slot->new_content_view);
+		slot->new_content_view = NULL;
+	}
+
 	g_free (slot->title);
 }
 

Modified: branches/multiview/src/nautilus-window-slot.h
==============================================================================
--- branches/multiview/src/nautilus-window-slot.h	(original)
+++ branches/multiview/src/nautilus-window-slot.h	Fri Mar 21 15:51:19 2008
@@ -46,8 +46,12 @@
 struct NautilusWindowSlotClass {
 	GObjectClass parent_class;
 
+	/* wrapped NautilusWindowInfo signals, for overloading */
 	void (* active)   (NautilusWindowSlot *slot);
 	void (* inactive) (NautilusWindowSlot *slot);
+
+	/* gets the slot to make active after this slot has been closed. */
+	NautilusWindowSlot * (* get_close_successor) (NautilusWindowSlot *slot);
 };
 
 /* Each NautilusWindowSlot corresponds to
@@ -113,9 +117,21 @@
 GFile * nautilus_window_slot_get_location		   (NautilusWindowSlot *slot);
 char *  nautilus_window_slot_get_location_uri		   (NautilusWindowSlot *slot);
 
+NautilusWindowSlot *
+	nautilus_window_slot_get_close_successor           (NautilusWindowSlot *slot);
 void    nautilus_window_slot_close			   (NautilusWindowSlot *slot);
 void    nautilus_window_slot_reload			   (NautilusWindowSlot *slot);
 
+#define nautilus_window_slot_go_to(slot,location) \
+	nautilus_window_slot_open_location(slot, location, FALSE)
+
+#define nautilus_window_slot_go_to_with_selection(slot,location,new_selection) \
+	nautilus_window_slot_open_location_with_selection(slot, location, new_selection, FALSE)
+
+void    nautilus_window_slot_go_home			   (NautilusWindow    *window);
+void    nautilus_window_slot_go_up			   (NautilusWindow    *window,
+							    gboolean           close_behind);
+
 void    nautilus_window_slot_set_content_view_widget	   (NautilusWindowSlot *slot,
 							    NautilusView       *content_view);
 void    nautilus_window_slot_set_viewed_file		   (NautilusWindowSlot *slot,

Modified: branches/multiview/src/nautilus-window.c
==============================================================================
--- branches/multiview/src/nautilus-window.c	(original)
+++ branches/multiview/src/nautilus-window.c	Fri Mar 21 15:51:19 2008
@@ -37,6 +37,8 @@
 #include "nautilus-main.h"
 #include "nautilus-window-manage-views.h"
 #include "nautilus-window-bookmarks.h"
+#include "nautilus-window-slot.h"
+#include "nautilus-navigation-window-slot.h"
 #include "nautilus-zoom-control.h"
 #include "nautilus-search-bar.h"
 #include <eel/eel-debug.h>
@@ -240,7 +242,7 @@
 {
 	g_return_if_fail (NAUTILUS_IS_WINDOW (window));
 
-	nautilus_window_slot_open_location (window->details->active_slot, location, FALSE);
+	nautilus_window_slot_go_to (window->details->active_slot, location);
 }
 
 
@@ -249,7 +251,7 @@
 {
 	g_return_if_fail (NAUTILUS_IS_WINDOW (window));
 
-	nautilus_window_slot_open_location_with_selection (window->details->active_slot, location, new_selection, FALSE);
+	nautilus_window_slot_go_to_with_selection (window->details->active_slot, location, new_selection);
 }
 
 static gboolean
@@ -645,7 +647,6 @@
 {
 	NautilusWindow *window;
 	NautilusWindowSlot *slot;
-	GtkWidget *widget;
 	GList *l;
 
 	window = NAUTILUS_WINDOW (object);
@@ -657,18 +658,7 @@
 		slot = l->data;
 
 		cancel_view_as_callback (slot);
-
-		if (slot->content_view) {
-			g_object_unref (slot->content_view);
-			slot->content_view = NULL;
-		}
-
-		if (slot->new_content_view) {
-			widget = nautilus_view_get_widget (slot->new_content_view);
-			gtk_widget_destroy (widget);
-			g_object_unref (slot->new_content_view);
-			slot->new_content_view = NULL;
-		}
+		g_object_unref (slot);
 	}
 
 	GTK_OBJECT_CLASS (nautilus_window_parent_class)->destroy (object);
@@ -707,6 +697,7 @@
 {
 	GObject *object;
 	NautilusWindow *window;
+	NautilusWindowSlot *slot;
 
 	object = (* G_OBJECT_CLASS (nautilus_window_parent_class)->constructor) (type,
 										 n_construct_properties,
@@ -714,7 +705,6 @@
 
 	window = NAUTILUS_WINDOW (object);
 
-	NautilusWindowSlot *slot;
 	slot = nautilus_window_open_slot (window);
 	nautilus_window_set_active_slot (window, slot);
 
@@ -755,8 +745,18 @@
 void
 nautilus_window_close (NautilusWindow *window)
 {
+	NautilusWindowSlot *slot;
+	GList *l;
+
 	g_return_if_fail (NAUTILUS_IS_WINDOW (window));
 
+	nautilus_window_set_active_slot (window, NULL);
+
+	for (l = window->details->slots; l != NULL; l = l->next) {
+		slot = NAUTILUS_WINDOW_SLOT (l->data);
+		nautilus_window_close_slot (window, slot);
+	}
+
 	EEL_CALL_METHOD (NAUTILUS_WINDOW_CLASS, window,
 			 close, (window));
 	
@@ -781,6 +781,13 @@
 	return slot;
 }
 
+static void
+real_close_slot (NautilusWindow *window,
+		 NautilusWindowSlot *slot)
+{
+	g_object_unref (slot);
+}
+
 void
 nautilus_window_close_slot (NautilusWindow *window,
 			    NautilusWindowSlot *slot)
@@ -794,7 +801,6 @@
 			 close_slot, (window, slot));
 
 	window->details->slots = g_list_remove (window->details->slots, slot);
-	nautilus_window_slot_set_allow_stop (slot, FALSE);
 }
 
 void
@@ -804,10 +810,12 @@
 	NautilusWindowSlot *old_slot;
 
 	g_assert (NAUTILUS_IS_WINDOW (window));
-	g_assert (NAUTILUS_IS_WINDOW_SLOT (new_slot));
-	g_assert (window == new_slot->window);
 
-	g_assert (g_list_find (window->details->slots, new_slot) != NULL);
+	if (new_slot != NULL) {
+		g_assert (NAUTILUS_IS_WINDOW_SLOT (new_slot));
+		g_assert (window == new_slot->window);
+		g_assert (g_list_find (window->details->slots, new_slot) != NULL);
+	}
 
 	old_slot = window->details->active_slot;
 
@@ -827,17 +835,20 @@
 
 	window->details->active_slot = new_slot;
 
-	/* inform sidebar panels */
-	nautilus_window_report_location_change (window, TRUE);
-	/* TODO decide whether "selection-changed" should be emitted */
 
-	if (new_slot->content_view != NULL) {
-		/* inform window */
-		nautilus_window_connect_content_view (window, new_slot->content_view);
-	}
+	if (new_slot != NULL) {
+		/* inform sidebar panels */
+		nautilus_window_report_location_change (window, TRUE);
+		/* TODO decide whether "selection-changed" should be emitted */
+
+		if (new_slot->content_view != NULL) {
+			/* inform window */
+			nautilus_window_connect_content_view (window, new_slot->content_view);
+		}
 
-	/* inform slot & view */
-	g_signal_emit_by_name (new_slot, "active");
+		/* inform slot & view */
+		g_signal_emit_by_name (new_slot, "active");
+	}
 }
 
 void
@@ -847,18 +858,11 @@
 
 	window = slot->window;
 
-	if (g_list_length (window->details->slots) > 1) {
-		EEL_CALL_METHOD (NAUTILUS_WINDOW_CLASS, window,
-				 close_slot, (window, slot));
-		g_object_unref (slot);
-	} else {
-		/* no slot_closed will be emitted for the last slot.
- 		 * All the NautilusWindowInfo clients life inside the window, so they
- 		 * will be destroyed anyway.
- 		 *
- 		 * This is just for convenience, because otherwise we'd have to handle
- 		 * windows without any active slot.
- 		 */
+	nautilus_window_set_active_slot (window,	
+					 nautilus_window_slot_get_close_successor (slot));
+	nautilus_window_close_slot (window, slot);
+
+	if (g_list_length (window->details->slots) == 0) {
 		nautilus_window_close (window);
 	}
 }
@@ -1255,9 +1259,12 @@
 
 	slot = callback_data;
 	window = NAUTILUS_WINDOW (slot->window);
-	
-	EEL_CALL_METHOD (NAUTILUS_WINDOW_CLASS, window,
-                         load_view_as_menu, (window));
+
+	if (slot == window->details->active_slot) {
+		/* slot may have changed in the meantime */
+		EEL_CALL_METHOD (NAUTILUS_WINDOW_CLASS, window,
+				 load_view_as_menu, (window));
+	}
 }
 
 static void
@@ -1347,7 +1354,7 @@
          * views in the menu are for the old location).
          */
 	if (slot->pending_location == NULL) {
-		nautilus_window_synch_view_as_menus (window);
+		nautilus_window_load_view_as_menus (window);
 	}
 
 	nautilus_view_grab_focus (view);
@@ -1642,6 +1649,24 @@
 	return NULL;
 }
 
+NautilusWindowSlot *
+nautilus_window_get_slot_for_content_box (NautilusWindow *window,
+					  GtkWidget *content_box)
+{
+	NautilusWindowSlot *slot;
+	GList *l;
+
+	for (l = window->details->slots; l != NULL; l = l->next) {
+		slot = NAUTILUS_WINDOW_SLOT (l->data);
+
+		if (slot->content_box == content_box) {
+			return slot;
+		}
+	}
+
+	return NULL;
+}
+
 void
 nautilus_window_add_current_location_to_history_list (NautilusWindow *window)
 {
@@ -1655,6 +1680,7 @@
 nautilus_forget_history (void) 
 {
 	NautilusWindowSlot *slot;
+	NautilusNavigationWindowSlot *navigation_slot;
 	GList *window_node, *l;
 
 	/* Clear out each window's back & forward lists. Also, remove 
@@ -1669,10 +1695,15 @@
 			NautilusNavigationWindow *window;
 			
 			window = NAUTILUS_NAVIGATION_WINDOW (window_node->data);
-			
-			nautilus_navigation_window_clear_back_list (window);
-			nautilus_navigation_window_clear_forward_list (window);
-			
+
+			for (l = NAUTILUS_WINDOW (window_node->data)->details->slots;
+			     l != NULL; l = l->next) {
+				navigation_slot = l->data;
+
+				nautilus_navigation_window_slot_clear_back_list (navigation_slot);
+				nautilus_navigation_window_slot_clear_forward_list (navigation_slot);
+			}
+
 			nautilus_navigation_window_allow_back (window, FALSE);
 			nautilus_navigation_window_allow_forward (window, FALSE);
 		}
@@ -1834,6 +1865,7 @@
 	class->disconnect_content_view = real_disconnect_content_view;
 	class->load_view_as_menu = real_load_view_as_menu;
 	class->set_allow_up = real_set_allow_up;
+	class->close_slot = real_close_slot;
 
 	g_object_class_install_property (G_OBJECT_CLASS (class),
 					 ARG_APP,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]