From ebb2977a54798d3253556126cf404b9f381bba58 Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Mon, 26 Nov 2012 18:05:18 -0600 Subject: [PATCH] New settings key for the startup mode Signed-off-by: Federico Mena Quintero --- gtk/gtkfilechooserdefault.c | 4 +++ gtk/gtkfilechooserprivate.h | 7 +++++ gtk/gtkfilechoosersettings.c | 55 ++++++++++++++++++++++++++++++++++++ gtk/gtkfilechoosersettings.h | 5 ++++ 4 files changed, 71 insertions(+) diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index a2dfc1e1e3..417f4e260b 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -3410,6 +3410,10 @@ shortcuts_build_popup_menu (GtkFileChooserDefault *impl) G_CALLBACK (rename_shortcut_cb), impl); gtk_widget_show (item); gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_shortcuts_popup_menu), item); + + item = gtk_separator_menu_item_new (); + gtk_widget_show (item); + gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_shortcuts_popup_menu), item); } static void diff --git a/gtk/gtkfilechooserprivate.h b/gtk/gtkfilechooserprivate.h index eb974273c1..6eb03b98bb 100644 --- a/gtk/gtkfilechooserprivate.h +++ b/gtk/gtkfilechooserprivate.h @@ -152,6 +152,11 @@ typedef enum { OPERATION_MODE_RECENT } OperationMode; +typedef enum { + STARTUP_MODE_RECENT, + STARTUP_MODE_CWD +} StartupMode; + struct _GtkFileChooserDefault { GtkVBox parent_instance; @@ -195,6 +200,8 @@ struct _GtkFileChooserDefault GtkFileSystemModel *browse_files_model; char *browse_files_last_selected_name; + StartupMode startup_mode; + /* OPERATION_MODE_SEARCH */ GtkWidget *search_hbox; GtkWidget *search_entry; diff --git a/gtk/gtkfilechoosersettings.c b/gtk/gtkfilechoosersettings.c index 8d5e4733fd..ac5e46207c 100644 --- a/gtk/gtkfilechoosersettings.c +++ b/gtk/gtkfilechoosersettings.c @@ -48,6 +48,7 @@ #define GEOMETRY_HEIGHT_KEY "GeometryHeight" #define SORT_COLUMN_KEY "SortColumn" #define SORT_ORDER_KEY "SortOrder" +#define STARTUP_MODE_KEY "StartupMode" #define COLUMN_NAME_STRING "name" #define COLUMN_MTIME_STRING "modified" @@ -55,6 +56,9 @@ #define SORT_ASCENDING_STRING "ascending" #define SORT_DESCENDING_STRING "descending" +#define STARTUP_MODE_RECENT_STRING "recent" +#define STARTUP_MODE_CWD_STRING "cwd" + #define MODE_PATH_BAR "path-bar" #define MODE_FILENAME_ENTRY "filename-entry" @@ -113,6 +117,7 @@ ensure_settings_read (GtkFileChooserSettings *settings) GKeyFile *key_file; gchar *location_mode_str, *filename; gchar *sort_column, *sort_order; + gchar *startup_mode; gboolean value; if (settings->settings_read) @@ -220,6 +225,23 @@ ensure_settings_read (GtkFileChooserSettings *settings) g_free (sort_order); } + /* Startup mode */ + + startup_mode = g_key_file_get_string (key_file, SETTINGS_GROUP, + STARTUP_MODE_KEY, NULL); + if (startup_mode) + { + if (EQ (STARTUP_MODE_RECENT_STRING, startup_mode)) + settings->startup_mode = STARTUP_MODE_RECENT; + else if (EQ (STARTUP_MODE_CWD_STRING, startup_mode)) + settings->startup_mode = STARTUP_MODE_CWD; + else + g_warning ("Unknown startup mode '%s' encountered in filechooser settings", + startup_mode); + + g_free (startup_mode); + } + out: g_key_file_free (key_file); @@ -248,6 +270,7 @@ _gtk_file_chooser_settings_init (GtkFileChooserSettings *settings) settings->geometry_y = -1; settings->geometry_width = -1; settings->geometry_height = -1; + settings->startup_mode = STARTUP_MODE_RECENT; } GtkFileChooserSettings * @@ -367,6 +390,20 @@ _gtk_file_chooser_settings_set_sort_order (GtkFileChooserSettings *settings, settings->sort_order = sort_order; } +void +_gtk_file_chooser_settings_set_startup_mode (GtkFileChooserSettings *settings, + StartupMode startup_mode) +{ + settings->startup_mode = startup_mode; +} + +StartupMode +_gtk_file_chooser_settings_get_startup_mode (GtkFileChooserSettings *settings) +{ + ensure_settings_read (settings); + return settings->startup_mode; +} + gboolean _gtk_file_chooser_settings_save (GtkFileChooserSettings *settings, GError **error) @@ -377,6 +414,7 @@ _gtk_file_chooser_settings_save (GtkFileChooserSettings *settings, gchar *contents; gchar *sort_column; gchar *sort_order; + gchar *startup_mode; gsize len; gboolean retval; GKeyFile *key_file; @@ -432,6 +470,21 @@ _gtk_file_chooser_settings_save (GtkFileChooserSettings *settings, sort_order = NULL; } + switch (settings->startup_mode) + { + case STARTUP_MODE_RECENT: + startup_mode = STARTUP_MODE_RECENT_STRING; + break; + + case STARTUP_MODE_CWD: + startup_mode = STARTUP_MODE_CWD_STRING; + break; + + default: + g_assert_not_reached (); + startup_mode = NULL; + } + key_file = g_key_file_new (); /* Initialise with the on-disk keyfile, so we keep unknown options */ @@ -457,6 +510,8 @@ _gtk_file_chooser_settings_save (GtkFileChooserSettings *settings, SORT_COLUMN_KEY, sort_column); g_key_file_set_string (key_file, SETTINGS_GROUP, SORT_ORDER_KEY, sort_order); + g_key_file_set_string (key_file, SETTINGS_GROUP, + STARTUP_MODE_KEY, startup_mode); contents = g_key_file_to_data (key_file, &len, error); g_key_file_free (key_file); diff --git a/gtk/gtkfilechoosersettings.h b/gtk/gtkfilechoosersettings.h index b7f6cd3c69..a846a221fd 100644 --- a/gtk/gtkfilechoosersettings.h +++ b/gtk/gtkfilechoosersettings.h @@ -50,6 +50,7 @@ struct _GtkFileChooserSettings GtkSortType sort_order; gint sort_column; + StartupMode startup_mode; int geometry_x; int geometry_y; @@ -104,6 +105,10 @@ void _gtk_file_chooser_settings_set_geometry (GtkFileChooserSettings *settings, int width, int heigth); +void _gtk_file_chooser_settings_set_startup_mode (GtkFileChooserSettings *settings, + StartupMode startup_mode); +StartupMode _gtk_file_chooser_settings_get_startup_mode (GtkFileChooserSettings *settings); + gboolean _gtk_file_chooser_settings_save (GtkFileChooserSettings *settings, GError **error);