2.5 filebrowser
* code cleanup: removed unused fileselect mode (type) * brought back 'hide dot files', needs proper storing of the settings still.
This commit is contained in:
@@ -35,7 +35,6 @@ struct SpaceFile;
|
|||||||
#define FILE_IMGDISPLAY 3
|
#define FILE_IMGDISPLAY 3
|
||||||
|
|
||||||
typedef struct FileSelectParams {
|
typedef struct FileSelectParams {
|
||||||
int type; /* the mode of the filebrowser, FILE_BLENDER, FILE_SPECIAL, FILE_MAIN or FILE_LOADLIB */
|
|
||||||
char title[24]; /* title, also used for the text of the execute button */
|
char title[24]; /* title, also used for the text of the execute button */
|
||||||
char dir[240]; /* directory */
|
char dir[240]; /* directory */
|
||||||
char file[80]; /* file */
|
char file[80]; /* file */
|
||||||
@@ -96,8 +95,8 @@ typedef struct FileLayout
|
|||||||
|
|
||||||
FileSelectParams* ED_fileselect_get_params(struct SpaceFile *sfile);
|
FileSelectParams* ED_fileselect_get_params(struct SpaceFile *sfile);
|
||||||
|
|
||||||
short ED_fileselect_set_params(struct SpaceFile *sfile, int type, const char *title, const char *path,
|
short ED_fileselect_set_params(struct SpaceFile *sfile, const char *title, const char *path,
|
||||||
short flag, short display, short filter);
|
short flag, short display, short filter, short sort);
|
||||||
|
|
||||||
void ED_fileselect_reset_params(struct SpaceFile *sfile);
|
void ED_fileselect_reset_params(struct SpaceFile *sfile);
|
||||||
|
|
||||||
|
|||||||
@@ -444,13 +444,11 @@ void file_draw_list(const bContext *C, ARegion *ar)
|
|||||||
int colorid = 0;
|
int colorid = 0;
|
||||||
short sx, sy;
|
short sx, sy;
|
||||||
int offset;
|
int offset;
|
||||||
short type;
|
|
||||||
int i;
|
int i;
|
||||||
float sw, spos;
|
float sw, spos;
|
||||||
|
|
||||||
numfiles = filelist_numfiles(files);
|
numfiles = filelist_numfiles(files);
|
||||||
type = filelist_gettype(files);
|
|
||||||
|
|
||||||
sx = ar->v2d.tot.xmin + layout->tile_border_x/2;
|
sx = ar->v2d.tot.xmin + layout->tile_border_x/2;
|
||||||
sy = ar->v2d.cur.ymax - layout->tile_border_y;
|
sy = ar->v2d.cur.ymax - layout->tile_border_y;
|
||||||
|
|
||||||
|
|||||||
@@ -63,6 +63,7 @@
|
|||||||
#define B_SORTIMASELLIST 1
|
#define B_SORTIMASELLIST 1
|
||||||
#define B_RELOADIMASELDIR 2
|
#define B_RELOADIMASELDIR 2
|
||||||
#define B_FILTERIMASELDIR 3
|
#define B_FILTERIMASELDIR 3
|
||||||
|
#define B_HIDEDOTFILES 4
|
||||||
|
|
||||||
/* ************************ header area region *********************** */
|
/* ************************ header area region *********************** */
|
||||||
|
|
||||||
@@ -88,6 +89,14 @@ static void do_file_header_buttons(bContext *C, void *arg, int event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
WM_event_add_notifier(C, NC_WINDOW, NULL);
|
WM_event_add_notifier(C, NC_WINDOW, NULL);
|
||||||
|
break;
|
||||||
|
case B_HIDEDOTFILES:
|
||||||
|
if(sfile->params) {
|
||||||
|
filelist_free(sfile->files);
|
||||||
|
filelist_hidedot(sfile->files, sfile->params->flag & FILE_HIDE_DOT);
|
||||||
|
WM_event_add_notifier(C, NC_WINDOW, NULL);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,15 +135,14 @@ void file_header_buttons(const bContext *C, ARegion *ar)
|
|||||||
|
|
||||||
xco += 5;
|
xco += 5;
|
||||||
|
|
||||||
if (sfile->params->type != FILE_MAIN) {
|
uiBlockBeginAlign(block);
|
||||||
uiBlockBeginAlign(block);
|
uiDefIconButS(block, ROW, B_RELOADIMASELDIR, ICON_SHORTDISPLAY, xco+=XIC, yco, XIC,YIC, ¶ms->display, 1.0, FILE_SHORTDISPLAY, 0, 0, "Displays short file description");
|
||||||
uiDefIconButS(block, ROW, B_RELOADIMASELDIR, ICON_SHORTDISPLAY, xco+=XIC, yco, XIC,YIC, ¶ms->display, 1.0, FILE_SHORTDISPLAY, 0, 0, "Displays short file description");
|
uiDefIconButS(block, ROW, B_RELOADIMASELDIR, ICON_LONGDISPLAY, xco+=XIC, yco, XIC,YIC, ¶ms->display, 1.0, FILE_LONGDISPLAY, 0, 0, "Displays long file description");
|
||||||
uiDefIconButS(block, ROW, B_RELOADIMASELDIR, ICON_LONGDISPLAY, xco+=XIC, yco, XIC,YIC, ¶ms->display, 1.0, FILE_LONGDISPLAY, 0, 0, "Displays long file description");
|
uiDefIconButS(block, ROW, B_RELOADIMASELDIR, ICON_IMGDISPLAY, xco+=XIC, yco, XIC,YIC, ¶ms->display, 1.0, FILE_IMGDISPLAY, 0, 0, "Displays files as thumbnails");
|
||||||
uiDefIconButS(block, ROW, B_RELOADIMASELDIR, ICON_IMGDISPLAY, xco+=XIC, yco, XIC,YIC, ¶ms->display, 1.0, FILE_IMGDISPLAY, 0, 0, "Displays files as thumbnails");
|
uiBlockEndAlign(block);
|
||||||
uiBlockEndAlign(block);
|
|
||||||
|
xco+=XIC;
|
||||||
xco+=XIC;
|
|
||||||
}
|
|
||||||
|
|
||||||
uiBlockBeginAlign(block);
|
uiBlockBeginAlign(block);
|
||||||
uiDefIconButS(block, ROW, B_SORTIMASELLIST, ICON_SORTALPHA, xco+=XIC, yco, XIC,YIC, ¶ms->sort, 1.0, 0.0, 0, 0, "Sorts files alphabetically");
|
uiDefIconButS(block, ROW, B_SORTIMASELLIST, ICON_SORTALPHA, xco+=XIC, yco, XIC,YIC, ¶ms->sort, 1.0, 0.0, 0, 0, "Sorts files alphabetically");
|
||||||
@@ -144,17 +152,8 @@ void file_header_buttons(const bContext *C, ARegion *ar)
|
|||||||
uiBlockEndAlign(block);
|
uiBlockEndAlign(block);
|
||||||
|
|
||||||
xco+=XIC;
|
xco+=XIC;
|
||||||
|
uiDefIconButBitS(block, TOG, FILE_HIDE_DOT, B_HIDEDOTFILES, ICON_GHOST,xco+=XIC,yco,XIC,YIC, ¶ms->flag, 0, 0, 0, 0, "Hide dot files");
|
||||||
/* replace with consistent sub-region collapsing
|
xco+=XIC;
|
||||||
if (sfile->params->type != FILE_MAIN) {
|
|
||||||
uiBlockBeginAlign(block);
|
|
||||||
// uiDefIconButBitS(block, TOG, FILE_BOOKMARKS, B_RELOADIMASELDIR, ICON_BOOKMARKS,xco+=XIC,0,XIC,YIC, ¶ms->flag, 0, 0, 0, 0, "Toggles Bookmarks on/off");
|
|
||||||
uiDefIconButO(block, TOG, "FILE_OT_bookmark_toggle", WM_OP_INVOKE_DEFAULT, ICON_BOOKMARKS, xco+XIC,yco,20,20, "Toggle Bookmarks");
|
|
||||||
uiBlockEndAlign(block);
|
|
||||||
xco+=XIC;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
uiDefIconButBitS(block, TOG, FILE_FILTER, B_FILTERIMASELDIR, ICON_FILTER,xco+=XIC,yco,XIC,YIC, ¶ms->flag, 0, 0, 0, 0, "Filter files");
|
uiDefIconButBitS(block, TOG, FILE_FILTER, B_FILTERIMASELDIR, ICON_FILTER,xco+=XIC,yco,XIC,YIC, ¶ms->flag, 0, 0, 0, 0, "Filter files");
|
||||||
|
|
||||||
if (params->flag & FILE_FILTER) {
|
if (params->flag & FILE_FILTER) {
|
||||||
|
|||||||
@@ -113,7 +113,6 @@ typedef struct FileList
|
|||||||
int numfiles;
|
int numfiles;
|
||||||
int numfiltered;
|
int numfiltered;
|
||||||
char dir[FILE_MAX];
|
char dir[FILE_MAX];
|
||||||
short type;
|
|
||||||
int has_func;
|
int has_func;
|
||||||
short prv_w;
|
short prv_w;
|
||||||
short prv_h;
|
short prv_h;
|
||||||
@@ -358,12 +357,6 @@ void filelist_free_icons()
|
|||||||
struct FileList* filelist_new()
|
struct FileList* filelist_new()
|
||||||
{
|
{
|
||||||
FileList* p = MEM_callocN( sizeof(FileList), "filelist" );
|
FileList* p = MEM_callocN( sizeof(FileList), "filelist" );
|
||||||
p->filelist = 0;
|
|
||||||
p->numfiles = 0;
|
|
||||||
p->dir[0] = '\0';
|
|
||||||
p->type = 0;
|
|
||||||
p->has_func = 0;
|
|
||||||
p->filter = 0;
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -373,7 +366,6 @@ struct FileList* filelist_copy(struct FileList* filelist)
|
|||||||
BLI_strncpy(p->dir, filelist->dir, FILE_MAX);
|
BLI_strncpy(p->dir, filelist->dir, FILE_MAX);
|
||||||
p->filelist = NULL;
|
p->filelist = NULL;
|
||||||
p->fidx = NULL;
|
p->fidx = NULL;
|
||||||
p->type = filelist->type;
|
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
@@ -413,6 +405,7 @@ void filelist_free(struct FileList* filelist)
|
|||||||
filelist->filelist = 0;
|
filelist->filelist = 0;
|
||||||
filelist->filter = 0;
|
filelist->filter = 0;
|
||||||
filelist->numfiltered =0;
|
filelist->numfiltered =0;
|
||||||
|
filelist->hide_dot =0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int filelist_numfiles(struct FileList* filelist)
|
int filelist_numfiles(struct FileList* filelist)
|
||||||
@@ -510,48 +503,46 @@ void filelist_loadimage(struct FileList* filelist, int index)
|
|||||||
|
|
||||||
if (!filelist->filelist[fidx].image)
|
if (!filelist->filelist[fidx].image)
|
||||||
{
|
{
|
||||||
if (filelist->type != FILE_MAIN)
|
|
||||||
{
|
if ( (filelist->filelist[fidx].flags & IMAGEFILE) || (filelist->filelist[fidx].flags & MOVIEFILE) ) {
|
||||||
if ( (filelist->filelist[fidx].flags & IMAGEFILE) || (filelist->filelist[fidx].flags & MOVIEFILE) ) {
|
imb = IMB_thumb_read(filelist->dir, filelist->filelist[fidx].relname, THB_NORMAL);
|
||||||
imb = IMB_thumb_read(filelist->dir, filelist->filelist[fidx].relname, THB_NORMAL);
|
}
|
||||||
}
|
if (imb) {
|
||||||
if (imb) {
|
if (imb->x > imb->y) {
|
||||||
if (imb->x > imb->y) {
|
scaledx = (float)imgwidth;
|
||||||
scaledx = (float)imgwidth;
|
scaledy = ( (float)imb->y/(float)imb->x )*imgwidth;
|
||||||
scaledy = ( (float)imb->y/(float)imb->x )*imgwidth;
|
}
|
||||||
|
else {
|
||||||
|
scaledy = (float)imgheight;
|
||||||
|
scaledx = ( (float)imb->x/(float)imb->y )*imgheight;
|
||||||
|
}
|
||||||
|
ex = (short)scaledx;
|
||||||
|
ey = (short)scaledy;
|
||||||
|
|
||||||
|
dx = imgwidth - ex;
|
||||||
|
dy = imgheight - ey;
|
||||||
|
|
||||||
|
// IMB_scaleImBuf(imb, ex, ey);
|
||||||
|
filelist->filelist[fidx].image = imb;
|
||||||
|
} else {
|
||||||
|
/* prevent loading image twice */
|
||||||
|
FileImage* limg = filelist->loadimages.first;
|
||||||
|
short found= 0;
|
||||||
|
while(limg) {
|
||||||
|
if (limg->index == fidx) {
|
||||||
|
found= 1;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else {
|
limg= limg->next;
|
||||||
scaledy = (float)imgheight;
|
}
|
||||||
scaledx = ( (float)imb->x/(float)imb->y )*imgheight;
|
if (!found) {
|
||||||
}
|
FileImage* limg = MEM_callocN(sizeof(struct FileImage), "loadimage");
|
||||||
ex = (short)scaledx;
|
limg->index= fidx;
|
||||||
ey = (short)scaledy;
|
limg->lock= 0;
|
||||||
|
limg->filelist= filelist;
|
||||||
dx = imgwidth - ex;
|
BLI_addtail(&filelist->loadimages, limg);
|
||||||
dy = imgheight - ey;
|
}
|
||||||
|
}
|
||||||
// IMB_scaleImBuf(imb, ex, ey);
|
|
||||||
filelist->filelist[fidx].image = imb;
|
|
||||||
} else {
|
|
||||||
/* prevent loading image twice */
|
|
||||||
FileImage* limg = filelist->loadimages.first;
|
|
||||||
short found= 0;
|
|
||||||
while(limg) {
|
|
||||||
if (limg->index == fidx) {
|
|
||||||
found= 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
limg= limg->next;
|
|
||||||
}
|
|
||||||
if (!found) {
|
|
||||||
FileImage* limg = MEM_callocN(sizeof(struct FileImage), "loadimage");
|
|
||||||
limg->index= fidx;
|
|
||||||
limg->lock= 0;
|
|
||||||
limg->filelist= filelist;
|
|
||||||
BLI_addtail(&filelist->loadimages, limg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -826,16 +817,6 @@ void filelist_swapselect(struct FileList* filelist)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void filelist_settype(struct FileList* filelist, int type)
|
|
||||||
{
|
|
||||||
filelist->type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
short filelist_gettype(struct FileList* filelist)
|
|
||||||
{
|
|
||||||
return filelist->type;
|
|
||||||
}
|
|
||||||
|
|
||||||
void filelist_sort(struct FileList* filelist, short sort)
|
void filelist_sort(struct FileList* filelist, short sort)
|
||||||
{
|
{
|
||||||
struct direntry *file;
|
struct direntry *file;
|
||||||
|
|||||||
@@ -70,8 +70,7 @@ void filelist_readdir(struct FileList* filelist);
|
|||||||
int filelist_empty(struct FileList* filelist);
|
int filelist_empty(struct FileList* filelist);
|
||||||
void filelist_parent(struct FileList* filelist);
|
void filelist_parent(struct FileList* filelist);
|
||||||
void filelist_setfiletypes(struct FileList* filelist, short has_quicktime);
|
void filelist_setfiletypes(struct FileList* filelist, short has_quicktime);
|
||||||
void filelist_settype(struct FileList* filelist, int type);
|
|
||||||
short filelist_gettype(struct FileList* filelist);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,13 +84,13 @@
|
|||||||
FileSelectParams* ED_fileselect_get_params(struct SpaceFile *sfile)
|
FileSelectParams* ED_fileselect_get_params(struct SpaceFile *sfile)
|
||||||
{
|
{
|
||||||
if (!sfile->params) {
|
if (!sfile->params) {
|
||||||
ED_fileselect_set_params(sfile, FILE_UNIX, "", "/", 0, FILE_SHORTDISPLAY, 0);
|
ED_fileselect_set_params(sfile, "", "/", 0, FILE_SHORTDISPLAY, 0, FILE_SORTALPHA);
|
||||||
}
|
}
|
||||||
return sfile->params;
|
return sfile->params;
|
||||||
}
|
}
|
||||||
|
|
||||||
short ED_fileselect_set_params(SpaceFile *sfile, int type, const char *title, const char *path,
|
short ED_fileselect_set_params(SpaceFile *sfile, const char *title, const char *path,
|
||||||
short flag, short display, short filter)
|
short flag, short display, short filter, short sort)
|
||||||
{
|
{
|
||||||
char name[FILE_MAX], dir[FILE_MAX], file[FILE_MAX];
|
char name[FILE_MAX], dir[FILE_MAX], file[FILE_MAX];
|
||||||
FileSelectParams *params;
|
FileSelectParams *params;
|
||||||
@@ -101,39 +101,26 @@ short ED_fileselect_set_params(SpaceFile *sfile, int type, const char *title, co
|
|||||||
|
|
||||||
params = sfile->params;
|
params = sfile->params;
|
||||||
|
|
||||||
params->type = type;
|
|
||||||
params->flag = flag;
|
params->flag = flag;
|
||||||
params->display = display;
|
params->display = display;
|
||||||
params->filter = filter;
|
params->filter = filter;
|
||||||
|
params->sort = sort;
|
||||||
|
|
||||||
BLI_strncpy(params->title, title, sizeof(params->title));
|
BLI_strncpy(params->title, title, sizeof(params->title));
|
||||||
|
|
||||||
BLI_strncpy(name, path, sizeof(name));
|
BLI_strncpy(name, path, sizeof(name));
|
||||||
BLI_convertstringcode(name, G.sce);
|
BLI_convertstringcode(name, G.sce);
|
||||||
|
|
||||||
switch(type) {
|
BLI_split_dirfile(name, dir, file);
|
||||||
case FILE_MAIN:
|
BLI_strncpy(params->file, file, sizeof(params->file));
|
||||||
break;
|
BLI_strncpy(params->dir, dir, sizeof(params->dir));
|
||||||
case FILE_LOADLIB:
|
BLI_make_file_string(G.sce, params->dir, dir, ""); /* XXX needed ? - also solve G.sce */
|
||||||
break;
|
|
||||||
case FILE_BLENDER:
|
|
||||||
case FILE_LOADFONT:
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
BLI_split_dirfile(name, dir, file);
|
|
||||||
BLI_strncpy(params->file, file, sizeof(params->file));
|
|
||||||
BLI_strncpy(params->dir, dir, sizeof(params->dir));
|
|
||||||
BLI_make_file_string(G.sce, params->dir, dir, ""); /* XXX needed ? - also solve G.sce */
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ED_fileselect_reset_params(SpaceFile *sfile)
|
void ED_fileselect_reset_params(SpaceFile *sfile)
|
||||||
{
|
{
|
||||||
sfile->params->type = FILE_UNIX;
|
|
||||||
sfile->params->flag = 0;
|
sfile->params->flag = 0;
|
||||||
sfile->params->title[0] = '\0';
|
sfile->params->title[0] = '\0';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -156,7 +156,6 @@ static SpaceLink *file_duplicate(SpaceLink *sl)
|
|||||||
sfilen->params= MEM_dupallocN(sfileo->params);
|
sfilen->params= MEM_dupallocN(sfileo->params);
|
||||||
|
|
||||||
filelist_setdir(sfilen->files, sfilen->params->dir);
|
filelist_setdir(sfilen->files, sfilen->params->dir);
|
||||||
filelist_settype(sfilen->files, sfilen->params->type);
|
|
||||||
}
|
}
|
||||||
if (sfileo->layout) {
|
if (sfileo->layout) {
|
||||||
sfilen->layout= MEM_dupallocN(sfileo->layout);
|
sfilen->layout= MEM_dupallocN(sfileo->layout);
|
||||||
@@ -193,7 +192,6 @@ static void file_main_area_draw(const bContext *C, ARegion *ar)
|
|||||||
if (!sfile->files) {
|
if (!sfile->files) {
|
||||||
sfile->files = filelist_new();
|
sfile->files = filelist_new();
|
||||||
filelist_setdir(sfile->files, params->dir);
|
filelist_setdir(sfile->files, params->dir);
|
||||||
filelist_settype(sfile->files, params->type);
|
|
||||||
params->active_file = -1; // added this so it opens nicer (ton)
|
params->active_file = -1; // added this so it opens nicer (ton)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -773,12 +773,9 @@ static int wm_handler_fileselect_call(bContext *C, ListBase *handlers, wmEventHa
|
|||||||
case EVT_FILESELECT_OPEN:
|
case EVT_FILESELECT_OPEN:
|
||||||
case EVT_FILESELECT_FULL_OPEN:
|
case EVT_FILESELECT_FULL_OPEN:
|
||||||
{
|
{
|
||||||
int filetype= FILE_BLENDER;
|
short flag =0; short display =FILE_SHORTDISPLAY; short filter =0; short sort =FILE_SORTALPHA;
|
||||||
char *path= RNA_string_get_alloc(handler->op->ptr, "filename", NULL, 0);
|
char *path= RNA_string_get_alloc(handler->op->ptr, "filename", NULL, 0);
|
||||||
|
|
||||||
if(RNA_struct_find_property(handler->op->ptr, "filetype"))
|
|
||||||
filetype= RNA_int_get(handler->op->ptr, "filetype");
|
|
||||||
|
|
||||||
if(event->val==EVT_FILESELECT_OPEN)
|
if(event->val==EVT_FILESELECT_OPEN)
|
||||||
ED_area_newspace(C, handler->op_area, SPACE_FILE);
|
ED_area_newspace(C, handler->op_area, SPACE_FILE);
|
||||||
else
|
else
|
||||||
@@ -788,7 +785,16 @@ static int wm_handler_fileselect_call(bContext *C, ListBase *handlers, wmEventHa
|
|||||||
sfile= (SpaceFile*)CTX_wm_space_data(C);
|
sfile= (SpaceFile*)CTX_wm_space_data(C);
|
||||||
sfile->op= handler->op;
|
sfile->op= handler->op;
|
||||||
|
|
||||||
ED_fileselect_set_params(sfile, filetype, handler->op->type->name, path, 0, FILE_SHORTDISPLAY, 0);
|
/* XXX for now take the settings from the existing (previous) filebrowser
|
||||||
|
should be stored in settings and passed via the operator */
|
||||||
|
if (sfile->params) {
|
||||||
|
flag = sfile->params->flag;
|
||||||
|
filter = sfile->params->filter;
|
||||||
|
display = sfile->params->display;
|
||||||
|
sort = sfile->params->sort;
|
||||||
|
}
|
||||||
|
|
||||||
|
ED_fileselect_set_params(sfile, handler->op->type->name, path, flag, display, filter, sort);
|
||||||
MEM_freeN(path);
|
MEM_freeN(path);
|
||||||
|
|
||||||
action= WM_HANDLER_BREAK;
|
action= WM_HANDLER_BREAK;
|
||||||
|
|||||||
Reference in New Issue
Block a user