diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index 2b98846746..2d1923d77e 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -3787,6 +3787,7 @@ shortcuts_pane_create (GtkFileChooserDefault *impl, GtkSizeGroup *size_group) { impl->places_sidebar = gtk_places_sidebar_new (); + gtk_places_sidebar_set_show_cwd (GTK_PLACES_SIDEBAR (impl->places_sidebar), TRUE); g_signal_connect (impl->places_sidebar, "location-selected", G_CALLBACK (places_sidebar_location_selected_cb), diff --git a/gtk/gtkplacessidebar.c b/gtk/gtkplacessidebar.c index 3fb2cc2022..38320a8c83 100644 --- a/gtk/gtkplacessidebar.c +++ b/gtk/gtkplacessidebar.c @@ -120,6 +120,7 @@ struct _GtkPlacesSidebar { guint show_properties : 1; guint show_trash : 1; guint trash_is_full : 1; + guint show_cwd : 1; }; struct _GtkPlacesSidebarClass { @@ -653,6 +654,7 @@ update_places (GtkPlacesSidebar *sidebar) GSList *bookmarks, *sl; int index; char *location, *mount_uri, *name, *last_uri, *identifier; + char *home_uri; char *bookmark_name; GIcon *icon; GFile *root; @@ -702,16 +704,63 @@ update_places (GtkPlacesSidebar *sidebar) g_object_unref (icon); } + /* compute the $HOME URI here; we'll use it when we generate the $CWD item as well as the $HOME item */ + + home_uri = get_home_directory_uri (); + + /* cwd */ + if (sidebar->show_cwd) { + char *cwd; + GFile *home_file; + + cwd = g_get_current_dir (); + root = g_file_new_for_path (cwd); + g_free (cwd); + + home_file = g_file_new_for_uri (home_uri); + + if (!g_file_equal (home_file, root)) { + GFileInfo *info; + + info = g_file_query_info (root, + "standard::display-name,standard::icon", + G_FILE_QUERY_INFO_NONE, + NULL, + NULL); /* NULL-GError */ + + /* FIXME: we are getting file info synchronously. We may want to do it async at some point. */ + if (info) { + bookmark_name = g_strdup (g_file_info_get_display_name (info)); + icon = g_file_info_get_icon (info); /* FIXME: use symbolic icon */ + mount_uri = g_file_get_uri (root); + tooltip = g_file_get_parse_name (root); + + add_place (sidebar, PLACES_BUILT_IN, + SECTION_COMPUTER, + bookmark_name, icon, mount_uri, + NULL, NULL, NULL, 0, + tooltip); + + g_free (mount_uri); + g_free (tooltip); + g_free (bookmark_name); + + g_object_unref (info); + } + } + + g_object_unref (home_file); + } + /* home folder */ - mount_uri = get_home_directory_uri (); icon = g_themed_icon_new (ICON_NAME_HOME); add_place (sidebar, PLACES_BUILT_IN, SECTION_COMPUTER, _("Home"), icon, - mount_uri, NULL, NULL, NULL, 0, + home_uri, NULL, NULL, NULL, 0, _("Open your personal folder")); g_object_unref (icon); - g_free (mount_uri); + g_free (home_uri); if (sidebar->show_desktop) { /* desktop */ @@ -3909,3 +3958,12 @@ gtk_places_sidebar_set_trash_is_full (GtkPlacesSidebar *sidebar, gboolean is_ful update_places (sidebar); bookmarks_check_popup_sensitivity (sidebar); } + +void +gtk_places_sidebar_set_show_cwd (GtkPlacesSidebar *sidebar, gboolean show_cwd) +{ + g_return_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar)); + + sidebar->show_cwd = !!show_cwd; + update_places (sidebar); +} diff --git a/gtk/gtkplacessidebar.h b/gtk/gtkplacessidebar.h index 749399d72f..98bac73c7b 100644 --- a/gtk/gtkplacessidebar.h +++ b/gtk/gtkplacessidebar.h @@ -68,6 +68,8 @@ void gtk_places_sidebar_set_show_properties (GtkPlacesSidebar *sidebar, gboolean void gtk_places_sidebar_set_show_trash (GtkPlacesSidebar *sidebar, gboolean show_trash); void gtk_places_sidebar_set_trash_is_full (GtkPlacesSidebar *sidebar, gboolean is_full); +void gtk_places_sidebar_set_show_cwd (GtkPlacesSidebar *sidebar, gboolean show_cwd); + G_END_DECLS #endif /* __GTK_PLACES_SIDEBAR_H__ */