[gtk+/bgo658280-filechooser-recently-used: 1/3] Allow choosing whether to open in recently-used mode, last-used-folder mode, or
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/bgo658280-filechooser-recently-used: 1/3] Allow choosing whether to open in recently-used mode, last-used-folder mode, or
- Date: Sat, 17 Nov 2012 00:18:06 +0000 (UTC)
commit dc52c6d45d05841b916c61c454666fd99cc52372
Author: Federico Mena Quintero <federico gnome org>
Date: Fri Nov 16 11:56:46 2012 -0600
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]
DefaultFolder=cwd|last|recent
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 files changed, 85 insertions(+), 1 deletions(-)
---
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 {
+ DEFAULT_FOLDER_CWD,
+ DEFAULT_FOLDER_LAST,
+ DEFAULT_FOLDER_RECENT
+} DefaultFolder;
+
+static DefaultFolder
+get_default_folder (void)
+{
+ GKeyFile *keyfile;
+ char *filename;
+ DefaultFolder folder;
+
+ folder = DEFAULT_FOLDER_RECENT;
+
+ /* 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,
+ G_KEY_FILE_NONE,
+ 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)
+ folder = DEFAULT_FOLDER_RECENT;
+ }
+ }
+
+ 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);
break;
case RELOAD_HAS_FOLDER:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]