Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2010-05-08 03:34:03 +0400
committerCampbell Barton <ideasman42@gmail.com>2010-05-08 03:34:03 +0400
commit14b41f907803a1383075f497dfc7ab9bcb843ad8 (patch)
tree8f199dbce7f7dd244fbed4d2a257ed2f5d6e295c
parentb2b780f2fe9a97ce4ed97e9fc93ec05b6c4d906d (diff)
bugfix [#22276] filemanager autocompleate based on current path
also added autocomp to filename in fileselector
-rw-r--r--source/blender/blenlib/intern/bpath.c2
-rw-r--r--source/blender/editors/space_file/file_draw.c3
-rw-r--r--source/blender/editors/space_file/file_intern.h1
-rw-r--r--source/blender/editors/space_file/file_ops.c19
-rw-r--r--source/blender/editors/space_file/filesel.c70
5 files changed, 66 insertions, 29 deletions
diff --git a/source/blender/blenlib/intern/bpath.c b/source/blender/blenlib/intern/bpath.c
index 2367af470fe..afe73a53e5b 100644
--- a/source/blender/blenlib/intern/bpath.c
+++ b/source/blender/blenlib/intern/bpath.c
@@ -622,7 +622,7 @@ static int findFileRecursive(char *filename_new, const char *dirname, const char
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;
BLI_join_dirfile(path, dirname, de->d_name);
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c
index 0773ad96a7c..ac09ce6861a 100644
--- a/source/blender/editors/space_file/file_draw.c
+++ b/source/blender/editors/space_file/file_draw.c
@@ -180,10 +180,11 @@ void file_draw_buttons(const bContext *C, ARegion *ar)
params->dir, 0.0, (float)FILE_MAX-1, 0, 0,
"File path.");
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,
params->file, 0.0, (float)FILE_MAXFILE-1, 0, 0,
"File name.");
+ uiButSetCompleteFunc(but, autocomplete_file, NULL);
}
/* Filename number increment / decrement buttons. */
diff --git a/source/blender/editors/space_file/file_intern.h b/source/blender/editors/space_file/file_intern.h
index a7aeaa1d365..ef05e6cac76 100644
--- a/source/blender/editors/space_file/file_intern.h
+++ b/source/blender/editors/space_file/file_intern.h
@@ -90,6 +90,7 @@ float file_font_pointsize();
void file_change_dir(bContext *C, int checkdir);
int file_select_match(struct SpaceFile *sfile, const char *pattern);
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 */
void file_panels_register(struct ARegionType *art);
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index 85b3cee354b..ed098d2d44e 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -816,26 +816,15 @@ void FILE_OT_directory_new(struct wmOperatorType *ot)
int file_directory_exec(bContext *C, wmOperator *unused)
{
- char tmpstr[FILE_MAX];
-
SpaceFile *sfile= CTX_wm_space_file(C);
if(sfile->params) {
if ( sfile->params->dir[0] == '~' ) {
- if (sfile->params->dir[1] == '\0') {
- BLI_strncpy(sfile->params->dir, BLI_gethome(), sizeof(sfile->params->dir) );
- } else {
- /* 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));
- }
+ char tmpstr[sizeof(sfile->params->dir)-1];
+ strncpy(tmpstr, sfile->params->dir+1, sizeof(tmpstr));
+ BLI_join_dirfile(sfile->params->dir, BLI_gethome(), tmpstr);
}
+
#ifdef WIN32
if (sfile->params->dir[0] == '\0')
get_default_root(sfile->params->dir);
diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c
index ea098ffcdb4..916f8dfcd62 100644
--- a/source/blender/editors/space_file/filesel.c
+++ b/source/blender/editors/space_file/filesel.c
@@ -42,6 +42,15 @@
#include <sys/times.h>
#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_screen_types.h"
#include "DNA_userdef_types.h"
@@ -432,10 +441,55 @@ 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= 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);
/* 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) {
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);
+ if (file && S_ISREG(file->type)) {
+ autocomplete_do_name(autocpl, file->relname);
}
}
autocomplete_end(autocpl, str);
- if (BLI_exists(str)) {
- BLI_add_slash(str);
- } else {
- BLI_make_exist(str);
- }
}
}