GtkPlacesSidebar: Allow hiding Trash
authorMatthias Clasen <mclasen@redhat.com>
Fri, 3 Jul 2015 16:49:00 +0000 (09:49 -0700)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 4 Jul 2015 04:29:26 +0000 (00:29 -0400)
We will use this in the filechooser in save mode.

docs/reference/gtk/gtk3-sections.txt
gtk/gtkplacessidebar.c
gtk/gtkplacessidebar.h

index 5df974531cd66dd463f1616289d918b64159720d..7b29c139f80611637941cb6742341a64c24a70da 100644 (file)
@@ -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
 <SUBSECTION Standard>
 GTK_PLACES_SIDEBAR
index 860769b8f6f24feaf3897adc7bd75c1838cd8d77..f833ea912ee99eb54d8c0c7d03bf14ec6f7c9a4f 100644 (file)
@@ -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
index 0cd481913bcd7a068b6a14afe15f6fd8d42cad49..a40c8c8909c64e03e35782f0db057af5f8b21861 100644 (file)
@@ -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