GNOME Bugzilla – Bug 741870
When opening file, file chooser should default to the directory of a currently-opened file
Last modified: 2014-12-27 17:31:52 UTC
When I select Open, Builder creates a file chooser dialog that starts out by displaying my recently-opened files. I then have to click through several levels of directories in order to reach the file I want to open. I could speed this up a little by adding a bookmark to the sidebar using nautilus, but in a big project with lots of nested directories that doesn't help much unless I create tons of bookmarks; for example, if the file I want to open is in ~/WebKit/Source/WebKit2/UIProcess/API/gtk then I have to click through six levels of folders before I can click on the file. I don't like this very much. gedit takes a different approach: it uses gtk_file_chooser_set_current_folder() to show the directory of the file I'm currently editing when the file chooser is launched. From here, I can view recently-opened files with one click on the sidebar if need be, but I probably want to edit another file in the same directory, or in a nearby directory. This is much nicer. (Note that the documentation for GtkFileChooser explicitly recommends against what gedit is doing [1], but I think the documentation is wrong and silly: as a programmer, I don't want to open random recently-edited text files from other projects, I want to open files from the project I'm currently working on.) (Since Builder can display multiple files at once, a somewhat different heuristic would be needed to pick the directory to show.) [1] https://developer.gnome.org/gtk3/stable/GtkFileChooserDialog.html#gtkfilechooserdialog-setting-up
This sounds reasonable to me. There was no reason for it to be different, it's just how it got written in haste to have a way to open files.
Created attachment 293373 [details] [review] editor-workspace: memorize last directory When choosing a file to open, memorize the directory from where the last file was opened and open this directory instead of "Recent" one.
Thanks! Pushed this to master, with a small style fix and I switched dirname() to g_path_get_dirname() since dirname() has non-obvious side-effects.
I've also removed the libgen.h include, as it was not necessary anymore, and pushed to master. Thanks a lot!
Created attachment 293377 [details] [review] editor-workspace: use g_clear_pointer() Thanks Fabiano! I see one missed opportunity to use g_clear_pointer().