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.
This commit is contained in:
Julian Eisel 2019-09-03 23:05:32 +02:00
parent 5ba0ce8544
commit 197653e087
3 changed files with 28 additions and 11 deletions

View File

@ -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;

View File

@ -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)
{

View File

@ -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);