After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 644426 - GNOME-wide default to remember last folder
GNOME-wide default to remember last folder
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: GtkFileChooser
3.0.x
Other All
: Normal enhancement
: ---
Assigned To: gtk-bugs
Federico Mena Quintero
Depends on:
Blocks:
 
 
Reported: 2011-03-10 19:01 UTC by Wolf-Jakob Gratz
Modified: 2011-04-15 20:17 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Make GtkFileChooser remember last directory (6.28 KB, patch)
2011-04-13 16:16 UTC, Stéphane Maniaci
none Details | Review
Make GtkFileChooser remember last directory (6.41 KB, patch)
2011-04-13 16:39 UTC, Stéphane Maniaci
none Details | Review
Make GtkFileChoser remember the last directory opened (6.98 KB, patch)
2011-04-14 02:42 UTC, Stéphane Maniaci
none Details | Review
Make GtkFileChoser remember the last directory opened (5.53 KB, patch)
2011-04-14 18:57 UTC, Federico Mena Quintero
none Details | Review

Description Wolf-Jakob Gratz 2011-03-10 19:01:13 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.))
Comment 1 Federico Mena Quintero 2011-03-10 23:18:22 UTC
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.
Comment 2 Stéphane Maniaci 2011-04-13 16:16:21 UTC
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.
Comment 3 Christian Persch 2011-04-13 16:31:14 UTC
+	  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).
Comment 4 Stéphane Maniaci 2011-04-13 16:39:26 UTC
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.
Comment 5 Stéphane Maniaci 2011-04-14 02:42:41 UTC
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.
Comment 6 Federico Mena Quintero 2011-04-14 18:57:41 UTC
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>
Comment 7 Federico Mena Quintero 2011-04-15 20:17:29 UTC
Pushed to master.  Thanks, Stéphane, for all your work on this!