2.5 filebrowser
* bugfix: don't allow parent dir to go beyond root * bugfix: only attempt to change directory if it exists New (WIP) feature: autocomplete for directory * works on TAB * so far only one level (in current directory)
This commit is contained in:
@@ -72,6 +72,9 @@ void BLI_cleanup_dir(const char *relabase, char *dir); /* same as above but adds
|
||||
/* go back one directory */
|
||||
int BLI_parent_dir(char *path);
|
||||
|
||||
/* return whether directory is root and thus has no parent dir */
|
||||
int BLI_has_parent(char *path);
|
||||
|
||||
/**
|
||||
* Blender's path code replacement function.
|
||||
* Bases @a path strings leading with "//" by the
|
||||
|
||||
@@ -494,6 +494,22 @@ void BLI_makestringcode(const char *relfile, char *file)
|
||||
}
|
||||
}
|
||||
|
||||
int BLI_has_parent(char *path)
|
||||
{
|
||||
int len;
|
||||
int slashes = 0;
|
||||
BLI_clean(path);
|
||||
BLI_add_slash(path);
|
||||
|
||||
len = strlen(path)-1;
|
||||
while (len) {
|
||||
if ((path[len] == '\\') || (path[len] == '/'))
|
||||
slashes++;
|
||||
len--;
|
||||
}
|
||||
return slashes > 1;
|
||||
}
|
||||
|
||||
int BLI_parent_dir(char *path)
|
||||
{
|
||||
#ifdef WIN32
|
||||
|
||||
@@ -186,10 +186,11 @@ void file_draw_buttons(const bContext *C, ARegion *ar)
|
||||
|
||||
/* Text input fields for directory and file. */
|
||||
if (available_w > 0) {
|
||||
uiDefBut(block, TEX, B_FS_DIRNAME, "",
|
||||
but = uiDefBut(block, TEX, B_FS_DIRNAME, "",
|
||||
min_x, line1_y, line1_w, btn_h,
|
||||
params->dir, 0.0, (float)FILE_MAXFILE-1, 0, 0,
|
||||
"File path.");
|
||||
uiButSetCompleteFunc(but, autocomplete_directory, NULL);
|
||||
uiDefBut(block, TEX, B_FS_FILENAME, "",
|
||||
min_x, line2_y, line2_w, btn_h,
|
||||
params->file, 0.0, (float)FILE_MAXFILE-1, 0, 0,
|
||||
|
||||
@@ -89,6 +89,7 @@ float file_string_width(const char* str);
|
||||
float file_font_pointsize();
|
||||
void file_change_dir(struct SpaceFile *sfile);
|
||||
int file_select_match(struct SpaceFile *sfile, const char *pattern);
|
||||
void autocomplete_directory(struct bContext *C, char *str, void *arg_v);
|
||||
|
||||
/* file_panels.c */
|
||||
void file_panels_register(struct ARegionType *art);
|
||||
|
||||
@@ -142,10 +142,10 @@ static void file_select(SpaceFile* sfile, ARegion* ar, const rcti* rect, short v
|
||||
{
|
||||
// XXX error("Path too long, cannot enter this directory");
|
||||
} else {
|
||||
strcat(params->dir, file->relname);
|
||||
strcat(params->dir,"/");
|
||||
params->file[0] = '\0';
|
||||
BLI_cleanup_dir(G.sce, params->dir);
|
||||
strcat(params->dir, file->relname);
|
||||
BLI_add_slash(params->dir);
|
||||
params->file[0] = '\0';
|
||||
file_change_dir(sfile);
|
||||
}
|
||||
}
|
||||
@@ -557,11 +557,13 @@ int file_parent_exec(bContext *C, wmOperator *unused)
|
||||
SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
|
||||
|
||||
if(sfile->params) {
|
||||
BLI_parent_dir(sfile->params->dir);
|
||||
file_change_dir(sfile);
|
||||
if (BLI_has_parent(sfile->params->dir)) {
|
||||
BLI_parent_dir(sfile->params->dir);
|
||||
file_change_dir(sfile);
|
||||
WM_event_add_notifier(C, NC_FILE|ND_FILELIST, NULL);
|
||||
}
|
||||
}
|
||||
WM_event_add_notifier(C, NC_FILE|ND_FILELIST, NULL);
|
||||
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
|
||||
}
|
||||
@@ -718,10 +720,11 @@ int file_directory_exec(bContext *C, wmOperator *unused)
|
||||
BLI_strncpy(sfile->params->dir, tmpstr, sizeof(sfile->params->dir));
|
||||
}
|
||||
}
|
||||
|
||||
BLI_add_slash(sfile->params->dir);
|
||||
file_change_dir(sfile);
|
||||
WM_event_add_notifier(C, NC_FILE|ND_FILELIST, NULL);
|
||||
}
|
||||
WM_event_add_notifier(C, NC_FILE|ND_FILELIST, NULL);
|
||||
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
@@ -298,7 +298,7 @@ FileLayout* ED_fileselect_get_layout(struct SpaceFile *sfile, struct ARegion *ar
|
||||
|
||||
void file_change_dir(struct SpaceFile *sfile)
|
||||
{
|
||||
if (sfile->params) {
|
||||
if (sfile->params && BLI_exists(sfile->params->dir)) {
|
||||
filelist_setdir(sfile->files, sfile->params->dir);
|
||||
|
||||
if(folderlist_clear_next(sfile))
|
||||
@@ -329,3 +329,27 @@ int file_select_match(struct SpaceFile *sfile, const char *pattern)
|
||||
}
|
||||
return match;
|
||||
}
|
||||
|
||||
|
||||
void autocomplete_directory(struct bContext *C, char *str, void *arg_v)
|
||||
{
|
||||
char tmp[FILE_MAX];
|
||||
SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
|
||||
|
||||
/* search if str matches the beginning of name */
|
||||
if(str[0] && sfile->files) {
|
||||
AutoComplete *autocpl= autocomplete_begin(str, FILE_MAX);
|
||||
int nentries = filelist_numfiles(sfile->files);
|
||||
int i;
|
||||
|
||||
for(i= 0; i<nentries; ++i) {
|
||||
struct direntry* file = filelist_file(sfile->files, i);
|
||||
char* dir = filelist_dir(sfile->files);
|
||||
if (file && S_ISDIR(file->type)) {
|
||||
BLI_make_file_string(G.sce, tmp, dir, file->relname);
|
||||
autocomplete_do_name(autocpl,tmp);
|
||||
}
|
||||
}
|
||||
autocomplete_end(autocpl, str);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user