[nautilus] views: fix alternate locaiton opening somewhat



commit 1988c7bc5feff1a2630b2603d558d1c376b12c9f
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Fri Feb 18 10:53:08 2011 -0500

    views: fix alternate locaiton opening somewhat
    
    It was broken after the last changes.
    Also, add some comments to clarify how things work.

 src/nautilus-icon-view.c           |   67 ++++++++++++++++++++++++++----------
 src/nautilus-list-view.c           |   19 ++++++----
 src/nautilus-window-manage-views.c |   45 +++++++++++++++++++++---
 3 files changed, 101 insertions(+), 30 deletions(-)
---
diff --git a/src/nautilus-icon-view.c b/src/nautilus-icon-view.c
index e2ba952..3ae2ed9 100644
--- a/src/nautilus-icon-view.c
+++ b/src/nautilus-icon-view.c
@@ -59,6 +59,10 @@
 #include <libnautilus-private/nautilus-metadata.h>
 #include <libnautilus-private/nautilus-clipboard.h>
 #include <libnautilus-private/nautilus-desktop-icon-file.h>
+
+#define DEBUG_FLAG NAUTILUS_DEBUG_ICON_VIEW
+#include <libnautilus-private/nautilus-debug.h>
+
 #include <locale.h>
 #include <signal.h>
 #include <stdio.h>
@@ -1795,6 +1799,19 @@ icon_container_activate_callback (NautilusIconContainer *container,
 				      0, TRUE);
 }
 
+/* this is called in one of these cases:
+ * - we activate with enter holding shift
+ * - we activate with space holding shift
+ * - we double click an icon holding shift
+ * - we middle click an icon
+ *
+ * If we don't open in new windows by default, the behavior should be
+ * - middle click, shift + activate -> open in new tab
+ * - shift + double click -> open in new window
+ *
+ * If we open in new windows by default, the behaviour should be
+ * - middle click, or shift + activate, or shift + double-click -> close parent
+ */
 static void
 icon_container_activate_alternate_callback (NautilusIconContainer *container,
 					    GList *file_list,
@@ -1803,37 +1820,51 @@ icon_container_activate_alternate_callback (NautilusIconContainer *container,
 	GdkEvent *event;
 	GdkEventButton *button_event;
 	GdkEventKey *key_event;
-	gboolean open_in_tab;
+	gboolean open_in_tab, open_in_window, close_behind;
 	NautilusWindowOpenFlags flags;
 
 	g_assert (NAUTILUS_IS_ICON_VIEW (icon_view));
 	g_assert (container == get_icon_container (icon_view));
 
-	open_in_tab = FALSE;
-
+	flags = 0;
 	event = gtk_get_current_event ();
-	if (event->type == GDK_BUTTON_PRESS ||
-	    event->type == GDK_BUTTON_RELEASE ||
-	    event->type == GDK_2BUTTON_PRESS ||
-	    event->type == GDK_3BUTTON_PRESS) {
-		button_event = (GdkEventButton *) event;
-		open_in_tab = (button_event->state & GDK_SHIFT_MASK) == 0;
-	} else if (event->type == GDK_KEY_PRESS ||
-		   event->type == GDK_KEY_RELEASE) {
-		key_event = (GdkEventKey *) event;
-		open_in_tab = !((key_event->state & GDK_SHIFT_MASK) != 0 &&
-				(key_event->state & GDK_CONTROL_MASK) != 0);
+	open_in_tab = FALSE;
+	open_in_window = FALSE;
+	close_behind = FALSE;
+	
+	if (g_settings_get_boolean (nautilus_preferences,
+				    NAUTILUS_PREFERENCES_ALWAYS_USE_BROWSER)) {
+		if (event->type == GDK_BUTTON_PRESS ||
+		    event->type == GDK_BUTTON_RELEASE ||
+		    event->type == GDK_2BUTTON_PRESS ||
+		    event->type == GDK_3BUTTON_PRESS) {
+			button_event = (GdkEventButton *) event;
+			open_in_window = ((button_event->state & GDK_SHIFT_MASK) != 0);
+			open_in_tab = !open_in_window;
+		} else if (event->type == GDK_KEY_PRESS ||
+			   event->type == GDK_KEY_RELEASE) {
+			key_event = (GdkEventKey *) event;
+			open_in_tab = ((key_event->state & GDK_SHIFT_MASK) != 0);
+		}
 	} else {
-		open_in_tab = TRUE;
-	}
+		close_behind = TRUE;
+	} 
 
-	flags = NAUTILUS_WINDOW_OPEN_FLAG_CLOSE_BEHIND;
 	if (open_in_tab) {
 		flags |= NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB;
-	} else {
+	}
+
+	if (open_in_window) {
 		flags |= NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW;
 	}
 
+	if (close_behind) {
+		flags |= NAUTILUS_WINDOW_OPEN_FLAG_CLOSE_BEHIND;
+	}
+
+	DEBUG ("Activate alternate, open in tab %d, close behind %d, new window %d\n",
+	       open_in_tab, close_behind, open_in_window);
+
 	nautilus_view_activate_files (NAUTILUS_VIEW (icon_view), 
 				      file_list, 
 				      flags,
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index 5da88eb..c9e5ac5 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -273,13 +273,18 @@ activate_selected_items_alternate (NautilusListView *view,
 	GList *file_list;
 	NautilusWindowOpenFlags flags;
 
-	flags = NAUTILUS_WINDOW_OPEN_FLAG_CLOSE_BEHIND;
+	flags = 0;
 
-	if (open_in_tab) {
-		flags |= NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB;
-        } else {
-		flags |= NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW;
-        }
+	if (g_settings_get_boolean (nautilus_preferences,
+				    NAUTILUS_PREFERENCES_ALWAYS_USE_BROWSER)) {
+		if (open_in_tab) {
+			flags |= NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB;
+		} else {
+			flags |= NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW;
+		}
+	} else {
+		flags |= NAUTILUS_WINDOW_OPEN_FLAG_CLOSE_BEHIND;
+	}
 
 	if (file != NULL) {
 		nautilus_file_ref (file);
diff --git a/src/nautilus-window-manage-views.c b/src/nautilus-window-manage-views.c
index 6c259bd..a685888 100644
--- a/src/nautilus-window-manage-views.c
+++ b/src/nautilus-window-manage-views.c
@@ -417,6 +417,19 @@ cancel_viewed_file_changed_callback (NautilusWindowSlot *slot)
         }
 }
 
+static void
+new_window_show_callback (GtkWidget *widget,
+			  gpointer user_data){
+	NautilusWindow *window;
+
+	window = NAUTILUS_WINDOW (user_data);
+	nautilus_window_close (window);
+
+	g_signal_handlers_disconnect_by_func (widget,
+					      G_CALLBACK (new_window_show_callback),
+					      user_data);
+}
+
 void
 nautilus_window_slot_open_location_full (NautilusWindowSlot *slot,
 					 GFile *location,
@@ -444,6 +457,7 @@ nautilus_window_slot_open_location_full (NautilusWindowSlot *slot,
 	target_slot = NULL;
 	use_same = FALSE;
 
+	/* this happens at startup */
 	old_uri = nautilus_window_slot_get_location_uri (slot);
 	if (old_uri == NULL) {
 		old_uri = g_strdup ("(none)");
@@ -460,27 +474,33 @@ nautilus_window_slot_open_location_full (NautilusWindowSlot *slot,
 		    (flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB) != 0));
 
 	is_desktop = NAUTILUS_IS_DESKTOP_WINDOW (window);
+
+	/* we use the same window if the preferences say so, but also for the first desktop window */
 	use_same |= g_settings_get_boolean (nautilus_preferences, NAUTILUS_PREFERENCES_ALWAYS_USE_BROWSER) ||
 		(is_desktop && !nautilus_desktop_window_loaded (NAUTILUS_DESKTOP_WINDOW (window)));
 
-	old_location = nautilus_window_slot_get_location (slot);
+	/* and if the flags specify so, this is overridden */
+	if ((flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW) != 0) {
+		use_same = FALSE;
+	}
 
-	app = nautilus_application_dup_singleton ();
+	old_location = nautilus_window_slot_get_location (slot);
 
-	/* now get/create the window according to the mode */
+	/* now get/create the window */
 	if (use_same) {
 		target_window = window;
 	} else {
+		app = nautilus_application_dup_singleton ();
 		target_window = nautilus_application_create_window
 			(app,
 			 NULL,
 			 gtk_window_get_screen (GTK_WINDOW (window)));
+		g_object_unref (app);
 	}
 
-	g_object_unref (app);
-
         g_assert (target_window != NULL);
 
+	/* if the flags say we want a new tab, open a slot in the current window */
 	if ((flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB) != 0) {
 		g_assert (target_window == window);
 
@@ -494,6 +514,21 @@ nautilus_window_slot_open_location_full (NautilusWindowSlot *slot,
 		target_slot = nautilus_window_open_slot (window->details->active_pane, slot_flags);
 	}
 
+	/* close the current window if the flags say so */
+	if ((flags & NAUTILUS_WINDOW_OPEN_FLAG_CLOSE_BEHIND) != 0) {
+		if (!is_desktop) {
+			if (gtk_widget_get_visible (GTK_WIDGET (target_window))) {
+				nautilus_window_close (window);
+			} else {
+				g_signal_connect_object (target_window,
+							 "show",
+							 G_CALLBACK (new_window_show_callback),
+							 window,
+							 G_CONNECT_AFTER);
+			}
+		}
+	}
+
 	if (target_slot == NULL) {
 		if (target_window == window) {
 			target_slot = slot;



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