forked from bartvdbraak/blender
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
This commit is contained in:
parent
e3a79258d1
commit
9c5fb7b2e7
@ -188,7 +188,7 @@ void file_draw_buttons(const bContext *C, ARegion *ar)
|
|||||||
uiButSetFlag(but, UI_BUT_NO_UTF8);
|
uiButSetFlag(but, UI_BUT_NO_UTF8);
|
||||||
|
|
||||||
if ((params->flag & FILE_DIRSEL_ONLY) == 0) {
|
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,
|
min_x, line2_y, line2_w - chan_offs, btn_h,
|
||||||
params->file, 0.0, (float)FILE_MAXFILE, 0, 0,
|
params->file, 0.0, (float)FILE_MAXFILE, 0, 0,
|
||||||
TIP_(overwrite_alert ? N_("File name, overwrite existing") : N_("File name")));
|
TIP_(overwrite_alert ? N_("File name, overwrite existing") : N_("File name")));
|
||||||
|
@ -73,6 +73,7 @@ void FILE_OT_cancel(struct wmOperatorType *ot);
|
|||||||
void FILE_OT_parent(struct wmOperatorType *ot);
|
void FILE_OT_parent(struct wmOperatorType *ot);
|
||||||
void FILE_OT_directory_new(struct wmOperatorType *ot);
|
void FILE_OT_directory_new(struct wmOperatorType *ot);
|
||||||
void FILE_OT_directory(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_previous(struct wmOperatorType *ot);
|
||||||
void FILE_OT_next(struct wmOperatorType *ot);
|
void FILE_OT_next(struct wmOperatorType *ot);
|
||||||
void FILE_OT_refresh(struct wmOperatorType *ot);
|
void FILE_OT_refresh(struct wmOperatorType *ot);
|
||||||
|
@ -32,6 +32,8 @@
|
|||||||
#include "BLI_utildefines.h"
|
#include "BLI_utildefines.h"
|
||||||
#include "BLI_fileops_types.h"
|
#include "BLI_fileops_types.h"
|
||||||
|
|
||||||
|
#include "BLO_readfile.h"
|
||||||
|
|
||||||
#include "BKE_context.h"
|
#include "BKE_context.h"
|
||||||
#include "BKE_screen.h"
|
#include "BKE_screen.h"
|
||||||
#include "BKE_global.h"
|
#include "BKE_global.h"
|
||||||
@ -1240,13 +1242,31 @@ int file_directory_exec(bContext *C, wmOperator *UNUSED(unused))
|
|||||||
return OPERATOR_FINISHED;
|
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))
|
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];
|
char matched_file[FILE_MAX];
|
||||||
|
char filepath[sizeof(sfile->params->dir)];
|
||||||
|
|
||||||
if (sfile->params) {
|
if (sfile->params) {
|
||||||
|
int matches = 0;
|
||||||
matched_file[0] = '\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 */
|
/* int i, numfiles = filelist_numfiles(sfile->files); */ /* XXX UNUSED */
|
||||||
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 */
|
/* 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);
|
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;
|
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 */
|
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)
|
void FILE_OT_refresh(struct wmOperatorType *ot)
|
||||||
{
|
{
|
||||||
/* identifiers */
|
/* identifiers */
|
||||||
|
@ -627,7 +627,7 @@ int file_select_match(struct SpaceFile *sfile, const char *pattern, char *matche
|
|||||||
if (!match) {
|
if (!match) {
|
||||||
BLI_strncpy(matched_file, file->relname, FILE_MAX);
|
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) {
|
for (i = 0; i < nentries; ++i) {
|
||||||
struct direntry *file = filelist_file(sfile->files, 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);
|
autocomplete_do_name(autocpl, file->relname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
match = autocomplete_end(autocpl, str);
|
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)
|
void ED_fileselect_clear(struct wmWindowManager *wm, struct SpaceFile *sfile)
|
||||||
|
@ -396,6 +396,7 @@ static void file_operatortypes(void)
|
|||||||
WM_operatortype_append(FILE_OT_rename);
|
WM_operatortype_append(FILE_OT_rename);
|
||||||
WM_operatortype_append(FILE_OT_smoothscroll);
|
WM_operatortype_append(FILE_OT_smoothscroll);
|
||||||
WM_operatortype_append(FILE_OT_directory);
|
WM_operatortype_append(FILE_OT_directory);
|
||||||
|
WM_operatortype_append(FILE_OT_filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* NOTE: do not add .blend file reading on this level */
|
/* NOTE: do not add .blend file reading on this level */
|
||||||
|
Loading…
Reference in New Issue
Block a user