summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCosimo Cecchi <cosimoc@gnome.org>2012-10-29 07:50:37 -0400
committerCosimo Cecchi <cosimoc@gnome.org>2012-10-29 07:50:37 -0400
commit37e46337dad263b2e1931f30a1deb30a57a44ebf (patch)
tree2cceffe81df48792d8fd0c29a7f3e0f2559d6232
parentf5078be101bc506d6da8a928ce3d44eb1c50e409 (diff)
downloadnautilus-37e46337dad263b2e1931f30a1deb30a57a44ebf.tar.gz
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
-rw-r--r--src/nautilus-places-sidebar.c73
-rw-r--r--src/nautilus-window.c14
2 files changed, 49 insertions, 38 deletions
diff --git a/src/nautilus-places-sidebar.c b/src/nautilus-places-sidebar.c
index 1a732e8dd..33ab83be1 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 bf10c9e36..90d3a9964 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);