From 78db92df7e2e33a081094a52e3c96d572670114e Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 3 Jul 2015 09:49:00 -0700 Subject: [PATCH] GtkPlacesSidebar: Allow hiding Trash We will use this in the filechooser in save mode. --- docs/reference/gtk/gtk3-sections.txt | 2 + gtk/gtkplacessidebar.c | 62 +++++++++++++++++++++++++++- gtk/gtkplacessidebar.h | 5 +++ 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt index 5df974531c..7b29c139f8 100644 --- a/docs/reference/gtk/gtk3-sections.txt +++ b/docs/reference/gtk/gtk3-sections.txt @@ -2654,6 +2654,8 @@ gtk_places_sidebar_get_local_only gtk_places_sidebar_set_local_only gtk_places_sidebar_get_show_enter_location gtk_places_sidebar_set_show_enter_location +gtk_places_sidebar_get_show_trash +gtk_places_sidebar_set_show_trash gtk_places_sidebar_set_drop_targets_visible GTK_PLACES_SIDEBAR diff --git a/gtk/gtkplacessidebar.c b/gtk/gtkplacessidebar.c index 860769b8f6..f833ea912e 100644 --- a/gtk/gtkplacessidebar.c +++ b/gtk/gtkplacessidebar.c @@ -158,6 +158,7 @@ struct _GtkPlacesSidebar { guint show_desktop : 1; guint show_connect_to_server : 1; guint show_enter_location : 1; + guint show_trash : 1; guint local_only : 1; }; @@ -207,6 +208,7 @@ enum { PROP_SHOW_DESKTOP, PROP_SHOW_CONNECT_TO_SERVER, PROP_SHOW_ENTER_LOCATION, + PROP_SHOW_TRASH, PROP_LOCAL_ONLY, NUM_PROPERTIES }; @@ -904,7 +906,7 @@ update_places (GtkPlacesSidebar *sidebar) } /* Trash */ - if (!sidebar->local_only) + if (!sidebar->local_only && sidebar->show_trash) { mount_uri = "trash:///"; /* No need to strdup */ icon = _gtk_trash_monitor_get_icon (sidebar->trash_monitor); @@ -3710,6 +3712,8 @@ gtk_places_sidebar_init (GtkPlacesSidebar *sidebar) sidebar->cancellable = g_cancellable_new (); + sidebar->show_trash = TRUE; + create_volume_monitor (sidebar); sidebar->open_flags = GTK_PLACES_OPEN_NORMAL; @@ -3848,6 +3852,10 @@ gtk_places_sidebar_set_property (GObject *obj, gtk_places_sidebar_set_show_enter_location (sidebar, g_value_get_boolean (value)); break; + case PROP_SHOW_TRASH: + gtk_places_sidebar_set_show_trash (sidebar, g_value_get_boolean (value)); + break; + case PROP_LOCAL_ONLY: gtk_places_sidebar_set_local_only (sidebar, g_value_get_boolean (value)); break; @@ -3892,6 +3900,10 @@ gtk_places_sidebar_get_property (GObject *obj, g_value_set_boolean (value, gtk_places_sidebar_get_show_enter_location (sidebar)); break; + case PROP_SHOW_TRASH: + g_value_set_boolean (value, gtk_places_sidebar_get_show_trash (sidebar)); + break; + case PROP_LOCAL_ONLY: g_value_set_boolean (value, gtk_places_sidebar_get_local_only (sidebar)); break; @@ -4236,6 +4248,12 @@ gtk_places_sidebar_class_init (GtkPlacesSidebarClass *class) P_("Whether the sidebar only includes local files"), FALSE, G_PARAM_READWRITE); + properties[PROP_SHOW_TRASH] = + g_param_spec_boolean ("show-trash", + P_("Show 'Trash'"), + P_("Whether the sidebar includes a builtin shortcut to the Trash location"), + TRUE, + G_PARAM_READWRITE); g_object_class_install_properties (gobject_class, NUM_PROPERTIES, properties); } @@ -4619,6 +4637,48 @@ gtk_places_sidebar_get_show_enter_location (GtkPlacesSidebar *sidebar) return sidebar->show_enter_location; } +/** + * gtk_places_sidebar_set_show_trash: + * @sidebar: a places sidebar + * @show_trash: whether to show an item for the Trash location + * + * Sets whether the @sidebar should show an item for the Trash location. + * + * Since: 3.18 + */ +void +gtk_places_sidebar_set_show_trash (GtkPlacesSidebar *sidebar, + gboolean show_trash) +{ + g_return_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar)); + + show_trash = !!show_trash; + if (sidebar->show_trash != show_trash) + { + sidebar->show_trash = show_trash; + update_places (sidebar); + g_object_notify_by_pspec (G_OBJECT (sidebar), properties[PROP_SHOW_TRASH]); + } +} + +/** + * gtk_places_sidebar_get_show_trash: + * @sidebar: a places sidebar + * + * Returns the value previously set with gtk_places_sidebar_set_show_trash() + * + * Returns: %TRUE if the sidebar will display a “Trash” item. + * + * Since: 3.18 + */ +gboolean +gtk_places_sidebar_get_show_trash (GtkPlacesSidebar *sidebar) +{ + g_return_val_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar), TRUE); + + return sidebar->show_trash; +} + /** * gtk_places_sidebar_set_local_only: * @sidebar: a places sidebar diff --git a/gtk/gtkplacessidebar.h b/gtk/gtkplacessidebar.h index 0cd481913b..a40c8c8909 100644 --- a/gtk/gtkplacessidebar.h +++ b/gtk/gtkplacessidebar.h @@ -141,6 +141,11 @@ GDK_AVAILABLE_IN_3_18 void gtk_places_sidebar_set_drop_targets_visible (GtkPlacesSidebar *sidebar, gboolean visible, GdkDragContext *context); +GDK_AVAILABLE_IN_3_18 +gboolean gtk_places_sidebar_get_show_trash (GtkPlacesSidebar *sidebar); +GDK_AVAILABLE_IN_3_18 +void gtk_places_sidebar_set_show_trash (GtkPlacesSidebar *sidebar, + gboolean show_trash); G_END_DECLS