[Bf-blender-cvs] [2205950] master: File Browser: Ensure active file is unset if no file is selected

Julian Eisel noreply at git.blender.org
Fri Jun 12 04:47:21 CEST 2015


Commit: 220595027498b8e55c071b2388ac3be2859b94af
Author: Julian Eisel
Date:   Fri Jun 12 04:42:31 2015 +0200
Branches: master
https://developer.blender.org/rB220595027498b8e55c071b2388ac3be2859b94af

File Browser: Ensure active file is unset if no file is selected

Otherwise arrow keys navigation might start from this file instead of
the last/first file in the list.

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

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

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

diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index fcb8400..4889b77 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -215,6 +215,23 @@ static FileSelect file_select_do(bContext *C, int selected_idx, bool do_diropen)
 	return retval;
 }
 
+/**
+ * \warning: loops over all files so better use cautiously
+ */
+static bool file_is_any_selected(struct FileList *files)
+{
+	const int numfiles = filelist_numfiles(files);
+	int i;
+
+	for (i = 0; i < numfiles; ++i) {
+		if (filelist_is_selected(files, i, CHECK_ALL)) {
+			return true;
+		}
+	}
+
+	return false;
+}
+
 
 static FileSelect file_select(bContext *C, const rcti *rect, FileSelType select, bool fill, bool do_diropen)
 {
@@ -230,36 +247,23 @@ static FileSelect file_select(bContext *C, const rcti *rect, FileSelType select,
 	if (sel.first != sel.last) select = 0;
 
 	/* Do we have a valid selection and are we actually selecting */
-	if ((sel.last >= 0) && ((select == FILE_SEL_ADD) || (select == FILE_SEL_TOGGLE))) {
+	if ((sel.last >= 0) && (select != FILE_SEL_REMOVE)) {
 		/* Check last selection, if selected, act on the file or dir */
 		if (filelist_is_selected(sfile->files, sel.last, check_type)) {
 			retval = file_select_do(C, sel.last, do_diropen);
 		}
 	}
 
+	if (select != FILE_SEL_ADD && !file_is_any_selected(sfile->files)) {
+		sfile->params->active_file = -1;
+	}
+
 	/* update operator for name change event */
 	file_draw_check(C);
 	
 	return retval;
 }
 
-/**
- * \warning: loops over all files so better use cautiously
- */
-static bool file_is_any_selected(struct FileList *files)
-{
-	const int numfiles = filelist_numfiles(files);
-	int i;
-
-	for (i = 0; i < numfiles; ++i) {
-		if (filelist_is_selected(files, i, CHECK_ALL)) {
-			return true;
-		}
-	}
-
-	return false;
-}
-
 static int file_border_select_find_last_selected(
         SpaceFile *sfile, ARegion *ar, const FileSelection *sel,
         const int mouse_xy[2])
@@ -680,6 +684,7 @@ static int file_select_all_exec(bContext *C, wmOperator *UNUSED(op))
 	/* select all only if previously no file was selected */
 	if (has_selection) {
 		filelist_select(sfile->files, &sel, FILE_SEL_REMOVE, FILE_SEL_SELECTED, CHECK_ALL);
+		sfile->params->active_file = -1;
 	}
 	else {
 		const FileCheckType check_type = (sfile->params->flag & FILE_DIRSEL_ONLY) ? CHECK_DIRS : CHECK_FILES;




More information about the Bf-blender-cvs mailing list