[gtk+] places sidebar: Make 'recent' work on other platforms
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] places sidebar: Make 'recent' work on other platforms
- Date: Sat, 6 Jun 2015 21:16:39 +0000 (UTC)
commit a8191e7113672abbfdfe5d2f62c6eeddf730c9dd
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Jun 6 17:13:22 2015 -0400
places sidebar: Make 'recent' work on other platforms
Since nautilus merge, we were not showing 'Recent' in the sidebar
if GIO did not support the recent: scheme. But the file chooser
can show recent files independent of gvfs - it loads the recent
files manually. This is relevant on Windows and OS X, where gvfs
is typically not used.
This commit adds a show-recent property which can be used to override
the recent: scheme check. We use it in the file chooser.
https://bugzilla.gnome.org/show_bug.cgi?id=750068
docs/reference/gtk/gtk3-sections.txt | 2 +
gtk/gtkfilechooserwidget.c | 20 +---------
gtk/gtkplacessidebar.c | 68 +++++++++++++++++++++++++++++++++-
gtk/gtkplacessidebar.h | 6 +++
gtk/ui/gtkfilechooserwidget.ui | 1 +
5 files changed, 77 insertions(+), 20 deletions(-)
---
diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt
index 4cd12c1..6491778 100644
--- a/docs/reference/gtk/gtk3-sections.txt
+++ b/docs/reference/gtk/gtk3-sections.txt
@@ -2638,6 +2638,8 @@ gtk_places_sidebar_set_open_flags
gtk_places_sidebar_get_open_flags
gtk_places_sidebar_set_location
gtk_places_sidebar_get_location
+gtk_places_sidebar_set_show_recent
+gtk_places_sidebar_get_show_recent
gtk_places_sidebar_set_show_desktop
gtk_places_sidebar_get_show_desktop
gtk_places_sidebar_add_shortcut
diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c
index 22515da..232640c 100644
--- a/gtk/gtkfilechooserwidget.c
+++ b/gtk/gtkfilechooserwidget.c
@@ -3212,24 +3212,6 @@ recent_files_setting_is_enabled (GtkFileChooserWidget *impl)
return enabled;
}
-static gboolean
-recent_scheme_is_supported (void)
-{
- const gchar * const *supported;
-
- supported = g_vfs_get_supported_uri_schemes (g_vfs_get_default ());
- if (supported != NULL)
- return g_strv_contains (supported, "recent");
-
- return FALSE;
-}
-
-static gboolean
-can_show_recent (GtkFileChooserWidget *impl)
-{
- return recent_files_setting_is_enabled (impl) && recent_scheme_is_supported ();
-}
-
/* Sets the file chooser to showing Recent Files or $CWD, depending on the
* user’s settings.
*/
@@ -3241,7 +3223,7 @@ set_startup_mode (GtkFileChooserWidget *impl)
switch (priv->startup_mode)
{
case STARTUP_MODE_RECENT:
- if (can_show_recent (impl))
+ if (recent_files_setting_is_enabled (impl))
{
operation_mode_set (impl, OPERATION_MODE_RECENT);
break;
diff --git a/gtk/gtkplacessidebar.c b/gtk/gtkplacessidebar.c
index 31f8eb3..f767e14 100644
--- a/gtk/gtkplacessidebar.c
+++ b/gtk/gtkplacessidebar.c
@@ -175,6 +175,8 @@ struct _GtkPlacesSidebar {
guint mounting : 1;
guint drag_data_received : 1;
guint drop_occured : 1;
+ guint show_recent_set : 1;
+ guint show_recent : 1;
guint show_desktop_set : 1;
guint show_desktop : 1;
guint show_connect_to_server : 1;
@@ -260,6 +262,7 @@ enum {
enum {
PROP_LOCATION = 1,
PROP_OPEN_FLAGS,
+ PROP_SHOW_RECENT,
PROP_SHOW_DESKTOP,
PROP_SHOW_CONNECT_TO_SERVER,
PROP_SHOW_ENTER_LOCATION,
@@ -586,7 +589,9 @@ recent_scheme_is_supported (void)
static gboolean
should_show_recent (GtkPlacesSidebar *sidebar)
{
- return recent_files_setting_is_enabled (sidebar) && recent_scheme_is_supported ();
+ return recent_files_setting_is_enabled (sidebar) &&
+ ((sidebar->show_recent_set && sidebar->show_recent) ||
+ (!sidebar->show_recent_set && recent_scheme_is_supported ()));
}
static gboolean
@@ -4309,6 +4314,10 @@ gtk_places_sidebar_set_property (GObject *obj,
gtk_places_sidebar_set_open_flags (sidebar, g_value_get_flags (value));
break;
+ case PROP_SHOW_RECENT:
+ gtk_places_sidebar_set_show_recent (sidebar, g_value_get_boolean (value));
+ break;
+
case PROP_SHOW_DESKTOP:
gtk_places_sidebar_set_show_desktop (sidebar, g_value_get_boolean (value));
break;
@@ -4349,6 +4358,10 @@ gtk_places_sidebar_get_property (GObject *obj,
g_value_set_flags (value, gtk_places_sidebar_get_open_flags (sidebar));
break;
+ case PROP_SHOW_RECENT:
+ g_value_set_boolean (value, gtk_places_sidebar_get_show_recent (sidebar));
+ break;
+
case PROP_SHOW_DESKTOP:
g_value_set_boolean (value, gtk_places_sidebar_get_show_desktop (sidebar));
break;
@@ -4690,6 +4703,12 @@ gtk_places_sidebar_class_init (GtkPlacesSidebarClass *class)
GTK_TYPE_PLACES_OPEN_FLAGS,
GTK_PLACES_OPEN_NORMAL,
G_PARAM_READWRITE);
+ properties[PROP_SHOW_RECENT] =
+ g_param_spec_boolean ("show-recent",
+ P_("Show recent files"),
+ P_("Whether the sidebar includes a builtin shortcut for recent files"),
+ TRUE,
+ G_PARAM_READWRITE);
properties[PROP_SHOW_DESKTOP] =
g_param_spec_boolean ("show-desktop",
P_("Show 'Desktop'"),
@@ -4981,6 +5000,53 @@ gtk_places_sidebar_get_location (GtkPlacesSidebar *sidebar)
}
/**
+ * gtk_places_sidebar_set_show_recent:
+ * @sidebar: a places sidebar
+ * @show_recent: whether to show an item for recent files
+ *
+ * Sets whether the @sidebar should show an item for recent files.
+ * The default value for this option is determined by the desktop
+ * environment, but this function can be used to override it on a
+ * per-application basis.
+ *
+ * Since: 3.18
+ */
+void
+gtk_places_sidebar_set_show_recent (GtkPlacesSidebar *sidebar,
+ gboolean show_recent)
+{
+ g_return_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar));
+
+ sidebar->show_recent_set = TRUE;
+
+ show_recent = !!show_recent;
+ if (sidebar->show_recent != show_recent)
+ {
+ sidebar->show_recent = show_recent;
+ update_places (sidebar);
+ g_object_notify_by_pspec (G_OBJECT (sidebar), properties[PROP_SHOW_RECENT]);
+ }
+}
+
+/**
+ * gtk_places_sidebar_get_show_recent:
+ * @sidebar: a places sidebar
+ *
+ * Returns the value previously set with gtk_places_sidebar_set_show_recent()
+ *
+ * Returns: %TRUE if the sidebar will display a builtin shortcut for recent files
+ *
+ * Since: 3.18
+ */
+gboolean
+gtk_places_sidebar_get_show_recent (GtkPlacesSidebar *sidebar)
+{
+ g_return_val_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar), FALSE);
+
+ return sidebar->show_recent;
+}
+
+/**
* gtk_places_sidebar_set_show_desktop:
* @sidebar: a places sidebar
* @show_desktop: whether to show an item for the Desktop folder
diff --git a/gtk/gtkplacessidebar.h b/gtk/gtkplacessidebar.h
index f703cf8..2546db4 100644
--- a/gtk/gtkplacessidebar.h
+++ b/gtk/gtkplacessidebar.h
@@ -95,6 +95,12 @@ GDK_AVAILABLE_IN_3_10
void gtk_places_sidebar_set_location (GtkPlacesSidebar *sidebar,
GFile *location);
+GDK_AVAILABLE_IN_3_18
+gboolean gtk_places_sidebar_get_show_recent (GtkPlacesSidebar *sidebar);
+GDK_AVAILABLE_IN_3_18
+void gtk_places_sidebar_set_show_recent (GtkPlacesSidebar *sidebar,
+ gboolean show_recent);
+
GDK_AVAILABLE_IN_3_10
gboolean gtk_places_sidebar_get_show_desktop (GtkPlacesSidebar *sidebar);
GDK_AVAILABLE_IN_3_10
diff --git a/gtk/ui/gtkfilechooserwidget.ui b/gtk/ui/gtkfilechooserwidget.ui
index 00349fb..9af256a 100644
--- a/gtk/ui/gtkfilechooserwidget.ui
+++ b/gtk/ui/gtkfilechooserwidget.ui
@@ -19,6 +19,7 @@
<property name="hscrollbar_policy">never</property>
<property name="local_only">True</property>
<property name="show_enter_location">True</property>
+ <property name="show_recent">True</property>
<style>
<class name="sidebar"/>
</style>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]