Fix #417: Natural sort order
authorColin Clark <cclark@mcb.net>
Tue, 13 Dec 2016 20:12:06 +0000 (20:12 +0000)
committerColin Clark <cclark@mcb.net>
Tue, 13 Dec 2016 20:12:06 +0000 (20:12 +0000)
https://github.com/BestImageViewer/geeqie/issues/417
Refer also to commit bd34c324c92456f5182579d6922d7aba664f93c3

Include an option on the Files tab of Preferences to permit the
selection of either g_utf8_collate_key() or
g_utf8_collate_key_for_filename() for the sort order of files and
folders

doc/docbook/GuideOptionsFiltering.xml
src/filedata.c
src/options.c
src/options.h
src/preferences.c
src/rcfile.c

index 026e4be..371d8d5 100644 (file)
           </para>\r
         </listitem>\r
       </varlistentry>\r
+      <varlistentry>\r
+        <term>\r
+          <guilabel>Natural sort order</guilabel>\r
+        </term>\r
+        <listitem>\r
+          <para>Files and folders are sorted with the dot '.' treated as a special case, so the order is e.g. "event.c" "event.h" "eventgenerator.c". Also, files containing numbers are sorted as "file1" "file5" "file10".</para>\r
+        </listitem>\r
+      </varlistentry>\r
       <varlistentry>\r
         <term>\r
           <guilabel>Disable file extension checks</guilabel>\r
index ae1cadc..34b545a 100644 (file)
@@ -279,8 +279,21 @@ static void file_data_set_collate_keys(FileData *fd)
        g_free(fd->collate_key_name);
        g_free(fd->collate_key_name_nocase);
 
+#if GTK_CHECK_VERSION(2, 8, 0)
+       if (options->file_sort.natural)
+               {
+               fd->collate_key_name = g_utf8_collate_key_for_filename(fd->name, -1);
+               fd->collate_key_name_nocase = g_utf8_collate_key_for_filename(caseless_name, -1);
+               }
+       else
+               {
+               fd->collate_key_name = g_utf8_collate_key(valid_name, -1);
+               fd->collate_key_name_nocase = g_utf8_collate_key(caseless_name, -1);
+               }
+#else
        fd->collate_key_name = g_utf8_collate_key(valid_name, -1);
        fd->collate_key_name_nocase = g_utf8_collate_key(caseless_name, -1);
+#endif
 
        g_free(valid_name);
        g_free(caseless_name);
index f5ffb8e..c49396b 100644 (file)
@@ -69,6 +69,7 @@ ConfOptions *init_options(ConfOptions *options)
        options->file_sort.ascending = TRUE;
        options->file_sort.case_sensitive = FALSE;
        options->file_sort.method = SORT_NAME;
+       options->file_sort.natural = FALSE;
 
        options->fullscreen.above = FALSE;
        options->fullscreen.clean_flip = FALSE;
index 84a29d9..021b22a 100644 (file)
@@ -129,6 +129,7 @@ struct _ConfOptions
                SortType method;
                gboolean ascending;
                gboolean case_sensitive; /* file sorting method (case) */
+               gboolean natural;
        } file_sort;
 
        /* slideshow */
index 911b724..d7477ad 100644 (file)
@@ -216,6 +216,7 @@ static void config_window_apply(void)
        if (options->file_filter.show_parent_directory != c_options->file_filter.show_parent_directory) refresh = TRUE;
        if (options->file_filter.show_dot_directory != c_options->file_filter.show_dot_directory) refresh = TRUE;
        if (options->file_sort.case_sensitive != c_options->file_sort.case_sensitive) refresh = TRUE;
+       if (options->file_sort.natural != c_options->file_sort.natural) refresh = TRUE;
        if (options->file_filter.disable_file_extension_checks != c_options->file_filter.disable_file_extension_checks) refresh = TRUE;
        if (options->file_filter.disable != c_options->file_filter.disable) refresh = TRUE;
 
@@ -260,6 +261,7 @@ static void config_window_apply(void)
        options->file_filter.disable_file_extension_checks = c_options->file_filter.disable_file_extension_checks;
 
        options->file_sort.case_sensitive = c_options->file_sort.case_sensitive;
+       options->file_sort.natural = c_options->file_sort.natural;
        options->file_filter.disable = c_options->file_filter.disable;
 
        config_entry_to_option(sidecar_ext_entry, &options->sidecar.ext, NULL);
@@ -1704,6 +1706,8 @@ static void config_tab_files(GtkWidget *notebook)
                              options->file_filter.show_parent_directory, &c_options->file_filter.show_parent_directory);
        pref_checkbox_new_int(group, _("Case sensitive sort"),
                              options->file_sort.case_sensitive, &c_options->file_sort.case_sensitive);
+       pref_checkbox_new_int(group, _("Natural sort order"),
+                                         options->file_sort.natural, &c_options->file_sort.natural);
        pref_checkbox_new_int(group, _("Disable file extension checks"),
                              options->file_filter.disable_file_extension_checks, &c_options->file_filter.disable_file_extension_checks);
 
index ed61511..509e018 100644 (file)
@@ -353,6 +353,7 @@ static void write_global_attributes(GString *outstr, gint indent)
        WRITE_NL(); WRITE_INT(*options, file_sort.method);
        WRITE_NL(); WRITE_BOOL(*options, file_sort.ascending);
        WRITE_NL(); WRITE_BOOL(*options, file_sort.case_sensitive);
+       WRITE_NL(); WRITE_BOOL(*options, file_sort.natural);
 
        /* Fullscreen Options */
        WRITE_NL(); WRITE_INT(*options, fullscreen.screen);
@@ -623,6 +624,7 @@ static gboolean load_global_params(const gchar **attribute_names, const gchar **
                if (READ_UINT(*options, file_sort.method)) continue;
                if (READ_BOOL(*options, file_sort.ascending)) continue;
                if (READ_BOOL(*options, file_sort.case_sensitive)) continue;
+               if (READ_BOOL(*options, file_sort.natural)) continue;
 
                /* File operations *options */
                if (READ_BOOL(*options, file_ops.enable_in_place_rename)) continue;