Commit c87d0252 authored by Cosimo Cecchi's avatar Cosimo Cecchi

Preserve last selection while updating places.

parent 6b768ef1
...@@ -265,12 +265,41 @@ add_place (NautilusPlacesSidebar *sidebar, ...@@ -265,12 +265,41 @@ add_place (NautilusPlacesSidebar *sidebar,
return child_iter; return child_iter;
} }
static void
compare_for_selection (NautilusPlacesSidebar *sidebar,
const gchar *location,
const gchar *added_uri,
const gchar *last_uri,
GtkTreeIter *iter,
GtkTreePath **path)
{
int res;
res = eel_strcmp (added_uri, last_uri);
if (res == 0) {
/* last_uri always comes first */
if (*path != NULL) {
gtk_tree_path_free (*path);
}
*path = gtk_tree_model_get_path (sidebar->filter_model,
iter);
} else if (eel_strcmp (location, added_uri) == 0) {
if (*path == NULL) {
*path = gtk_tree_model_get_path (sidebar->filter_model,
iter);
}
}
}
static void static void
update_places (NautilusPlacesSidebar *sidebar) update_places (NautilusPlacesSidebar *sidebar)
{ {
NautilusBookmark *bookmark; NautilusBookmark *bookmark;
GtkTreeSelection *selection; GtkTreeSelection *selection;
GtkTreeIter iter, last_iter; GtkTreeIter iter, last_iter;
GtkTreePath *select_path;
GtkTreeModel *model = NULL;
GVolumeMonitor *volume_monitor; GVolumeMonitor *volume_monitor;
GList *mounts, *l, *ll; GList *mounts, *l, *ll;
GMount *mount; GMount *mount;
...@@ -279,14 +308,20 @@ update_places (NautilusPlacesSidebar *sidebar) ...@@ -279,14 +308,20 @@ update_places (NautilusPlacesSidebar *sidebar)
GList *volumes; GList *volumes;
GVolume *volume; GVolume *volume;
int bookmark_count, index; int bookmark_count, index;
char *location, *mount_uri, *name, *desktop_path; char *location, *mount_uri, *name, *desktop_path, *last_uri;
GIcon *icon; GIcon *icon;
GFile *root; GFile *root;
NautilusWindowSlotInfo *slot; NautilusWindowSlotInfo *slot;
char *tooltip; char *tooltip;
selection = gtk_tree_view_get_selection (sidebar->tree_view); selection = gtk_tree_view_get_selection (sidebar->tree_view);
if (gtk_tree_selection_get_selected (selection, &model, &last_iter)) {
gtk_tree_model_get (model,
&last_iter,
PLACES_SIDEBAR_COLUMN_URI, &last_uri, -1);
}
gtk_list_store_clear (sidebar->store); gtk_list_store_clear (sidebar->store);
select_path = NULL;
slot = nautilus_window_info_get_active_slot (sidebar->window); slot = nautilus_window_info_get_active_slot (sidebar->window);
location = nautilus_window_slot_info_get_current_location (slot); location = nautilus_window_slot_info_get_current_location (slot);
...@@ -306,9 +341,9 @@ update_places (NautilusPlacesSidebar *sidebar) ...@@ -306,9 +341,9 @@ update_places (NautilusPlacesSidebar *sidebar)
_("Open your personal folder")); _("Open your personal folder"));
g_object_unref (icon); g_object_unref (icon);
g_free (display_name); g_free (display_name);
if (eel_strcmp (location, mount_uri) == 0) { compare_for_selection (sidebar,
gtk_tree_selection_select_iter (selection, &last_iter); location, mount_uri, last_uri,
} &last_iter, &select_path);
g_free (mount_uri); g_free (mount_uri);
} }
...@@ -319,9 +354,9 @@ update_places (NautilusPlacesSidebar *sidebar) ...@@ -319,9 +354,9 @@ update_places (NautilusPlacesSidebar *sidebar)
mount_uri, NULL, NULL, NULL, 0, mount_uri, NULL, NULL, NULL, 0,
_("Open the contents of your desktop in a folder")); _("Open the contents of your desktop in a folder"));
g_object_unref (icon); g_object_unref (icon);
if (eel_strcmp (location, mount_uri) == 0) { compare_for_selection (sidebar,
gtk_tree_selection_select_iter (selection, &last_iter); location, mount_uri, last_uri,
} &last_iter, &select_path);
g_free (mount_uri); g_free (mount_uri);
g_free (desktop_path); g_free (desktop_path);
...@@ -332,9 +367,9 @@ update_places (NautilusPlacesSidebar *sidebar) ...@@ -332,9 +367,9 @@ update_places (NautilusPlacesSidebar *sidebar)
mount_uri, NULL, NULL, NULL, 0, mount_uri, NULL, NULL, NULL, 0,
_("Open the contents of the File System")); _("Open the contents of the File System"));
g_object_unref (icon); g_object_unref (icon);
if (eel_strcmp (location, mount_uri) == 0) { compare_for_selection (sidebar,
gtk_tree_selection_select_iter (selection, &last_iter); location, mount_uri, last_uri,
} &last_iter, &select_path);
mount_uri = "network:///"; /* No need to strdup */ mount_uri = "network:///"; /* No need to strdup */
icon = g_themed_icon_new (NAUTILUS_ICON_NETWORK); icon = g_themed_icon_new (NAUTILUS_ICON_NETWORK);
...@@ -343,9 +378,9 @@ update_places (NautilusPlacesSidebar *sidebar) ...@@ -343,9 +378,9 @@ update_places (NautilusPlacesSidebar *sidebar)
mount_uri, NULL, NULL, NULL, 0, mount_uri, NULL, NULL, NULL, 0,
_("Browse the contents of the network")); _("Browse the contents of the network"));
g_object_unref (icon); g_object_unref (icon);
if (strcmp (location, mount_uri) == 0) { compare_for_selection (sidebar,
gtk_tree_selection_select_iter (selection, &last_iter); location, mount_uri, last_uri,
} &last_iter, &select_path);
volume_monitor = sidebar->volume_monitor; volume_monitor = sidebar->volume_monitor;
...@@ -369,9 +404,9 @@ update_places (NautilusPlacesSidebar *sidebar) ...@@ -369,9 +404,9 @@ update_places (NautilusPlacesSidebar *sidebar)
last_iter = add_place (sidebar, PLACES_MOUNTED_VOLUME, last_iter = add_place (sidebar, PLACES_MOUNTED_VOLUME,
name, icon, mount_uri, name, icon, mount_uri,
drive, volume, mount, 0, tooltip); drive, volume, mount, 0, tooltip);
if (eel_strcmp (location, mount_uri) == 0) { compare_for_selection (sidebar,
gtk_tree_selection_select_iter (selection, &last_iter); location, mount_uri, last_uri,
} &last_iter, &select_path);
g_object_unref (root); g_object_unref (root);
g_object_unref (mount); g_object_unref (mount);
g_object_unref (icon); g_object_unref (icon);
...@@ -446,9 +481,9 @@ update_places (NautilusPlacesSidebar *sidebar) ...@@ -446,9 +481,9 @@ update_places (NautilusPlacesSidebar *sidebar)
last_iter = add_place (sidebar, PLACES_MOUNTED_VOLUME, last_iter = add_place (sidebar, PLACES_MOUNTED_VOLUME,
name, icon, mount_uri, name, icon, mount_uri,
NULL, volume, mount, 0, tooltip); NULL, volume, mount, 0, tooltip);
if (eel_strcmp (location, mount_uri) == 0) { compare_for_selection (sidebar,
gtk_tree_selection_select_iter (selection, &last_iter); location, mount_uri, last_uri,
} &last_iter, &select_path);
g_object_unref (mount); g_object_unref (mount);
g_object_unref (icon); g_object_unref (icon);
g_free (name); g_free (name);
...@@ -490,9 +525,9 @@ update_places (NautilusPlacesSidebar *sidebar) ...@@ -490,9 +525,9 @@ update_places (NautilusPlacesSidebar *sidebar)
last_iter = add_place (sidebar, PLACES_MOUNTED_VOLUME, last_iter = add_place (sidebar, PLACES_MOUNTED_VOLUME,
name, icon, mount_uri, name, icon, mount_uri,
NULL, NULL, mount, 0, tooltip); NULL, NULL, mount, 0, tooltip);
if (eel_strcmp (location, mount_uri) == 0) { compare_for_selection (sidebar,
gtk_tree_selection_select_iter (selection, &last_iter); location, mount_uri, last_uri,
} &last_iter, &select_path);
g_object_unref (root); g_object_unref (root);
g_object_unref (mount); g_object_unref (mount);
g_object_unref (icon); g_object_unref (icon);
...@@ -508,9 +543,9 @@ update_places (NautilusPlacesSidebar *sidebar) ...@@ -508,9 +543,9 @@ update_places (NautilusPlacesSidebar *sidebar)
_("Trash"), icon, mount_uri, _("Trash"), icon, mount_uri,
NULL, NULL, NULL, 0, NULL, NULL, NULL, 0,
_("Open the trash")); _("Open the trash"));
if (eel_strcmp (location, mount_uri) == 0) { compare_for_selection (sidebar,
gtk_tree_selection_select_iter (selection, &last_iter); location, mount_uri, last_uri,
} &last_iter, &select_path);
g_object_unref (icon); g_object_unref (icon);
/* add separator */ /* add separator */
...@@ -539,9 +574,9 @@ update_places (NautilusPlacesSidebar *sidebar) ...@@ -539,9 +574,9 @@ update_places (NautilusPlacesSidebar *sidebar)
name, icon, mount_uri, name, icon, mount_uri,
NULL, NULL, NULL, index, NULL, NULL, NULL, index,
tooltip); tooltip);
if (eel_strcmp (location, mount_uri) == 0) { compare_for_selection (sidebar,
gtk_tree_selection_select_iter (selection, &last_iter); location, mount_uri, last_uri,
} &last_iter, &select_path);
g_free (name); g_free (name);
g_object_unref (root); g_object_unref (root);
g_object_unref (icon); g_object_unref (icon);
...@@ -549,6 +584,16 @@ update_places (NautilusPlacesSidebar *sidebar) ...@@ -549,6 +584,16 @@ update_places (NautilusPlacesSidebar *sidebar)
g_free (tooltip); g_free (tooltip);
} }
g_free (location); g_free (location);
if (select_path != NULL) {
gtk_tree_selection_select_path (selection, select_path);
}
if (select_path != NULL) {
gtk_tree_path_free (select_path);
}
g_free (last_uri);
} }
static gboolean static gboolean
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment