Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/blender/editors/space_file/file_intern.h2
-rw-r--r--source/blender/editors/space_file/file_ops.c24
-rw-r--r--source/blender/editors/space_file/filesel.c28
3 files changed, 40 insertions, 14 deletions
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; i<numfiles; i++) {
if (filelist_is_selected(sfile->files, 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; i<numfiles; i++) {
if (filelist_is_selected(sfile->files, 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;
}