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) { 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); const char* dir = filelist_dir(sfile->files); if (file && S_ISDIR(file->type)) { // 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); if (BLI_exists(str)) { BLI_add_slash(str); } else { BLI_make_exist(str); } } }
int autocomplete_directory(struct bContext *C, char *str, void *UNUSED(arg_v)) { SpaceFile *sfile = CTX_wm_space_file(C); int match = AUTOCOMPLETE_NO_MATCH; /* search if str matches the beginning of name */ if (str[0] && sfile->files) { char dirname[FILE_MAX]; DIR *dir; struct dirent *de; BLI_split_dir_part(str, dirname, sizeof(dirname)); 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]; BLI_stat_t status; BLI_join_dirfile(path, sizeof(path), dirname, de->d_name); if (BLI_stat(path, &status) == 0) { if (S_ISDIR(status.st_mode)) { /* is subdir */ autocomplete_do_name(autocpl, path); } } } } closedir(dir); match = autocomplete_end(autocpl, str); if (match) { if (match == AUTOCOMPLETE_FULL_MATCH) { BLI_add_slash(str); } else { BLI_strncpy(sfile->params->dir, str, sizeof(sfile->params->dir)); } } } } return match; }
void autocomplete_file(struct bContext *C, char *str, void *UNUSED(arg_v)) { SpaceFile *sfile= CTX_wm_space_file(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); if (file && S_ISREG(file->type)) { autocomplete_do_name(autocpl, file->relname); } } autocomplete_end(autocpl, str); } }