[Bf-blender-cvs] [109cd4640b3] filebrowser_redesign: Support inverted sorting

Julian Eisel noreply at git.blender.org
Thu Jul 25 01:55:47 CEST 2019


Commit: 109cd4640b3d2fff0137fd4e488a7905b90e26b0
Author: Julian Eisel
Date:   Thu Jul 25 01:52:03 2019 +0200
Branches: filebrowser_redesign
https://developer.blender.org/rB109cd4640b3d2fff0137fd4e488a7905b90e26b0

Support inverted sorting

Adds a checkbox to the filter/display popup, to invert sorting. We do an
additional pass to reverse the listbase order, rather than modifying the
sort callbacks. That adds a overhead but guess it's not much of an
issue. The alternative would make return values a bit cryptic.

===================================================================

M	release/scripts/startup/bl_ui/space_filebrowser.py
M	source/blender/editors/space_file/filelist.c
M	source/blender/editors/space_file/filelist.h
M	source/blender/editors/space_file/filesel.c
M	source/blender/editors/space_file/space_file.c
M	source/blender/makesdna/DNA_space_types.h
M	source/blender/makesrna/intern/rna_space.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_filebrowser.py b/release/scripts/startup/bl_ui/space_filebrowser.py
index ab62fe1eb55..06cf6585683 100644
--- a/release/scripts/startup/bl_ui/space_filebrowser.py
+++ b/release/scripts/startup/bl_ui/space_filebrowser.py
@@ -40,6 +40,7 @@ class FILEBROWSER_HT_header(Header):
 
             layout.prop(params, "display_type", expand=True, text="")
             layout.prop(params, "sort_method", expand=True, text="")
+            layout.prop(params, "use_sort_invert")
             layout.prop(params, "show_hidden", text="", icon='FILE_HIDDEN')
 
             row = layout.row(align=True)
@@ -104,6 +105,7 @@ class FILEBROWSER_PT_filter(Panel):
 
         layout.label(text="Sort By:")
         layout.prop(params, "sort_method", expand=True, text="")
+        layout.prop(params, "use_sort_invert")
 
         layout.separator()
 
diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c
index 9004eaa7bf6..4c910c6f468 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -329,6 +329,7 @@ enum {
   FL_IS_PENDING = 1 << 2,
   FL_NEED_SORTING = 1 << 3,
   FL_NEED_FILTERING = 1 << 4,
+  FL_SORT_INVERT = 1 << 5,
 };
 
 #define SPECIAL_IMG_SIZE 48
@@ -571,16 +572,34 @@ void filelist_sort(struct FileList *filelist)
         break;
     }
 
+    /* We could avoid this extra reversal by letting callbacks check for inverted sorting. Would
+     * make return values a bit cryptic though, and it's not like reversal is that expensive. */
+    if (filelist->flags & FL_SORT_INVERT) {
+      FileListInternEntry *current_entry = BLI_pophead(&filelist->filelist_intern.entries);
+      FileListInternEntry *parent_entry = BLI_pophead(&filelist->filelist_intern.entries);
+
+      BLI_listbase_reverse(&filelist->filelist_intern.entries);
+      /* Reinsert '..' item at the top */
+      BLI_assert(FILENAME_IS_CURRENT(current_entry->relpath));
+      BLI_assert(FILENAME_IS_PARENT(parent_entry->relpath));
+      BLI_addhead(&filelist->filelist_intern.entries, parent_entry);
+      BLI_addhead(&filelist->filelist_intern.entries, current_entry);
+    }
+
     filelist_filter_clear(filelist);
     filelist->flags &= ~FL_NEED_SORTING;
   }
 }
 
-void filelist_setsorting(struct FileList *filelist, const short sort)
+void filelist_setsorting(struct FileList *filelist, const short sort, bool invert_sort)
 {
-  if (filelist->sort != sort) {
+  const bool was_invert_sort = filelist->flags & FL_SORT_INVERT;
+
+  if ((filelist->sort != sort) || (was_invert_sort != invert_sort)) {
     filelist->sort = sort;
     filelist->flags |= FL_NEED_SORTING;
+    filelist->flags = invert_sort ? (filelist->flags | FL_SORT_INVERT) :
+                                    (filelist->flags & ~FL_SORT_INVERT);
   }
 }
 
diff --git a/source/blender/editors/space_file/filelist.h b/source/blender/editors/space_file/filelist.h
index caf77246797..9af0b7d623f 100644
--- a/source/blender/editors/space_file/filelist.h
+++ b/source/blender/editors/space_file/filelist.h
@@ -55,7 +55,7 @@ void folderlist_pushdir(struct ListBase *folderlist, const char *dir);
 const char *folderlist_peeklastdir(struct ListBase *folderdist);
 int folderlist_clear_next(struct SpaceFile *sfile);
 
-void filelist_setsorting(struct FileList *filelist, const short sort);
+void filelist_setsorting(struct FileList *filelist, const short sort, bool invert_sort);
 void filelist_sort(struct FileList *filelist);
 
 void filelist_setfilter_options(struct FileList *filelist,
diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c
index a0dadcf4102..cfa662834f3 100644
--- a/source/blender/editors/space_file/filesel.c
+++ b/source/blender/editors/space_file/filesel.c
@@ -714,7 +714,7 @@ void ED_fileselect_init_layout(struct SpaceFile *sfile, ARegion *ar)
                (layout->tile_h + 2 * layout->tile_border_y);
     details_columns_init(params, layout);
 
-    if ((int)rowcount / numfiles >= 1) {
+    if (numfiles && (int)rowcount / numfiles >= 1) {
       layout->rows = rowcount;
     }
     else {
diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c
index 55f1fdab1ad..f7d83570b90 100644
--- a/source/blender/editors/space_file/space_file.c
+++ b/source/blender/editors/space_file/space_file.c
@@ -225,7 +225,7 @@ static void file_refresh(const bContext *C, ScrArea *sa)
   }
   filelist_setdir(sfile->files, params->dir);
   filelist_setrecursion(sfile->files, params->recursion_level);
-  filelist_setsorting(sfile->files, params->sort);
+  filelist_setsorting(sfile->files, params->sort, params->flag & FILE_SORT_INVERT);
   filelist_setfilter_options(sfile->files,
                              (params->flag & FILE_FILTER) != 0,
                              (params->flag & FILE_HIDE_DOT) != 0,
diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h
index 97965b1f313..5e780d06df0 100644
--- a/source/blender/makesdna/DNA_space_types.h
+++ b/source/blender/makesdna/DNA_space_types.h
@@ -788,6 +788,7 @@ typedef enum eFileSel_Params_Flag {
   FILE_FILTER = (1 << 8),
   FILE_PARAMS_FLAG_UNUSED_9 = (1 << 9), /* cleared */
   FILE_GROUP_INSTANCE = (1 << 10),
+  FILE_SORT_INVERT = (1 << 11)
 } eFileSel_Params_Flag;
 
 /* sfile->params->rename_flag */
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index 4ef4d6c3146..327158de50d 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -5336,6 +5336,12 @@ static void rna_def_fileselect_params(BlenderRNA *brna)
   RNA_def_property_ui_text(prop, "Sort", "");
   RNA_def_property_update(prop, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL);
 
+  prop = RNA_def_property(srna, "use_sort_invert", PROP_BOOLEAN, PROP_NONE);
+  RNA_def_property_boolean_sdna(prop, NULL, "flag", FILE_SORT_INVERT);
+  RNA_def_property_ui_text(
+      prop, "Sort Inverted", "Sort items descending, from highest value to lowest");
+  RNA_def_property_update(prop, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL);
+
   prop = RNA_def_property(srna, "use_filter_image", PROP_BOOLEAN, PROP_NONE);
   RNA_def_property_boolean_sdna(prop, NULL, "filter", FILE_TYPE_IMAGE);
   RNA_def_property_ui_text(prop, "Filter Images", "Show image files");



More information about the Bf-blender-cvs mailing list