From fe20596f9c7a2418a149cdc5ad5c7802851d4b23 Mon Sep 17 00:00:00 2001 From: Andrea Weikert Date: Sun, 17 Jun 2012 14:16:26 +0000 Subject: == filebrowser == fixes: * Sequence editor not loading file typed in filebrowser file button (reported by Sergey on IRC) * filename button doesn't match exactly typed in filename notes: * file specified in the filename button now gets added to 'files' list, even if not selected * after matching filename (either by typing in exact match or using wildcards) the first match is assigned to the filename button. --- source/blender/editors/space_file/file_intern.h | 2 +- source/blender/editors/space_file/file_ops.c | 24 +++++++++++++++++++-- source/blender/editors/space_file/filesel.c | 28 +++++++++++++++---------- 3 files changed, 40 insertions(+), 14 deletions(-) (limited to 'source') diff --git a/source/blender/editors/space_file/file_intern.h b/source/blender/editors/space_file/file_intern.h index d3598ffd4e7..df05d0518bd 100644 --- a/source/blender/editors/space_file/file_intern.h +++ b/source/blender/editors/space_file/file_intern.h @@ -103,7 +103,7 @@ float file_string_width(const char* str); float file_font_pointsize(void); void file_change_dir(bContext *C, int checkdir); -int file_select_match(struct SpaceFile *sfile, const char *pattern); +int file_select_match(struct SpaceFile *sfile, const char *pattern, char *matched_file); void autocomplete_directory(struct bContext *C, char *str, void *arg_v); void autocomplete_file(struct bContext *C, char *str, void *arg_v); diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index 4bb5a21cb3d..128bc3662d9 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -639,25 +639,40 @@ void file_sfile_to_operator(wmOperator *op, SpaceFile *sfile, char *filepath) int i, numfiles = filelist_numfiles(sfile->files); if (prop_files) { + int num_files = 0; RNA_property_collection_clear(op->ptr, prop_files); for (i=0; ifiles, i, CHECK_FILES)) { struct direntry *file= filelist_file(sfile->files, i); RNA_property_collection_add(op->ptr, prop_files, &itemptr); RNA_string_set(&itemptr, "name", file->relname); + num_files++; } } + /* make sure the file specified in the filename button is added even if no files selected */ + if (0 == num_files) { + RNA_property_collection_add(op->ptr, prop_files, &itemptr); + RNA_string_set(&itemptr, "name", sfile->params->file); + } } if (prop_dirs) { + int num_dirs = 0; RNA_property_collection_clear(op->ptr, prop_dirs); for (i=0; ifiles, i, CHECK_DIRS)) { struct direntry *file= filelist_file(sfile->files, i); RNA_property_collection_add(op->ptr, prop_dirs, &itemptr); RNA_string_set(&itemptr, "name", file->relname); + num_dirs++; } } + + /* make sure the directory specified in the button is added even if no directory selected */ + if (0 == num_dirs) { + RNA_property_collection_add(op->ptr, prop_dirs, &itemptr); + RNA_string_set(&itemptr, "name", sfile->params->dir); + } } @@ -1187,10 +1202,15 @@ int file_directory_exec(bContext *C, wmOperator *UNUSED(unused)) int file_filename_exec(bContext *C, wmOperator *UNUSED(unused)) { SpaceFile *sfile= CTX_wm_space_file(C); - + char matched_file[FILE_MAX]; if (sfile->params) { - if (file_select_match(sfile, sfile->params->file)) { + matched_file[0] = '\0'; + if (file_select_match(sfile, sfile->params->file, matched_file)) { + int i, numfiles= filelist_numfiles(sfile->files); sfile->params->file[0] = '\0'; + /* replace the pattern (or filename that the user typed in, with the first selected file of the match */ + BLI_strncpy(sfile->params->file, matched_file, sizeof(sfile->params->file)); + WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_PARAMS, NULL); } } diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c index b0818d40e53..969bdcb0d19 100644 --- a/source/blender/editors/space_file/filesel.c +++ b/source/blender/editors/space_file/filesel.c @@ -589,22 +589,28 @@ void file_change_dir(bContext *C, int checkdir) } } -int file_select_match(struct SpaceFile *sfile, const char *pattern) +int file_select_match(struct SpaceFile *sfile, const char *pattern, char *matched_file) { int match = 0; - if (strchr(pattern, '*') || strchr(pattern, '?') || strchr(pattern, '[')) { - int i; - struct direntry *file; - int n = filelist_numfiles(sfile->files); - - for (i = 0; i < n; i++) { - file = filelist_file(sfile->files, i); - if (fnmatch(pattern, file->relname, 0) == 0) { - file->selflag |= SELECTED_FILE; - match = 1; + + int i; + struct direntry *file; + int n = filelist_numfiles(sfile->files); + + /* select any file that matches the pattern, this includes exact match + * if the user selects a single file by entering the filename + */ + for (i = 0; i < n; i++) { + file = filelist_file(sfile->files, i); + if (fnmatch(pattern, file->relname, 0) == 0) { + file->selflag |= SELECTED_FILE; + if (!match) { + BLI_strncpy(matched_file, file->relname, FILE_MAX ); } + match = 1; } } + return match; } -- cgit v1.2.3