[Bf-blender-cvs] [197653e0874] master: Fix selecting multiple files ignoring first file

Julian Eisel noreply at git.blender.org
Tue Sep 3 23:15:45 CEST 2019


Commit: 197653e08749b8fd3a5cbec212438df391b8b41c
Author: Julian Eisel
Date:   Tue Sep 3 23:05:32 2019 +0200
Branches: master
https://developer.blender.org/rB197653e08749b8fd3a5cbec212438df391b8b41c

Fix selecting multiple files ignoring first file

E.g. box selecting wouldn't allow selecting the first file.
Work selection and shift/ctrl selection had similar issues.

Code assumed that the first item was the '..' parent item and manually
removed it from the selection. I could just remove this special
handling, but instead I made the behavior more dynamic. So the file list
checks if the '..' item is there and only then applies special
treatment.
That way we can easily bring the '..' item back or make it optional if
wanted.

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

M	source/blender/editors/space_file/file_ops.c
M	source/blender/editors/space_file/filelist.c
M	source/blender/editors/space_file/filelist.h

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

diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index d738a20bf53..5168300d21e 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -450,7 +450,7 @@ static int file_box_select_exec(bContext *C, wmOperator *op)
 
   /* unselect '..' parent entry - it's not supposed to be selected if more than
    * one file is selected */
-  filelist_entry_select_index_set(sfile->files, 0, FILE_SEL_REMOVE, FILE_SEL_SELECTED, CHECK_ALL);
+  filelist_entry_parent_select_set(sfile->files, FILE_SEL_REMOVE, FILE_SEL_SELECTED, CHECK_ALL);
 
   if (FILE_SELECT_DIR == ret) {
     WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL);
@@ -518,8 +518,7 @@ static int file_select_invoke(bContext *C, wmOperator *op, const wmEvent *event)
   if (extend) {
     /* unselect '..' parent entry - it's not supposed to be selected if more
      * than one file is selected */
-    filelist_entry_select_index_set(
-        sfile->files, 0, FILE_SEL_REMOVE, FILE_SEL_SELECTED, CHECK_ALL);
+    filelist_entry_parent_select_set(sfile->files, FILE_SEL_REMOVE, FILE_SEL_SELECTED, CHECK_ALL);
   }
 
   if (FILE_SELECT_DIR == ret) {
@@ -618,7 +617,7 @@ static bool file_walk_select_selection_set(bContext *C,
     }
     /* select first file */
     else if (ELEM(direction, FILE_SELECT_WALK_DOWN, FILE_SELECT_WALK_RIGHT)) {
-      params->active_file = active = extend ? 1 : 0;
+      params->active_file = active = 0;
     }
     else {
       BLI_assert(0);
@@ -635,7 +634,7 @@ static bool file_walk_select_selection_set(bContext *C,
 
     /* unselect '..' parent entry - it's not supposed to be selected if more
      * than one file is selected */
-    filelist_entry_select_index_set(files, 0, FILE_SEL_REMOVE, FILE_SEL_SELECTED, CHECK_ALL);
+    filelist_entry_parent_select_set(files, FILE_SEL_REMOVE, FILE_SEL_SELECTED, CHECK_ALL);
   }
   else {
     /* deselect all first */
@@ -650,11 +649,6 @@ static bool file_walk_select_selection_set(bContext *C,
   if (fill) {
     FileSelection sel = {MIN2(active, last_sel), MAX2(active, last_sel)};
 
-    /* clamping selection to not include '..' parent entry */
-    if (sel.first == 0) {
-      sel.first = 1;
-    }
-
     /* fill selection between last and first selected file */
     filelist_entries_select_index_range_set(
         files, &sel, deselect ? FILE_SEL_REMOVE : FILE_SEL_ADD, FILE_SEL_SELECTED, CHECK_ALL);
@@ -662,6 +656,12 @@ static bool file_walk_select_selection_set(bContext *C,
     if (deselect) {
       filelist_entry_select_index_set(files, active, FILE_SEL_ADD, FILE_SEL_SELECTED, CHECK_ALL);
     }
+
+    /* unselect '..' parent entry - it's not supposed to be selected if more
+     * than one file is selected */
+    if ((sel.last - sel.first) > 1) {
+      filelist_entry_parent_select_set(files, FILE_SEL_REMOVE, FILE_SEL_SELECTED, CHECK_ALL);
+    }
   }
   else {
     filelist_entry_select_index_set(
@@ -732,7 +732,7 @@ static bool file_walk_select_do(bContext *C,
       BLI_assert(0);
     }
 
-    if (!IN_RANGE(active_new, 0, numfiles)) {
+    if (!IN_RANGE(active_new, -1, numfiles)) {
       if (extend) {
         /* extend to invalid file -> abort */
         return false;
diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c
index fdc101f3d82..46302e0d087 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -2299,6 +2299,19 @@ unsigned int filelist_entry_select_index_get(FileList *filelist,
   return 0;
 }
 
+/**
+ * Set selection of the '..' parent entry, but only if it's actually visible.
+ */
+void filelist_entry_parent_select_set(FileList *filelist,
+                                      FileSelType select,
+                                      unsigned int flag,
+                                      FileCheckType check)
+{
+  if ((filelist->filter_data.flags & FLF_HIDE_PARENT) == 0) {
+    filelist_entry_select_index_set(filelist, 0, select, flag, check);
+  }
+}
+
 /* WARNING! dir must be FILE_MAX_LIBEXTRA long! */
 bool filelist_islibrary(struct FileList *filelist, char *dir, char **group)
 {
diff --git a/source/blender/editors/space_file/filelist.h b/source/blender/editors/space_file/filelist.h
index 9af0b7d623f..9b1107294ff 100644
--- a/source/blender/editors/space_file/filelist.h
+++ b/source/blender/editors/space_file/filelist.h
@@ -117,6 +117,10 @@ unsigned int filelist_entry_select_get(struct FileList *filelist,
 unsigned int filelist_entry_select_index_get(struct FileList *filelist,
                                              const int index,
                                              FileCheckType check);
+void filelist_entry_parent_select_set(struct FileList *filelist,
+                                      FileSelType select,
+                                      unsigned int flag,
+                                      FileCheckType check);
 
 void filelist_setrecursion(struct FileList *filelist, const int recursion_level);



More information about the Bf-blender-cvs mailing list