summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Jon McCann <william.jon.mccann@gmail.com>2013-12-03 12:10:29 -0500
committerWilliam Jon McCann <william.jon.mccann@gmail.com>2013-12-03 12:12:54 -0500
commita34702a61f16d8d171d21ca1490cb8b9e504519c (patch)
treedd81f7b909c6738e776c25083d96d78280533218
parentd9ce2ba32fba659fb991432dde30e77ca73bd1f8 (diff)
downloadgtk+-a34702a61f16d8d171d21ca1490cb8b9e504519c.tar.gz
file-chooser: add a sort-directories-first gsetting
Add an option to sort folders before files in order to be more constistent with the file manager.
-rw-r--r--gtk/gtkfilechooserdefault.c6
-rw-r--r--gtk/gtkfilechooserprivate.h1
-rw-r--r--gtk/org.gtk.Settings.FileChooser.gschema.xml5
3 files changed, 11 insertions, 1 deletions
diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c
index e573534f08..6ec75a2fdf 100644
--- a/gtk/gtkfilechooserdefault.c
+++ b/gtk/gtkfilechooserdefault.c
@@ -300,6 +300,7 @@ typedef struct {
guint use_preview_label : 1;
guint select_multiple : 1;
guint show_hidden : 1;
+ guint sort_directories_first : 1;
guint do_overwrite_confirmation : 1;
guint list_sort_ascending : 1;
guint changing_folder : 1;
@@ -3196,6 +3197,7 @@ settings_load (GtkFileChooserDefault *impl)
LocationMode location_mode;
gboolean show_hidden;
gboolean show_size_column;
+ gboolean sort_directories_first;
gint sort_column;
GtkSortType sort_order;
StartupMode startup_mode;
@@ -3211,6 +3213,7 @@ settings_load (GtkFileChooserDefault *impl)
sort_order = g_settings_get_enum (settings, SETTINGS_KEY_SORT_ORDER);
sidebar_width = g_settings_get_int (settings, SETTINGS_KEY_SIDEBAR_WIDTH);
startup_mode = g_settings_get_enum (settings, SETTINGS_KEY_STARTUP_MODE);
+ sort_directories_first = g_settings_get_boolean (settings, SETTINGS_KEY_SORT_DIRECTORIES_FIRST);
location_mode_set (impl, location_mode, TRUE);
@@ -3222,6 +3225,7 @@ settings_load (GtkFileChooserDefault *impl)
priv->sort_column = sort_column;
priv->sort_order = sort_order;
priv->startup_mode = startup_mode;
+ priv->sort_directories_first = sort_directories_first;
/* We don't call set_sort_column() here as the models may not have been
* created yet. The individual functions that create and set the models will
@@ -3421,7 +3425,7 @@ gtk_file_chooser_default_unmap (GtkWidget *widget)
dir_a = g_value_get_boolean (_gtk_file_system_model_get_value (fs_model, a, MODEL_COL_IS_FOLDER)); \
dir_b = g_value_get_boolean (_gtk_file_system_model_get_value (fs_model, b, MODEL_COL_IS_FOLDER)); \
\
- if (dir_a != dir_b) \
+ if (priv->sort_directories_first && dir_a != dir_b) \
return priv->list_sort_ascending ? (dir_a ? -1 : 1) : (dir_a ? 1 : -1) /* Directories *always* go first */
/* Sort callback for the filename column */
diff --git a/gtk/gtkfilechooserprivate.h b/gtk/gtkfilechooserprivate.h
index 58bfc9dbc9..e7b7053693 100644
--- a/gtk/gtkfilechooserprivate.h
+++ b/gtk/gtkfilechooserprivate.h
@@ -44,6 +44,7 @@ G_BEGIN_DECLS
#define SETTINGS_KEY_WINDOW_SIZE "window-size"
#define SETTINGS_KEY_SIDEBAR_WIDTH "sidebar-width"
#define SETTINGS_KEY_STARTUP_MODE "startup-mode"
+#define SETTINGS_KEY_SORT_DIRECTORIES_FIRST "sort-directories-first"
#define GTK_FILE_CHOOSER_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GTK_TYPE_FILE_CHOOSER, GtkFileChooserIface))
diff --git a/gtk/org.gtk.Settings.FileChooser.gschema.xml b/gtk/org.gtk.Settings.FileChooser.gschema.xml
index f2424e5655..586881a681 100644
--- a/gtk/org.gtk.Settings.FileChooser.gschema.xml
+++ b/gtk/org.gtk.Settings.FileChooser.gschema.xml
@@ -50,6 +50,11 @@
<summary>Whether to show hidden files</summary>
<description>If set to true, then hidden files are shown by default. Hidden files are either dotfiles, listed in the folder's .hidden file or backup files ending with a tilde (~).</description>
</key>
+ <key type="b" name="sort-directories-first">
+ <default>false</default>
+ <summary>Whether to show folders first</summary>
+ <description>If set to true, then folders are shown prior to showing files in the icon and list views.</description>
+ </key>
<key name='expand-folders' type='b'>
<default>false</default>
</key>