File chooser recent-files (was: Re: Guidelines for stable branch changes in GLib/Gtk)

On Sun, 2012-11-11 at 15:24 -0500, Ryan Lortie wrote:

> 3) The file chooser "recent folder" changes that landed in 3.0 and also 
> on 2.x.
> I consider the last case to be particularly egregious because nothing 
> was broken to start with and the changes were highly visible from a UI 
> standpoint.  As I understand it, GNOME enters UI freeze at a particular 
> point in time and never leaves it (on a given stable release).  We can 
> argue that Gtk is not GNOME, of course...

Mea culpa.

In retrospect, I completely agree with you:  the changes to make the
file chooser start up in recently-used mode when no starting folder is
specified, should have gone into master only, not in the stable

I think I got the wrong impression of just how bad the previous
situation was:  apps didn't suggest a default folder and they came up in
$HOME (because $CWD tends to be just $HOME if users launch apps from the
desktop shell); apps sometimes suggested a default folder, sometimes
saved from their last instance, sometimes not...  I thought it was
pretty inconsistent, and wanted to make that situation better.

But yes, it was a big change, and it should not have gone into the
stable branches.

(The file chooser is a bit peculiar; I've wanted to keep it as much in
sync as possible between GTK+ 2.24 and GTK+ 3.x, because Big Important
Apps(tm) still use 2.24.  I didn't want a situation where the main apps
use a shitty file chooser and "only" small/new Gnome utilities use the
improved file chooser.)

In [1] I wrote a detailed reasoning for starting up in recently-used
mode.  I still think that reasoning is correct.  However, you and other
people clearly don't like the resulting behavior.

Still, I've had even other people tell me that they like the new

At the risk of introducing another preference in the file chooser, I
want to make an experiment.

The attached patch, for gtk+ master, lets you select whether to use the
current behavior (recently-used at startup unless a folder is pre-set),
the original behavior ($CWD unless a folder is pre-set), or something
that didn't really ever reach a stable version (save the last directory
you used and use it in the next invocation of a file chooser).

The way this is set is by reusing the old
~/.config/gtk-2.0/gtkfilechooser.ini file - you create a DefaultFolder
key and it can have the values "cwd", "last", or "recent".  The reason
I'm using *that* configuration file is that:

1. If we want to play with this patch on big apps that still use GTK+
2.24, they'll need to store the configuration there anyway.

2. I don't want 2.x apps and 3.x apps behaving differently.

3. Although the code to save the last-used-dir uses GSettings in GTK+
3.x, it used to use gtkfilechooser.ini in 2.24 - and if we actually keep
that code in the end, I intend to move the last-used-dir to the .ini
file so it is kept in sync.

I really hope you and other people who don't like recently-used by
default get to try this patch.  I honestly don't know what the best
behavior is; maybe the best is to let people who know about filesystems
to use $cwd or whatever, and for people who are not as comfortable to be
presented with a recently-used list.



>From dc52c6d45d05841b916c61c454666fd99cc52372 Mon Sep 17 00:00:00 2001
From: Federico Mena Quintero <federico gnome org>
Date: Fri, 16 Nov 2012 11:56:46 -0600
Subject: [PATCH] Allow choosing whether to open in recently-used mode,
 last-used-folder mode, or

This works by having a GKeyFile, in ~/.config/gtk-2.0/gtkfilechooser.ini and reading this:

[Filechooser Settings]

That is, the DefaultFolder key can have values of 'cwd', 'last', and 'recent'.  The default, if
the key is not set, is 'recent' - this will bring up the recently-used mode as usual.
The 'cwd' mode will use  instead, and 'last' will restore the folder that was used
in the last instance of the file chooser in any application.

We use that config file in ~/.config/gtk-2.0, not in gtk-3.0, so that it *is* the same config
file as used in GTK2 applications.

Signed-off-by: Federico Mena Quintero <federico gnome org>
 gtk/gtkfilechooserdefault.c |   86 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 85 insertions(+), 1 deletion(-)

diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c
index 09d6303..26a014a 100644
--- a/gtk/gtkfilechooserdefault.c
+++ b/gtk/gtkfilechooserdefault.c
@@ -6152,6 +6152,90 @@ get_file_for_last_folder_opened (GtkFileChooserDefault *impl)
   return file;
+typedef enum {
+} DefaultFolder;
+static DefaultFolder
+get_default_folder (void)
+  GKeyFile *keyfile;
+  char *filename;
+  DefaultFolder folder;
+  /* Note that this is really "gtk-2.0" so that we can share the configuration
+   * with GTK2, for old applications.
+   */
+  filename = g_build_filename (g_get_user_config_dir (), "gtk-2.0", "gtkfilechooser.ini", NULL);
+  keyfile = g_key_file_new ();
+  if (g_key_file_load_from_file (keyfile,
+				 filename,
+				 NULL)) /* NULL-GError */
+    {
+      char *value;
+      value = g_key_file_get_string (keyfile,
+				     "Filechooser Settings",
+				     "DefaultFolder",
+				     NULL); /* NULL-GError */
+      if (value)
+	{
+	  if (strcmp (value, "cwd") == 0)
+	    folder = DEFAULT_FOLDER_CWD;
+	  else if (strcmp (value, "last") == 0)
+	    folder = DEFAULT_FOLDER_LAST;
+	  else if (strcmp (value, "recent") == 0)
+	}
+    }
+  g_free (filename);
+  g_key_file_unref (keyfile);
+  return folder;
+static void
+restore_cwd (GtkFileChooserDefault *impl)
+  char *current_working_dir;
+  current_working_dir = g_get_current_dir ();
+  gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (impl), current_working_dir);
+  g_free (current_working_dir);
+static void
+restore_last_folder (GtkFileChooserDefault *impl)
+  GFile *folder;
+  folder = get_file_for_last_folder_opened (impl);
+  gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (impl), folder, NULL);
+  g_object_unref (folder);
+static void
+set_default_folder (GtkFileChooserDefault *impl)
+  DefaultFolder default_folder;
+  default_folder = get_default_folder ();
+  if (default_folder == DEFAULT_FOLDER_CWD)
+    restore_cwd (impl);
+  else if (default_folder == DEFAULT_FOLDER_LAST)
+    restore_last_folder (impl);
+  else /* default, and also default_folder == DEFAULT_FOLDER_RECENT */
+    recent_shortcut_handler (impl);
 /* GtkWidget::map method */
 static void
 gtk_file_chooser_default_map (GtkWidget *widget)
@@ -6169,7 +6253,7 @@ gtk_file_chooser_default_map (GtkWidget *widget)
       switch (impl->reload_state)
         case RELOAD_EMPTY:
-	  recent_shortcut_handler (impl);
+	  set_default_folder (impl);
         case RELOAD_HAS_FOLDER:

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]