diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt index 4cd12c18c7..6491778363 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 22515da7f8..232640c11f 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 31f8eb3385..f767e14969 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'"), @@ -4980,6 +4999,53 @@ gtk_places_sidebar_get_location (GtkPlacesSidebar *sidebar) return file; } +/** + * 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 diff --git a/gtk/gtkplacessidebar.h b/gtk/gtkplacessidebar.h index f703cf8490..2546db4d5b 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 00349fb3d8..9af256a083 100644 --- a/gtk/ui/gtkfilechooserwidget.ui +++ b/gtk/ui/gtkfilechooserwidget.ui @@ -19,6 +19,7 @@ never True True + True