bugfix [#22276] filemanager autocompleate based on current path

also added autocomp to filename in fileselector
This commit is contained in:
Campbell Barton 2010-05-07 23:34:03 +00:00
parent b2b780f2fe
commit 14b41f9078
5 changed files with 66 additions and 29 deletions

@ -622,7 +622,7 @@ static int findFileRecursive(char *filename_new, const char *dirname, const char
while ((de = readdir(dir)) != NULL) { while ((de = readdir(dir)) != NULL) {
if (strncmp(".", de->d_name, 2)==0 || strncmp("..", de->d_name, 3)==0) if (strcmp(".", de->d_name)==0 || strcmp("..", de->d_name)==0)
continue; continue;
BLI_join_dirfile(path, dirname, de->d_name); BLI_join_dirfile(path, dirname, de->d_name);

@ -180,10 +180,11 @@ void file_draw_buttons(const bContext *C, ARegion *ar)
params->dir, 0.0, (float)FILE_MAX-1, 0, 0, params->dir, 0.0, (float)FILE_MAX-1, 0, 0,
"File path."); "File path.");
uiButSetCompleteFunc(but, autocomplete_directory, NULL); uiButSetCompleteFunc(but, autocomplete_directory, NULL);
uiDefBut(block, TEX, B_FS_FILENAME, "", but = uiDefBut(block, TEX, B_FS_FILENAME, "",
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-1, 0, 0, params->file, 0.0, (float)FILE_MAXFILE-1, 0, 0,
"File name."); "File name.");
uiButSetCompleteFunc(but, autocomplete_file, NULL);
} }
/* Filename number increment / decrement buttons. */ /* Filename number increment / decrement buttons. */

@ -90,6 +90,7 @@ float file_font_pointsize();
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);
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);
/* file_panels.c */ /* file_panels.c */
void file_panels_register(struct ARegionType *art); void file_panels_register(struct ARegionType *art);

@ -816,26 +816,15 @@ void FILE_OT_directory_new(struct wmOperatorType *ot)
int file_directory_exec(bContext *C, wmOperator *unused) int file_directory_exec(bContext *C, wmOperator *unused)
{ {
char tmpstr[FILE_MAX];
SpaceFile *sfile= CTX_wm_space_file(C); SpaceFile *sfile= CTX_wm_space_file(C);
if(sfile->params) { if(sfile->params) {
if ( sfile->params->dir[0] == '~' ) { if ( sfile->params->dir[0] == '~' ) {
if (sfile->params->dir[1] == '\0') { char tmpstr[sizeof(sfile->params->dir)-1];
BLI_strncpy(sfile->params->dir, BLI_gethome(), sizeof(sfile->params->dir) ); strncpy(tmpstr, sfile->params->dir+1, sizeof(tmpstr));
} else { BLI_join_dirfile(sfile->params->dir, BLI_gethome(), tmpstr);
/* replace ~ with home */ }
char homestr[FILE_MAX];
char *d = &sfile->params->dir[1];
while ( (*d == '\\') || (*d == '/') )
d++;
BLI_strncpy(homestr, BLI_gethome(), FILE_MAX);
BLI_join_dirfile(tmpstr, homestr, d);
BLI_strncpy(sfile->params->dir, tmpstr, sizeof(sfile->params->dir));
}
}
#ifdef WIN32 #ifdef WIN32
if (sfile->params->dir[0] == '\0') if (sfile->params->dir[0] == '\0')
get_default_root(sfile->params->dir); get_default_root(sfile->params->dir);

@ -42,6 +42,15 @@
#include <sys/times.h> #include <sys/times.h>
#endif #endif
/* path/file handeling stuff */
#ifndef WIN32
#include <dirent.h>
#include <unistd.h>
#else
#include <io.h>
#include "BLI_winstuff.h"
#endif
#include "DNA_space_types.h" #include "DNA_space_types.h"
#include "DNA_screen_types.h" #include "DNA_screen_types.h"
#include "DNA_userdef_types.h" #include "DNA_userdef_types.h"
@ -432,10 +441,55 @@ int file_select_match(struct SpaceFile *sfile, const char *pattern)
return match; return match;
} }
void autocomplete_directory(struct bContext *C, char *str, void *arg_v) void autocomplete_directory(struct bContext *C, char *str, void *arg_v)
{ {
char tmp[FILE_MAX]; SpaceFile *sfile= CTX_wm_space_file(C);
/* search if str matches the beginning of name */
if(str[0] && sfile->files) {
char dirname[FILE_MAX];
DIR *dir;
struct dirent *de;
BLI_split_dirfile(str, dirname, NULL);
dir = opendir(dirname);
if(dir) {
AutoComplete *autocpl= autocomplete_begin(str, FILE_MAX);
while ((de = readdir(dir)) != NULL) {
if (strcmp(".", de->d_name)==0 || strcmp("..", de->d_name)==0) {
/* pass */
}
else {
char path[FILE_MAX];
struct stat status;
BLI_join_dirfile(path, dirname, de->d_name);
if (stat(path, &status) == 0) {
if (S_ISDIR(status.st_mode)) { /* is subdir */
autocomplete_do_name(autocpl, path);
}
}
}
}
closedir(dir);
autocomplete_end(autocpl, str);
if (BLI_exists(str)) {
BLI_add_slash(str);
} else {
BLI_make_exist(str);
}
}
}
}
void autocomplete_file(struct bContext *C, char *str, void *arg_v)
{
SpaceFile *sfile= CTX_wm_space_file(C); SpaceFile *sfile= CTX_wm_space_file(C);
/* search if str matches the beginning of name */ /* search if str matches the beginning of name */
@ -446,19 +500,11 @@ void autocomplete_directory(struct bContext *C, char *str, void *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);
const char* dir = filelist_dir(sfile->files); if (file && S_ISREG(file->type)) {
if (file && S_ISDIR(file->type)) { autocomplete_do_name(autocpl, file->relname);
// BLI_make_file_string(G.sce, tmp, dir, file->relname);
BLI_join_dirfile(tmp, dir, file->relname);
autocomplete_do_name(autocpl,tmp);
} }
} }
autocomplete_end(autocpl, str); autocomplete_end(autocpl, str);
if (BLI_exists(str)) {
BLI_add_slash(str);
} else {
BLI_make_exist(str);
}
} }
} }