[nautilus/125-files-ignores-sort-folders-before-files-on-search] file: Handle "sorting-directories-first" specially in search



commit c75f268854465b39ecc866a77a6b7fcacb39c1a4
Author: António Fernandes <antoniojpfernandes gmail com>
Date:   Wed Nov 22 15:55:18 2017 +0000

    file: Handle "sorting-directories-first" specially in search
    
    We previously ignored this option when sorting search results, because
    we don't want files from the query location to sort under directories
    deeper in the hierarchy.
    
    However, as a side effect, this also prevented sorting directories from
    the query location first, which was not the main purpose, so this was
    reverted in the previous commit.
    
    Instead, make sure files from query location sort above deeper results,
    but otherwise let directories sort first if that option is enabled.
    
    Fixes #125

 src/nautilus-file.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
---
diff --git a/src/nautilus-file.c b/src/nautilus-file.c
index ad890a0bc..a058b854b 100644
--- a/src/nautilus-file.c
+++ b/src/nautilus-file.c
@@ -3856,6 +3856,23 @@ nautilus_file_compare_for_sort (NautilusFile         *file_1,
         return 0;
     }
 
+    if (directories_first && sort_type == NAUTILUS_FILE_SORT_BY_SEARCH_RELEVANCE)
+    {
+        gdouble r_1, r_2;
+
+        get_search_relevance (file_1, &r_1);
+        get_search_relevance (file_2, &r_2);
+
+        /* Make sure files from current directory are easy to find, even when 
+         * sorting directories first, by sorting them like this:
+         * 1- folders from current directory
+         * 2- files from current directory
+         * 3- folders from subdirectories
+         * 4- files from subdirectories
+         */
+        directories_first = ((r_1 >= 10000) == (r_2 >= 10000));
+    }
+
     result = nautilus_file_compare_for_sort_internal (file_1, file_2, directories_first, reversed);
 
     if (result == 0)


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