GNOME Bugzilla – Bug 644426
GNOME-wide default to remember last folder
Last modified: 2011-04-15 20:17:29 UTC
It should be a default for applications using GTK file-chooser to remember the folder most recently used for saving or loading with each application. Right now, this behavior depends on each individual application. However, the majority of GTK based applications ignore this. Considering that you will very often open many files from one specific folder, the current behavior of file-chooser is very cumbersome because you have to navigate to that folder again and again each time. When this first occurred to me, I assumed my config or my distro's options were broken, but I found out this is how file-chooser works right now. IMO, this feature is a standard of usability in modern graphical environments. Relying on each individual developer to implement this remembering behavior is not enough here. So I think there should be an option that saves the last folder of each application, and default to show that one the next time you select a file. This default behavior can be overridden by an application that uses its own file-choosing settings so as not to break existing app's behaviors with the general default i'm proposing. (For example, uses several file-chooser behaviors (e.g. one for documents and one for profiles/preferences etc.))
Yes, this is a good idea. I'll gladly review a patch to implement this. Basically, you need to look at gtk+/gtk/gtkfilechooserdefault.[ch] and the settings_save() and settings_load() functions inside it. That's where you need to save the last working directory of the filechooser. To load the directory, look at gtk_file_chooser_default_map() where it handles the RELOAD_EMPTY case. That's where it loads $(cwd) right now; you'd want it to use the saved directory instead.
Created attachment 185888 [details] [review] Make GtkFileChooser remember last directory Attaching my (first) patch (ever) to fix this issue. It adds a "last-folder" GSettings key that remember the last path opened, defaulting to the home folder the first time you fire up a GtkFileChooser on your system. For the moment, "home" is put in the GSettings key the first time, but it would be nice to have directly the home path (from autotools I guess), so we can avoid the check for "home" every time the chooser is fired up.
+ last_dir = g_settings_get_string (impl->settings, + SETTINGS_KEY_LAST_FOLDER); + if (g_strcmp0 (last_dir, "")) { + last_dir = g_get_home_dir (); + } g_strcmp0 is overkill here. last_dir will always be != NULL, so you can just test last_dir[0] == '\0'. + g_settings_set_string (impl->settings, SETTINGS_KEY_LAST_FOLDER, + g_file_get_path (impl->current_folder)); [etc.] This is wrong, since you declared the setting with type "s". Paths are not UTF-8. You need either to use "ay", or, preferably, keep "s" but store URIs (using gtk_file_chooser_{get,set}_current_folder_uri).
Created attachment 185889 [details] [review] Make GtkFileChooser remember last directory Sorry for not reviewing my own patch correctly: this one fixes a wrong comment, strcmp==0, and make sure we always check if the "last-folder" is empty. Correcting previous comment, the key is not set to "home" by default, it's set to an empty string.
Created attachment 185922 [details] [review] Make GtkFileChoser remember the last directory opened This new patch makes uses of URIs, and create the get_last_directory_opened() function to avoid repetition.
Created attachment 185975 [details] [review] Make GtkFileChoser remember the last directory opened Introduces a 'last-folder-uri' GSettings key, where we remember the last-opened folder from the previous instance of the file chooser. The idea is that this works globally, across all applications, so it will be easy to do things like 1. Save an attachment from a mail (or some other file) 2. Open another program 3. Do File/Open and automatically get sent to the folder where (1) happened. Signed-off-by: Federico Mena Quintero <federico@gnome.org>
Pushed to master. Thanks, Stéphane, for all your work on this!