[nautilus] places-sidebar: make sure to pre-select the active item on construction



commit 37e46337dad263b2e1931f30a1deb30a57a44ebf
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Mon Oct 29 07:50:37 2012 -0400

    places-sidebar: make sure to pre-select the active item on construction
    
    Ensure the current window URI gets selected in the sidebar also when
    it's already set on the window at construction.
    At the same time, move the sidebar construction from
    nautilus_window_show() to nautilus_window_constructed().
    
    https://bugzilla.gnome.org/show_bug.cgi?id=674052

 src/nautilus-places-sidebar.c |   73 +++++++++++++++++++++++-----------------
 src/nautilus-window.c         |   14 ++++----
 2 files changed, 49 insertions(+), 38 deletions(-)
---
diff --git a/src/nautilus-places-sidebar.c b/src/nautilus-places-sidebar.c
index 1a732e8..33ab83b 100644
--- a/src/nautilus-places-sidebar.c
+++ b/src/nautilus-places-sidebar.c
@@ -992,41 +992,52 @@ desktop_setting_changed_callback (gpointer user_data)
 }
 
 static void
-loading_uri_callback (NautilusWindow *window,
-		      char *location,
-		      NautilusPlacesSidebar *sidebar)
+update_current_uri (NautilusPlacesSidebar *sidebar)
 {
 	GtkTreeSelection *selection;
 	GtkTreeIter 	 iter;
 	gboolean 	 valid;
 	char  		 *uri;
 
-        if (strcmp (sidebar->uri, location) != 0) {
-		g_free (sidebar->uri);
-                sidebar->uri = g_strdup (location);
-  
-		/* set selection if any place matches location */
-		selection = gtk_tree_view_get_selection (sidebar->tree_view);
-		gtk_tree_selection_unselect_all (selection);
-  		valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (sidebar->store),
-						       &iter);
+	if (sidebar->uri == NULL) {
+		return;
+	}
 
-		while (valid) {
-			gtk_tree_model_get (GTK_TREE_MODEL (sidebar->store), &iter, 
-		 		       	    PLACES_SIDEBAR_COLUMN_URI, &uri,
-					    -1);
-			if (uri != NULL) {
-				if (strcmp (uri, location) == 0) {
-					g_free (uri);
-					gtk_tree_selection_select_iter (selection, &iter);
-					break;
-				}
+	/* set selection if any place matches location */
+	selection = gtk_tree_view_get_selection (sidebar->tree_view);
+	gtk_tree_selection_unselect_all (selection);
+	valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (sidebar->store),
+					       &iter);
+
+	while (valid) {
+		gtk_tree_model_get (GTK_TREE_MODEL (sidebar->store), &iter,
+				    PLACES_SIDEBAR_COLUMN_URI, &uri,
+				    -1);
+
+		if (uri != NULL) {
+			if (strcmp (uri, sidebar->uri) == 0) {
 				g_free (uri);
+				gtk_tree_selection_select_iter (selection, &iter);
+				break;
 			}
-        	 	valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (sidebar->store),
-							  &iter);
+			g_free (uri);
 		}
-    	}
+		valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (sidebar->store),
+						  &iter);
+	}
+}
+
+static void
+loading_uri_callback (NautilusWindow *window,
+		      char *location,
+		      NautilusPlacesSidebar *sidebar)
+{
+        if (g_strcmp0 (sidebar->uri, location) != 0) {
+		g_free (sidebar->uri);
+                sidebar->uri = g_strdup (location);
+
+		update_current_uri (sidebar);
+	}
 }
 
 /* Computes the appropriate row and position for dropping */
@@ -3343,17 +3354,11 @@ nautilus_places_sidebar_set_parent_window (NautilusPlacesSidebar *sidebar,
 	slot = nautilus_window_get_active_slot (window);
 
 	sidebar->bookmarks = nautilus_application_get_bookmarks (app);
-	sidebar->uri = nautilus_window_slot_get_current_uri (slot);
-
 	sidebar->bookmarks_changed_id =
 		g_signal_connect_swapped (sidebar->bookmarks, "changed",
 					  G_CALLBACK (update_places),
 					  sidebar);
 
-	g_signal_connect_object (window, "loading_uri",
-				 G_CALLBACK (loading_uri_callback),
-				 sidebar, 0);
-			 
 	g_signal_connect_object (sidebar->volume_monitor, "volume_added",
 				 G_CALLBACK (volume_added_callback), sidebar, 0);
 	g_signal_connect_object (sidebar->volume_monitor, "volume_removed",
@@ -3374,6 +3379,12 @@ nautilus_places_sidebar_set_parent_window (NautilusPlacesSidebar *sidebar,
 				 G_CALLBACK (drive_changed_callback), sidebar, 0);
 
 	update_places (sidebar);
+
+	g_signal_connect_object (window, "loading-uri",
+				 G_CALLBACK (loading_uri_callback),
+				 sidebar, 0);
+	sidebar->uri = nautilus_window_slot_get_current_uri (slot);
+	update_current_uri (sidebar);
 }
 
 static void
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index bf10c9e..90d3a99 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -1190,6 +1190,12 @@ nautilus_window_constructed (GObject *self)
 	slot = nautilus_window_open_slot (window, 0);
 	nautilus_window_set_active_slot (window, slot);
 
+	if (g_settings_get_boolean (nautilus_window_state, NAUTILUS_WINDOW_STATE_START_WITH_SIDEBAR)) {
+		nautilus_window_show_sidebar (window);
+	} else {
+		nautilus_window_hide_sidebar (window);
+	}
+
 	application = NAUTILUS_APPLICATION (g_application_get_default ());
 	window->details->bookmarks_id =
 		g_signal_connect_swapped (nautilus_application_get_bookmarks (application), "changed",
@@ -1389,7 +1395,7 @@ nautilus_window_report_location_change (NautilusWindow *window)
 	uri = nautilus_window_slot_get_current_uri (slot);
 
 	if (uri != NULL) {
-		g_signal_emit_by_name (window, "loading-uri", uri);
+		g_signal_emit (window, signals[LOADING_URI], 0, uri);
 		g_free (uri);
 	}
 }
@@ -1726,12 +1732,6 @@ nautilus_window_show (GtkWidget *widget)
 
 	window = NAUTILUS_WINDOW (widget);
 
-	if (g_settings_get_boolean (nautilus_window_state, NAUTILUS_WINDOW_STATE_START_WITH_SIDEBAR)) {
-		nautilus_window_show_sidebar (window);
-	} else {
-		nautilus_window_hide_sidebar (window);
-	}
-
 	GTK_WIDGET_CLASS (nautilus_window_parent_class)->show (widget);	
 
 	gtk_ui_manager_ensure_update (window->details->ui_manager);



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