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:
Diffstat (limited to 'source/blender/editors/space_file/filesel.c')
-rw-r--r--source/blender/editors/space_file/filesel.c149
1 files changed, 103 insertions, 46 deletions
diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c
index 7aed890e9ba..52d59270663 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"
@@ -53,10 +62,7 @@
#include "BLI_storage_types.h"
#include "BLI_dynstr.h"
-#include "BLO_readfile.h"
-
#include "BKE_context.h"
-#include "BKE_screen.h"
#include "BKE_global.h"
#include "BLF_api.h"
@@ -67,8 +73,6 @@
#include "WM_api.h"
#include "WM_types.h"
-#include "BIF_gl.h"
-#include "BIF_glutil.h"
#include "RNA_access.h"
@@ -77,16 +81,10 @@
#include "file_intern.h"
#include "filelist.h"
-#if defined __BeOS
-static int fnmatch(const char *pattern, const char *string, int flags)
-{
- return 0;
-}
-#elif defined WIN32 && !defined _LIBC
- /* use fnmatch included in blenlib */
- #include "BLI_fnmatch.h"
+#if defined WIN32 && !defined _LIBC
+# include "BLI_fnmatch.h" /* use fnmatch included in blenlib */
#else
- #include <fnmatch.h>
+# include <fnmatch.h>
#endif
FileSelectParams* ED_fileselect_get_params(struct SpaceFile *sfile)
@@ -99,7 +97,6 @@ FileSelectParams* ED_fileselect_get_params(struct SpaceFile *sfile)
short ED_fileselect_set_params(SpaceFile *sfile)
{
- char name[FILE_MAX], dir[FILE_MAX], file[FILE_MAX];
FileSelectParams *params;
wmOperator *op = sfile->op;
@@ -107,10 +104,7 @@ short ED_fileselect_set_params(SpaceFile *sfile)
if (!sfile->params) {
sfile->params= MEM_callocN(sizeof(FileSelectParams), "fileselparams");
/* set path to most recently opened .blend */
- BLI_strncpy(sfile->params->dir, G.sce, sizeof(sfile->params->dir));
- BLI_split_dirfile(G.sce, dir, file);
- BLI_strncpy(sfile->params->file, file, sizeof(sfile->params->file));
- BLI_make_file_string(G.sce, sfile->params->dir, dir, ""); /* XXX needed ? - also solve G.sce */
+ BLI_split_dirfile(G.sce, sfile->params->dir, sfile->params->file);
}
params = sfile->params;
@@ -124,19 +118,33 @@ short ED_fileselect_set_params(SpaceFile *sfile)
else
params->type = FILE_SPECIAL;
- if (RNA_property_is_set(op->ptr, "path")) {
- RNA_string_get(op->ptr, "path", name);
+ if (RNA_struct_find_property(op->ptr, "filepath") && RNA_property_is_set(op->ptr, "filepath")) {
+ char name[FILE_MAX];
+ RNA_string_get(op->ptr, "filepath", name);
if (params->type == FILE_LOADLIB) {
BLI_strncpy(params->dir, name, sizeof(params->dir));
- BLI_cleanup_dir(G.sce, params->dir);
- } else {
- /* if operator has path set, use it, otherwise keep the last */
- BLI_path_abs(name, G.sce);
- BLI_split_dirfile(name, dir, file);
- BLI_strncpy(params->file, file, sizeof(params->file));
- BLI_make_file_string(G.sce, params->dir, dir, ""); /* XXX needed ? - also solve G.sce */
+ sfile->params->file[0]= '\0';
+ }
+ else {
+ BLI_split_dirfile(name, sfile->params->dir, sfile->params->file);
}
}
+ else {
+ if (RNA_struct_find_property(op->ptr, "directory") && RNA_property_is_set(op->ptr, "directory")) {
+ RNA_string_get(op->ptr, "directory", params->dir);
+ sfile->params->file[0]= '\0';
+ }
+
+ if (RNA_struct_find_property(op->ptr, "filename") && RNA_property_is_set(op->ptr, "filename")) {
+ RNA_string_get(op->ptr, "filename", params->file);
+ }
+ }
+
+ if(params->dir[0]) {
+ BLI_cleanup_dir(G.sce, params->dir);
+ BLI_path_abs(params->dir, G.sce);
+ }
+
params->filter = 0;
if(RNA_struct_find_property(op->ptr, "filter_blender"))
params->filter |= RNA_boolean_get(op->ptr, "filter_blender") ? BLENDERFILE : 0;
@@ -160,8 +168,13 @@ short ED_fileselect_set_params(SpaceFile *sfile)
params->filter |= RNA_boolean_get(op->ptr, "filter_btx") ? BTXFILE : 0;
if(RNA_struct_find_property(op->ptr, "filter_collada"))
params->filter |= RNA_boolean_get(op->ptr, "filter_collada") ? COLLADAFILE : 0;
- if (params->filter != 0)
- params->flag |= FILE_FILTER;
+ if (params->filter != 0) {
+ if (U.uiflag & USER_FILTERFILEEXTS) {
+ params->flag |= FILE_FILTER;
+ } else {
+ params->flag &= ~FILE_FILTER;
+ }
+ }
if (U.uiflag & USER_HIDE_DOT) {
params->flag |= FILE_HIDE_DOT;
@@ -189,6 +202,13 @@ short ED_fileselect_set_params(SpaceFile *sfile)
params->filter = 0;
params->sort = FILE_SORT_ALPHA;
}
+
+
+ /* initialize the list with previous folders */
+ if (!sfile->folders_prev)
+ sfile->folders_prev = folderlist_new();
+ folderlist_pushdir(sfile->folders_prev, sfile->params->dir);
+
return 1;
}
@@ -205,11 +225,11 @@ int ED_fileselect_layout_numfiles(FileLayout* layout, struct ARegion *ar)
if (layout->flag & FILE_LAYOUT_HOR) {
int width = ar->v2d.cur.xmax - ar->v2d.cur.xmin - 2*layout->tile_border_x;
- numfiles = width/layout->tile_w + 1;
+ numfiles = (float)width/(float)layout->tile_w+0.5;
return numfiles*layout->rows;
} else {
int height = ar->v2d.cur.ymax - ar->v2d.cur.ymin - 2*layout->tile_border_y;
- numfiles = height/layout->tile_h + 1;
+ numfiles = (float)height/(float)layout->tile_h+0.5;
return numfiles*layout->columns;
}
}
@@ -255,7 +275,7 @@ float file_string_width(const char* str)
{
uiStyle *style= U.uistyles.first;
uiStyleFontSet(&style->widget);
- return BLF_width((char *)str);
+ return BLF_width(style->widget.uifont_id, (char *)str);
}
float file_font_pointsize()
@@ -264,7 +284,7 @@ float file_font_pointsize()
char tmp[2] = "X";
uiStyle *style= U.uistyles.first;
uiStyleFontSet(&style->widget);
- s = BLF_height(tmp);
+ s = BLF_height(style->widget.uifont_id, tmp);
return style->widget.points;
}
@@ -433,10 +453,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_strncpy(sfile->params->dir, str, sizeof(sfile->params->dir));
+ }
+ }
+ }
+}
+
+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 */
@@ -447,19 +512,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);
- }
}
}