[gtk+] file-chooser: add a sort-directories-first gsetting



commit a34702a61f16d8d171d21ca1490cb8b9e504519c
Author: William Jon McCann <william jon mccann gmail com>
Date:   Tue Dec 3 12:10:29 2013 -0500

    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.

 gtk/gtkfilechooserdefault.c                  |    6 +++++-
 gtk/gtkfilechooserprivate.h                  |    1 +
 gtk/org.gtk.Settings.FileChooser.gschema.xml |    5 +++++
 3 files changed, 11 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c
index e573534..6ec75a2 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 58bfc9d..e7b7053 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 f2424e5..586881a 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>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]