2.5 filebrowser

further cleanup:
- moved struct FileList* back to SpaceFile
- fix for memory related errors and freeing operator in file_free
- removed wmSubWindowSet, we're not doing OpenGL select in filebrowser
- removed drawing of load button when invoked from windowtype pupmenu
2.5 MSVC projectfiles:
- slipped in removal of multires_firstlevel.c in blenkernel
This commit is contained in:
Andrea Weikert 2009-01-06 19:22:29 +00:00
parent 25e5765f47
commit fc28d3cf75
8 changed files with 58 additions and 69 deletions

@ -649,10 +649,6 @@
RelativePath="..\..\..\source\blender\blenkernel\intern\modifier.c"
>
</File>
<File
RelativePath="..\..\..\source\blender\blenkernel\intern\multires-firstlevel.c"
>
</File>
<File
RelativePath="..\..\..\source\blender\blenkernel\intern\multires.c"
>

@ -51,9 +51,6 @@ typedef struct FileSelectParams {
char *pupmenu; /* allows menu for save options - result stored in menup */
short menu; /* currently selected option in pupmenu */
/* XXX --- end unused -- */
struct FileList *files;
} FileSelectParams;
FileSelectParams* ED_fileselect_get_params(const struct bContext *C);

@ -159,11 +159,9 @@ void file_draw_buttons(const bContext *C, ARegion *ar)
slen = UI_GetStringWidth(G.font, sfile->params->title, 0);
loadbutton= slen > 60 ? slen + 20 : MAX2(80, 20+UI_GetStringWidth(G.font, params->title, 0));
if(ar->v2d.mask.xmax-ar->v2d.mask.xmin > loadbutton+20) {
/* XXX
if(simasel->title[0]==0) {
if(params->title[0]==0) {
loadbutton= 0;
}
*/
}
else {
loadbutton= 0;
@ -295,7 +293,7 @@ void file_calc_previews(const bContext *C, ARegion *ar)
sfile->tile_h = sfile->prv_h + 2*sfile->prv_border_y + U.fontsize*3/2;
width= (v2d->cur.xmax - v2d->cur.xmin - 2*sfile->tile_border_x);
columns= file_view_columns(sfile, v2d);
rows= filelist_numfiles(params->files)/columns + 1; // XXX dirty, modulo is zero
rows= filelist_numfiles(sfile->files)/columns + 1; // XXX dirty, modulo is zero
height= rows*(sfile->tile_h+sfile->tile_border_y) + sfile->tile_border_y*2;
} else {
sfile->prv_w = 0;
@ -308,7 +306,7 @@ void file_calc_previews(const bContext *C, ARegion *ar)
sfile->tile_h = U.fontsize*3/2;
height= v2d->cur.ymax - v2d->cur.ymin;
rows = file_view_rows(sfile, v2d);
columns = filelist_numfiles(params->files)/rows + 1; // XXX dirty, modulo is zero
columns = filelist_numfiles(sfile->files)/rows + 1; // XXX dirty, modulo is zero
width = columns * (sfile->tile_w + sfile->tile_border_x) + sfile->tile_border_x*2;
}
@ -321,7 +319,7 @@ void file_draw_previews(const bContext *C, ARegion *ar)
FileSelectParams* params=sfile->params;
View2D *v2d= &ar->v2d;
static double lasttime= 0;
struct FileList* files = params->files;
struct FileList* files = sfile->files;
int numfiles;
struct direntry *file;
@ -474,7 +472,7 @@ void file_draw_list(const bContext *C, ARegion *ar)
{
SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
FileSelectParams* params = sfile->params;
struct FileList* files = params->files;
struct FileList* files = sfile->files;
struct direntry *file;
int numfiles;
int colorid = 0;

@ -103,7 +103,7 @@ static void do_file_header_buttons(bContext *C, void *arg, int event)
SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
switch(event) {
case B_SORTIMASELLIST:
filelist_sort(sfile->params->files, sfile->params->sort);
filelist_sort(sfile->files, sfile->params->sort);
WM_event_add_notifier(C, NC_WINDOW, NULL);
break;
case B_RELOADIMASELDIR:

@ -67,7 +67,7 @@ static void set_active_file_thumbs(SpaceFile *sfile, FileSelectParams* params, s
int active_file = -1;
struct direntry* file;
int offsetx, offsety;
int numfiles = filelist_numfiles(params->files);
int numfiles = filelist_numfiles(sfile->files);
int columns;
View2D* v2d = &ar->v2d;
@ -82,7 +82,7 @@ static void set_active_file_thumbs(SpaceFile *sfile, FileSelectParams* params, s
{
params->active_file = active_file;
if (params->selstate & ACTIVATE) {
file = filelist_file(params->files, params->active_file);
file = filelist_file(sfile->files, params->active_file);
file->flags |= ACTIVE;
}
}
@ -94,7 +94,7 @@ static void set_active_file(SpaceFile *sfile, FileSelectParams* params, struct A
int offsetx, offsety;
float x,y;
int active_file = -1;
int numfiles = filelist_numfiles(params->files);
int numfiles = filelist_numfiles(sfile->files);
int rows;
struct direntry* file;
@ -109,7 +109,7 @@ static void set_active_file(SpaceFile *sfile, FileSelectParams* params, struct A
{
params->active_file = active_file;
if (params->selstate & ACTIVATE) {
file = filelist_file(params->files, params->active_file);
file = filelist_file(sfile->files, params->active_file);
file->flags |= ACTIVE;
}
}
@ -128,7 +128,7 @@ static void set_active_bookmark(SpaceFile *sfile, FileSelectParams* params, stru
static void mouse_select(SpaceFile* sfile, FileSelectParams* params, ARegion* ar, short *mval)
{
int numfiles = filelist_numfiles(params->files);
int numfiles = filelist_numfiles(sfile->files);
if(mval[0]>ar->v2d.mask.xmin && mval[0]<ar->v2d.mask.xmax
&& mval[1]>ar->v2d.mask.ymin && mval[1]<ar->v2d.mask.ymax) {
params->selstate = NOTACTIVE;
@ -138,7 +138,7 @@ static void mouse_select(SpaceFile* sfile, FileSelectParams* params, ARegion* ar
set_active_file(sfile, params, ar, mval);
}
if (params->active_file >= 0 && params->active_file < numfiles) {
struct direntry* file = filelist_file(params->files, params->active_file);
struct direntry* file = filelist_file(sfile->files, params->active_file);
if(file && S_ISDIR(file->type)) {
/* the path is too long and we are not going up! */
@ -157,8 +157,8 @@ static void mouse_select(SpaceFile* sfile, FileSelectParams* params, ARegion* ar
params->file[0] = '\0';
BLI_cleanup_dir(G.sce, params->dir);
}
filelist_setdir(params->files, params->dir);
filelist_free(params->files);
filelist_setdir(sfile->files, params->dir);
filelist_free(sfile->files);
params->active_file = -1;
}
}
@ -194,8 +194,8 @@ static void mouse_select_bookmark(SpaceFile* sfile, ARegion* ar, short *mval)
FileSelectParams* params = sfile->params;
BLI_strncpy(params->dir, selected, sizeof(params->dir));
BLI_cleanup_dir(G.sce, params->dir);
filelist_free(params->files);
filelist_setdir(params->files, params->dir);
filelist_free(sfile->files);
filelist_setdir(sfile->files, params->dir);
params->file[0] = '\0';
params->active_file = -1;
}
@ -208,9 +208,6 @@ static int file_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
short mval[2];
/* note; otherwise opengl select won't work. do this for every glSelectBuffer() */
wmSubWindowSet(CTX_wm_window(C), ar->swinid);
mval[0]= event->x - ar->winrct.xmin;
mval[1]= event->y - ar->winrct.ymin;
mouse_select(sfile, sfile->params, ar, mval);
@ -238,9 +235,6 @@ static int bookmark_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
short mval[2];
/* note; otherwise opengl select won't work. do this for every glSelectBuffer() */
wmSubWindowSet(CTX_wm_window(C), ar->swinid);
mval[0]= event->x - ar->winrct.xmin;
mval[1]= event->y - ar->winrct.ymin;
mouse_select_bookmark(sfile, ar, mval);

@ -104,7 +104,6 @@ short ED_fileselect_set_params(const struct bContext *C, int type, const char *t
if (!sfile->params) {
sfile->params = MEM_callocN(sizeof(FileSelectParams), "fileselparams");
sfile->params->files = filelist_new();
}
params = sfile->params;
@ -132,14 +131,14 @@ short ED_fileselect_set_params(const struct bContext *C, int type, const char *t
BLI_strncpy(params->dir, dir, sizeof(params->dir));
BLI_make_file_string(G.sce, params->dir, dir, ""); /* XXX needed ? - also solve G.sce */
filelist_settype(params->files, type);
filelist_setdir(params->files, params->dir);
filelist_settype(sfile->files, type);
filelist_setdir(sfile->files, params->dir);
BLI_cleanup_dir(G.sce, params->dir); /* XXX solve G.sce */
/* free: filelist and libfiledata became incorrect */
if (params->files) {
filelist_free(params->files);
filelist_freelib(params->files);
if (sfile->files) {
filelist_free(sfile->files);
filelist_freelib(sfile->files);
}
}
break;

@ -76,19 +76,11 @@ static SpaceLink *file_new(const bContext *C)
sfile= MEM_callocN(sizeof(SpaceFile), "initfile");
sfile->spacetype= SPACE_FILE;
sfile->params= MEM_callocN(sizeof(FileSelectParams), "fileselparams");
sfile->params->files = filelist_new();
sfile->files = filelist_new();
// ED_fileselect_set_params(C, FILE_UNIX, "Load File", "F:\\photos\\2008_Kos", NULL, NULL, 0, 0, 0);
/* XXX move to context
sfile->dir[0]= '/';
strcpy(sfile->dir, "F:\\photos\\2008_Kos");
sfile->type= FILE_UNIX;
strcpy(sfile->title, "Load");
sfile->prv_h = 96;
sfile->prv_w = 96;
sfile->files = NULL;
*/
ED_fileselect_set_params(C, FILE_UNIX, "", "/", 0, 0, 0);
filelist_setdir(sfile->files, sfile->params->dir);
filelist_settype(sfile->files, sfile->params->type);
/* header */
ar= MEM_callocN(sizeof(ARegion), "header for file");
@ -126,19 +118,23 @@ static void file_free(SpaceLink *sl)
{
SpaceFile *sfile= (SpaceFile *) sl;
if (sfile->params) {
if(sfile->params->files) {
filelist_free(sfile->params->files);
filelist_freelib(sfile->params->files);
MEM_freeN(sfile->params->files);
sfile->params->files = 0;
if(sfile->files) {
filelist_free(sfile->files);
filelist_freelib(sfile->files);
MEM_freeN(sfile->files);
sfile->files = 0;
}
if (sfile->params) {
if(sfile->params->pupmenu)
MEM_freeN(sfile->params->pupmenu);
MEM_freeN(sfile->params);
sfile->params = 0;
}
if (sfile->op) {
WM_operator_free(sfile->op);
}
}
@ -149,15 +145,22 @@ static void file_init(struct wmWindowManager *wm, ScrArea *sa)
static SpaceLink *file_duplicate(SpaceLink *sl)
{
SpaceFile *sfileo= (SpaceFile*)sl;
SpaceFile *sfilen= MEM_dupallocN(sl);
/* clear or remove stuff from old */
sfilen->op = NULL; // XXX check if operator can be duplicated
sfilen->params= MEM_dupallocN(sfileo->params);
sfilen->params->pupmenu = NULL;
sfilen->files = filelist_new();
filelist_setdir(sfilen->files, sfilen->params->dir);
filelist_settype(sfilen->files, sfilen->params->type);
return (SpaceLink *)sfilen;
}
/* add handlers, stuff you only do once or on area/region changes */
static void file_main_area_init(wmWindowManager *wm, ARegion *ar)
{
@ -173,32 +176,32 @@ static void file_main_area_init(wmWindowManager *wm, ARegion *ar)
static void file_main_area_draw(const bContext *C, ARegion *ar)
{
/* draw entirely, view changes should be handled here */
// SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
FileSelectParams* params = ED_fileselect_get_params(C);
View2D *v2d= &ar->v2d;
View2DScrollers *scrollers;
float col[3];
if (!params->files) {
params->files = filelist_new();
filelist_setdir(params->files, params->dir);
filelist_settype(params->files, params->type);
if (!sfile->files) {
sfile->files = filelist_new();
filelist_setdir(sfile->files, params->dir);
filelist_settype(sfile->files, params->type);
}
if (filelist_empty(params->files))
if (filelist_empty(sfile->files))
{
unsigned int filter = 0;
filelist_hidedot(params->files, params->flag & FILE_HIDE_DOT);
filelist_hidedot(sfile->files, params->flag & FILE_HIDE_DOT);
if (params->flag & FILE_FILTER) {
filter = params->filter ;
} else {
filter = 0;
}
filelist_setfilter(params->files, filter);
filelist_readdir(params->files);
filelist_setfilter(sfile->files, filter);
filelist_readdir(sfile->files);
if(params->sort!=FILE_SORTALPHA) filelist_sort(params->files, params->sort);
if(params->sort!=FILE_SORTALPHA) filelist_sort(sfile->files, params->sort);
}

@ -165,6 +165,8 @@ typedef struct SpaceFile {
struct FileSelectParams* params; /* config and input for file select */
struct FileList *files; /* holds the list of files to show */
/* operator that is invoking fileselect
op->exec() will be called on the 'Load' button.
if operator provides op->cancel(), then this will be invoked