[Bf-blender-cvs] [035d864] master: Fix: tab completing a filepath name in file browsers asks to create a new directory if name was not fully matched

Henrik Aarnio noreply at git.blender.org
Tue Nov 19 16:46:38 CET 2013


Commit: 035d86402bbb8dab2bfb086a3027e5ec93e52748
Author: Henrik Aarnio
Date:   Tue Nov 19 16:31:48 2013 +0100
http://developer.blender.org/rB035d86402bbb8dab2bfb086a3027e5ec93e52748

Fix: tab completing a filepath name in file browsers asks to create a new
directory if name was not fully matched

When hitting tab to complete a directory name in the filepath field in the
filebrowser Blender shows a "create new directory?" popup, if the beginning
of directory name typed in the field matches many entries. For example if you
have directories in the open directory called "test123" and "test456", typing
"te", tab would complete up to "test", but ask to create a new folder with the
name "test".

This patch unsets the boolean storing the info about changing filepath if the
folder with the completed name does not exist.

Reviewed By: brecht

Differential Revision: http://developer.blender.org/D10

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

M	release/scripts/addons
M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface.c
M	source/blender/editors/interface/interface_regions.c
M	source/blender/editors/space_file/filesel.c

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

diff --git a/release/scripts/addons b/release/scripts/addons
index 3adbc8f..2c7464f 160000
--- a/release/scripts/addons
+++ b/release/scripts/addons
@@ -1 +1 @@
-Subproject commit 3adbc8f30b229e7c9ff465183d5ab0acbbdf921a
+Subproject commit 2c7464fb9510bedc6a19c43064ae83ed15f3f7c7
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 38aad64..50e2e53 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -641,9 +641,13 @@ void uiButSetFocusOnEnter(struct wmWindow *win, uiBut *but);
 
 typedef struct AutoComplete AutoComplete;
 
+#define AUTOCOMPLETE_NO_MATCH 0
+#define AUTOCOMPLETE_FULL_MATCH 1
+#define AUTOCOMPLETE_PARTIAL_MATCH 2
+
 AutoComplete *autocomplete_begin(const char *startname, size_t maxlen);
 void autocomplete_do_name(AutoComplete *autocpl, const char *name);
-bool autocomplete_end(AutoComplete *autocpl, char *autoname);
+int autocomplete_end(AutoComplete *autocpl, char *autoname);
 
 /* Panels
  *
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 96638f7..6ee097b 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -3188,6 +3188,7 @@ static int findBitIndex(unsigned int x)
 /* autocomplete helper functions */
 struct AutoComplete {
 	size_t maxlen;
+	int matches;
 	char *truncate;
 	const char *startname;
 };
@@ -3198,6 +3199,7 @@ AutoComplete *autocomplete_begin(const char *startname, size_t maxlen)
 	
 	autocpl = MEM_callocN(sizeof(AutoComplete), "AutoComplete");
 	autocpl->maxlen = maxlen;
+	autocpl->matches = 0;
 	autocpl->truncate = MEM_callocN(sizeof(char) * maxlen, "AutoCompleteTruncate");
 	autocpl->startname = startname;
 
@@ -3216,6 +3218,7 @@ void autocomplete_do_name(AutoComplete *autocpl, const char *name)
 	}
 	/* found a match */
 	if (startname[a] == 0) {
+		autocpl->matches++;
 		/* first match */
 		if (truncate[0] == 0)
 			BLI_strncpy(truncate, name, autocpl->maxlen);
@@ -3233,21 +3236,26 @@ void autocomplete_do_name(AutoComplete *autocpl, const char *name)
 	}
 }
 
-bool autocomplete_end(AutoComplete *autocpl, char *autoname)
+int autocomplete_end(AutoComplete *autocpl, char *autoname)
 {	
-	bool change = false;
+	int match = AUTOCOMPLETE_NO_MATCH;
 	if (autocpl->truncate[0]) {
+		if (autocpl->matches == 1) {
+			match = AUTOCOMPLETE_FULL_MATCH;
+		} else {
+			match = AUTOCOMPLETE_PARTIAL_MATCH;
+		}
 		BLI_strncpy(autoname, autocpl->truncate, autocpl->maxlen);
-		change = true;
 	}
 	else {
 		if (autoname != autocpl->startname) {  /* don't copy a string over its self */
 			BLI_strncpy(autoname, autocpl->startname, autocpl->maxlen);
 		}
 	}
+
 	MEM_freeN(autocpl->truncate);
 	MEM_freeN(autocpl);
-	return change;
+	return match;
 }
 
 static void ui_check_but_and_iconize(uiBut *but, int icon)
diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c
index 3ef613f..1de0a27 100644
--- a/source/blender/editors/interface/interface_regions.c
+++ b/source/blender/editors/interface/interface_regions.c
@@ -1054,17 +1054,17 @@ void ui_searchbox_update(bContext *C, ARegion *ar, uiBut *but, const bool reset)
 bool ui_searchbox_autocomplete(bContext *C, ARegion *ar, uiBut *but, char *str)
 {
 	uiSearchboxData *data = ar->regiondata;
-	bool changed = false;
+	int match = AUTOCOMPLETE_NO_MATCH;
 
 	if (str[0]) {
 		data->items.autocpl = autocomplete_begin(str, ui_get_but_string_max_length(but));
 
 		but->search_func(C, but->search_arg, but->editstr, &data->items);
 
-		changed = autocomplete_end(data->items.autocpl, str);
+		match = autocomplete_end(data->items.autocpl, str);
 		data->items.autocpl = NULL;
 	}
-	return changed;
+	return match != AUTOCOMPLETE_NO_MATCH;
 }
 
 static void ui_searchbox_region_draw_cb(const bContext *UNUSED(C), ARegion *ar)
diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c
index 9d762c8..c6e1541 100644
--- a/source/blender/editors/space_file/filesel.c
+++ b/source/blender/editors/space_file/filesel.c
@@ -637,7 +637,7 @@ int file_select_match(struct SpaceFile *sfile, const char *pattern, char *matche
 bool autocomplete_directory(struct bContext *C, char *str, void *UNUSED(arg_v))
 {
 	SpaceFile *sfile = CTX_wm_space_file(C);
-	bool change = false;
+	int match = AUTOCOMPLETE_NO_MATCH;
 
 	/* search if str matches the beginning of name */
 	if (str[0] && sfile->files) {
@@ -672,9 +672,9 @@ bool autocomplete_directory(struct bContext *C, char *str, void *UNUSED(arg_v))
 			}
 			closedir(dir);
 
-			change = autocomplete_end(autocpl, str);
-			if (change) {
-				if (BLI_exists(str)) {
+			match = autocomplete_end(autocpl, str);
+			if (match) {
+				if (match == AUTOCOMPLETE_FULL_MATCH) {
 					BLI_add_slash(str);
 				}
 				else {
@@ -684,13 +684,13 @@ bool autocomplete_directory(struct bContext *C, char *str, void *UNUSED(arg_v))
 		}
 	}
 
-	return change;
+	return match == AUTOCOMPLETE_FULL_MATCH;
 }
 
 bool autocomplete_file(struct bContext *C, char *str, void *UNUSED(arg_v))
 {
 	SpaceFile *sfile = CTX_wm_space_file(C);
-	bool change = false;
+	int match = AUTOCOMPLETE_NO_MATCH;
 
 	/* search if str matches the beginning of name */
 	if (str[0] && sfile->files) {
@@ -704,9 +704,9 @@ bool autocomplete_file(struct bContext *C, char *str, void *UNUSED(arg_v))
 				autocomplete_do_name(autocpl, file->relname);
 			}
 		}
-		change = autocomplete_end(autocpl, str);
+		match = autocomplete_end(autocpl, str);
 	}
-	return change;
+	return match != AUTOCOMPLETE_NO_MATCH;
 }
 
 void ED_fileselect_clear(struct wmWindowManager *wm, struct SpaceFile *sfile)




More information about the Bf-blender-cvs mailing list