== 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.
This commit is contained in:
Andrea Weikert 2012-06-17 14:16:26 +00:00
parent 3a6f573b95
commit fe20596f9c
3 changed files with 39 additions and 13 deletions

@ -103,7 +103,7 @@ float file_string_width(const char* str);
float file_font_pointsize(void); float file_font_pointsize(void);
void file_change_dir(bContext *C, int checkdir); 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_directory(struct bContext *C, char *str, void *arg_v);
void autocomplete_file(struct bContext *C, char *str, void *arg_v); void autocomplete_file(struct bContext *C, char *str, void *arg_v);

@ -639,25 +639,40 @@ void file_sfile_to_operator(wmOperator *op, SpaceFile *sfile, char *filepath)
int i, numfiles = filelist_numfiles(sfile->files); int i, numfiles = filelist_numfiles(sfile->files);
if (prop_files) { if (prop_files) {
int num_files = 0;
RNA_property_collection_clear(op->ptr, prop_files); RNA_property_collection_clear(op->ptr, prop_files);
for (i=0; i<numfiles; i++) { for (i=0; i<numfiles; i++) {
if (filelist_is_selected(sfile->files, i, CHECK_FILES)) { if (filelist_is_selected(sfile->files, i, CHECK_FILES)) {
struct direntry *file= filelist_file(sfile->files, i); struct direntry *file= filelist_file(sfile->files, i);
RNA_property_collection_add(op->ptr, prop_files, &itemptr); RNA_property_collection_add(op->ptr, prop_files, &itemptr);
RNA_string_set(&itemptr, "name", file->relname); 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) { if (prop_dirs) {
int num_dirs = 0;
RNA_property_collection_clear(op->ptr, prop_dirs); RNA_property_collection_clear(op->ptr, prop_dirs);
for (i=0; i<numfiles; i++) { for (i=0; i<numfiles; i++) {
if (filelist_is_selected(sfile->files, i, CHECK_DIRS)) { if (filelist_is_selected(sfile->files, i, CHECK_DIRS)) {
struct direntry *file= filelist_file(sfile->files, i); struct direntry *file= filelist_file(sfile->files, i);
RNA_property_collection_add(op->ptr, prop_dirs, &itemptr); RNA_property_collection_add(op->ptr, prop_dirs, &itemptr);
RNA_string_set(&itemptr, "name", file->relname); 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)) int file_filename_exec(bContext *C, wmOperator *UNUSED(unused))
{ {
SpaceFile *sfile= CTX_wm_space_file(C); SpaceFile *sfile= CTX_wm_space_file(C);
char matched_file[FILE_MAX];
if (sfile->params) { 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'; 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); WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_PARAMS, NULL);
} }
} }

@ -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; 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++) { int i;
file = filelist_file(sfile->files, i); struct direntry *file;
if (fnmatch(pattern, file->relname, 0) == 0) { int n = filelist_numfiles(sfile->files);
file->selflag |= SELECTED_FILE;
match = 1; /* 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; return match;
} }