[gtk+/places-sidebar] Remove gtk_places_sidebar_set_show_cwd(), implement that in the file chooser
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/places-sidebar] Remove gtk_places_sidebar_set_show_cwd(), implement that in the file chooser
- Date: Tue, 11 Dec 2012 21:54:58 +0000 (UTC)
commit 42d239f6d5c97bd0c4a9a3e1359a48374dfd7ebe
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Dec 11 15:52:17 2012 -0600
Remove gtk_places_sidebar_set_show_cwd(), implement that in the file chooser
This removes more idiosyncratic API from the sidebar.
Signed-off-by: Federico Mena Quintero <federico gnome org>
gtk/gtkfilechooserdefault.c | 60 ++++++++++++++++++++++++++++++++++++++++++-
gtk/gtkplacessidebar.c | 59 +-----------------------------------------
gtk/gtkplacessidebar.h | 2 -
3 files changed, 60 insertions(+), 61 deletions(-)
---
diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c
index 330c591..776d7ba 100644
--- a/gtk/gtkfilechooserdefault.c
+++ b/gtk/gtkfilechooserdefault.c
@@ -1318,7 +1318,6 @@ 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, "open-location",
G_CALLBACK (places_sidebar_open_location_cb),
@@ -3804,6 +3803,63 @@ set_startup_mode (GtkFileChooserDefault *impl)
}
}
+static gboolean
+shortcut_exists (GtkFileChooserDefault *impl, GFile *needle)
+{
+ GSList *haystack;
+ GSList *l;
+ gboolean exists;
+
+ exists = FALSE;
+
+ haystack = gtk_places_sidebar_list_shortcuts (GTK_PLACES_SIDEBAR (impl->places_sidebar));
+ for (l = haystack; l; l = l->next)
+ {
+ GFile *hay;
+
+ hay = G_FILE (l->data);
+ if (g_file_equal (hay, needle))
+ {
+ exists = TRUE;
+ break;
+ }
+ }
+ g_slist_free_full (haystack, g_object_unref);
+
+ return exists;
+}
+
+static void
+add_cwd_to_sidebar_if_needed (GtkFileChooserDefault *impl)
+{
+ char *cwd;
+ GFile *cwd_file;
+ GFile *home_file;
+
+ cwd = g_get_current_dir ();
+ cwd_file = g_file_new_for_path (cwd);
+ g_free (cwd);
+
+ if (shortcut_exists (impl, cwd_file))
+ goto out;
+
+ home_file = g_file_new_for_path (g_get_home_dir ());
+
+ /* We only add an item for $CWD if it is different from $HOME. This way,
+ * applications which get launched from a shell in a terminal (by someone who
+ * knows what they are doing) will get an item for $CWD in the places sidebar,
+ * and "normal" applications launched from the desktop shell (whose $CWD is
+ * $HOME) won't get any extra clutter in the sidebar.
+ */
+ if (!g_file_equal (home_file, cwd_file))
+ gtk_places_sidebar_add_shortcut (GTK_PLACES_SIDEBAR (impl->places_sidebar), cwd_file);
+
+ g_object_unref (home_file);
+
+ out:
+ g_object_unref (cwd_file);
+}
+
/* GtkWidget::map method */
static void
gtk_file_chooser_default_map (GtkWidget *widget)
@@ -3818,6 +3874,8 @@ gtk_file_chooser_default_map (GtkWidget *widget)
settings_load (impl);
+ add_cwd_to_sidebar_if_needed (impl);
+
if (impl->operation_mode == OPERATION_MODE_BROWSE)
{
switch (impl->reload_state)
diff --git a/gtk/gtkplacessidebar.c b/gtk/gtkplacessidebar.c
index 12e3ee3..a59da60 100644
--- a/gtk/gtkplacessidebar.c
+++ b/gtk/gtkplacessidebar.c
@@ -139,7 +139,6 @@ struct _GtkPlacesSidebar {
guint show_properties : 1;
guint show_trash : 1;
guint trash_is_full : 1;
- guint show_cwd : 1;
guint accept_uri_drops : 1;
};
@@ -799,55 +798,8 @@ 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 */
+ home_uri = get_home_directory_uri ();
icon = g_themed_icon_new (ICON_NAME_HOME);
add_place (sidebar, PLACES_BUILT_IN,
SECTION_COMPUTER,
@@ -4061,15 +4013,6 @@ gtk_places_sidebar_set_trash_is_full (GtkPlacesSidebar *sidebar, gboolean is_ful
}
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);
-}
-
-void
gtk_places_sidebar_set_accept_uri_drops (GtkPlacesSidebar *sidebar, gboolean accept_uri_drops)
{
g_return_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar));
diff --git a/gtk/gtkplacessidebar.h b/gtk/gtkplacessidebar.h
index da847b2..11ad664 100644
--- a/gtk/gtkplacessidebar.h
+++ b/gtk/gtkplacessidebar.h
@@ -68,8 +68,6 @@ 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);
-
void gtk_places_sidebar_set_accept_uri_drops (GtkPlacesSidebar *sidebar, gboolean accept_uri_drops);
void gtk_places_sidebar_add_shortcut (GtkPlacesSidebar *sidebar, GFile *location);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]