[Bf-blender-cvs] [9c5fb7b] master: Fix T37485: autocomplete while appending and autocomplete folder behaviour.

Henrik Aarnio noreply at git.blender.org
Fri Nov 22 14:52:35 CET 2013


Commit: 9c5fb7b2e7ecb0271371cd729808da44c3bc1bc3
Author: Henrik Aarnio
Date:   Fri Nov 22 14:35:34 2013 +0100
http://developer.blender.org/rB9c5fb7b2e7ecb0271371cd729808da44c3bc1bc3

Fix T37485: autocomplete while appending and autocomplete folder behaviour.

This adds functionality to tab-autocomplete folders in the file browser file
field, and the ability to autocomplete .blend files and their sub folders while
linking. If only one match of a blend or a folder is found, it is opened, which
applies to wildcards in the file field now.

Reviewed By: elubie, brecht

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

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

M	source/blender/editors/space_file/file_draw.c
M	source/blender/editors/space_file/file_intern.h
M	source/blender/editors/space_file/file_ops.c
M	source/blender/editors/space_file/filesel.c
M	source/blender/editors/space_file/space_file.c

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

diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c
index c4e6ca9..1ec2e3c 100644
--- a/source/blender/editors/space_file/file_draw.c
+++ b/source/blender/editors/space_file/file_draw.c
@@ -188,7 +188,7 @@ void file_draw_buttons(const bContext *C, ARegion *ar)
 		uiButSetFlag(but, UI_BUT_NO_UTF8);
 
 		if ((params->flag & FILE_DIRSEL_ONLY) == 0) {
-			but = uiDefBut(block, TEX, B_FS_FILENAME, "",
+			but = uiDefButTextO(block, TEX,  "FILE_OT_filename", 0, "",
 			               min_x, line2_y, line2_w - chan_offs, btn_h,
 			               params->file, 0.0, (float)FILE_MAXFILE, 0, 0,
 			               TIP_(overwrite_alert ? N_("File name, overwrite existing") : N_("File name")));
diff --git a/source/blender/editors/space_file/file_intern.h b/source/blender/editors/space_file/file_intern.h
index d012864..134fe0a 100644
--- a/source/blender/editors/space_file/file_intern.h
+++ b/source/blender/editors/space_file/file_intern.h
@@ -73,6 +73,7 @@ void FILE_OT_cancel(struct wmOperatorType *ot);
 void FILE_OT_parent(struct wmOperatorType *ot);
 void FILE_OT_directory_new(struct wmOperatorType *ot);
 void FILE_OT_directory(struct wmOperatorType *ot);
+void FILE_OT_filename(struct wmOperatorType *ot);
 void FILE_OT_previous(struct wmOperatorType *ot);
 void FILE_OT_next(struct wmOperatorType *ot);
 void FILE_OT_refresh(struct wmOperatorType *ot);
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index a97b3b1..ebc232e 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -32,6 +32,8 @@
 #include "BLI_utildefines.h"
 #include "BLI_fileops_types.h"
 
+#include "BLO_readfile.h"
+
 #include "BKE_context.h"
 #include "BKE_screen.h"
 #include "BKE_global.h"
@@ -1240,13 +1242,31 @@ int file_directory_exec(bContext *C, wmOperator *UNUSED(unused))
 	return OPERATOR_FINISHED;
 }
 
+static int file_filename_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+{
+	SpaceFile *sfile = CTX_wm_space_file(C);
+
+	if (sfile->params) {
+		file_expand_directory(C);
+
+		return file_filename_exec(C, op);
+	}
+
+	return OPERATOR_CANCELLED;
+}
+
 int file_filename_exec(bContext *C, wmOperator *UNUSED(unused))
 {
 	SpaceFile *sfile = CTX_wm_space_file(C);
 	char matched_file[FILE_MAX];
+	char filepath[sizeof(sfile->params->dir)];
+
 	if (sfile->params) {
+		int matches = 0;
 		matched_file[0] = '\0';
-		if (file_select_match(sfile, sfile->params->file, matched_file)) {
+		filepath[0] = '\0';
+
+		if (matches = file_select_match(sfile, sfile->params->file, matched_file)) {
 			/* int i, numfiles = filelist_numfiles(sfile->files); */ /* XXX UNUSED */
 			sfile->params->file[0] = '\0';
 			/* replace the pattern (or filename that the user typed in, with the first selected file of the match */
@@ -1254,6 +1274,31 @@ int file_filename_exec(bContext *C, wmOperator *UNUSED(unused))
 			
 			WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL);
 		}
+
+		if (matches == 1) {
+
+			BLI_join_dirfile(filepath, sizeof(sfile->params->dir), sfile->params->dir, sfile->params->file);
+
+			/* if directory, open it and empty filename field */
+			if (BLI_is_dir(filepath)) {
+				BLI_cleanup_dir(G.main->name, filepath);
+				BLI_strncpy(sfile->params->dir, filepath, sizeof(sfile->params->dir));
+				sfile->params->file[0] = '\0';
+				file_change_dir(C, 1);
+				WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL);
+			}
+			else if (sfile->params->type == FILE_LOADLIB){
+				char tdir[FILE_MAX], tgroup[FILE_MAX];
+				BLI_add_slash(filepath);
+				if (BLO_is_a_library(filepath, tdir, tgroup)) {
+					BLI_cleanup_dir(G.main->name, filepath);
+					BLI_strncpy(sfile->params->dir, filepath, sizeof(sfile->params->dir));
+					sfile->params->file[0] = '\0';
+					file_change_dir(C, 0);
+					WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL);
+				}
+			}
+		}
 	}
 
 	return OPERATOR_FINISHED;
@@ -1281,6 +1326,18 @@ void FILE_OT_directory(struct wmOperatorType *ot)
 	ot->poll = file_directory_poll; /* <- important, handler is on window level */
 }
 
+void FILE_OT_filename(struct wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Enter File Name";
+	ot->description = "Enter a file name";
+	ot->idname = "FILE_OT_filename";
+
+	/* api callbacks */
+	ot->invoke = file_filename_invoke;
+	ot->exec = file_filename_exec;
+}
+
 void FILE_OT_refresh(struct wmOperatorType *ot)
 {
 	/* identifiers */
diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c
index c6e1541..3cda5dd 100644
--- a/source/blender/editors/space_file/filesel.c
+++ b/source/blender/editors/space_file/filesel.c
@@ -627,7 +627,7 @@ int file_select_match(struct SpaceFile *sfile, const char *pattern, char *matche
 			if (!match) {
 				BLI_strncpy(matched_file, file->relname, FILE_MAX);
 			}
-			match = 1;
+			match++;
 		}
 	}
 
@@ -700,13 +700,13 @@ bool autocomplete_file(struct bContext *C, char *str, void *UNUSED(arg_v))
 
 		for (i = 0; i < nentries; ++i) {
 			struct direntry *file = filelist_file(sfile->files, i);
-			if (file && S_ISREG(file->type)) {
+			if (file && (S_ISREG(file->type) || S_ISDIR(file->type))) {
 				autocomplete_do_name(autocpl, file->relname);
 			}
 		}
 		match = autocomplete_end(autocpl, str);
 	}
-	return match != AUTOCOMPLETE_NO_MATCH;
+	return match == AUTOCOMPLETE_FULL_MATCH;
 }
 
 void ED_fileselect_clear(struct wmWindowManager *wm, struct SpaceFile *sfile)
diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c
index 1a8565a..0bc2d07 100644
--- a/source/blender/editors/space_file/space_file.c
+++ b/source/blender/editors/space_file/space_file.c
@@ -396,6 +396,7 @@ static void file_operatortypes(void)
 	WM_operatortype_append(FILE_OT_rename);
 	WM_operatortype_append(FILE_OT_smoothscroll);
 	WM_operatortype_append(FILE_OT_directory);
+	WM_operatortype_append(FILE_OT_filename);
 }
 
 /* NOTE: do not add .blend file reading on this level */




More information about the Bf-blender-cvs mailing list