diff options
Diffstat (limited to 'source/blender/editors/space_file')
-rw-r--r-- | source/blender/editors/space_file/file_draw.c | 598 | ||||
-rw-r--r-- | source/blender/editors/space_file/file_header.c | 43 | ||||
-rw-r--r-- | source/blender/editors/space_file/file_intern.h | 15 | ||||
-rw-r--r-- | source/blender/editors/space_file/file_ops.c | 269 | ||||
-rw-r--r-- | source/blender/editors/space_file/filelist.c | 5 | ||||
-rw-r--r-- | source/blender/editors/space_file/filesel.c | 80 | ||||
-rw-r--r-- | source/blender/editors/space_file/fsmenu.c | 67 | ||||
-rw-r--r-- | source/blender/editors/space_file/fsmenu.h | 9 | ||||
-rw-r--r-- | source/blender/editors/space_file/space_file.c | 212 |
9 files changed, 1239 insertions, 59 deletions
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c new file mode 100644 index 00000000000..04b126bf858 --- /dev/null +++ b/source/blender/editors/space_file/file_draw.c @@ -0,0 +1,598 @@ +/** + * $Id: + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2008 Blender Foundation. + * All rights reserved. + * + * + * Contributor(s): Blender Foundation + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include "BLI_blenlib.h" +#include "BLI_storage_types.h" +#ifdef WIN32 +#include "BLI_winstuff.h" +#endif + +#include "BIF_gl.h" +#include "BIF_glutil.h" + +#include "BKE_colortools.h" +#include "BKE_context.h" +#include "BKE_screen.h" +#include "BKE_global.h" +#include "BKE_utildefines.h" + +#include "BMF_Api.h" + +#include "DNA_space_types.h" +#include "DNA_scene_types.h" +#include "DNA_screen_types.h" +#include "DNA_userdef_types.h" + +#include "ED_fileselect.h" + +#include "IMB_imbuf_types.h" +#include "IMB_imbuf.h" + +#include "MEM_guardedalloc.h" + +#include "PIL_time.h" + +#include "RNA_access.h" + +#include "UI_interface.h" +#include "UI_interface_icons.h" +#include "UI_resources.h" +#include "UI_text.h" +#include "UI_view2d.h" + +#include "WM_api.h" +#include "WM_types.h" + +#include "fsmenu.h" +#include "filelist.h" + +#include "file_intern.h" // own include + +/* ui geometry */ +#define IMASEL_BUTTONS_HEIGHT 60 +#define TILE_BORDER_X 8 +#define TILE_BORDER_Y 8 + +/* button events */ +enum { + B_REDR = 0, + B_FS_LOAD, + B_FS_CANCEL, +} eFile_ButEvents; + +// XXX for Ton: bad level, maybe needs export in ED_screen? +extern void area_prevspace(bContext *C); + +static void do_file_buttons(bContext *C, void *arg, int event) +{ + SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C); + switch(event) { + case B_FS_LOAD: + { + char name[FILE_MAX]; + + area_prevspace(C); + BLI_strncpy(name, sfile->params->dir, sizeof(name)); + strcat(name, sfile->params->file); + RNA_string_set(sfile->op->ptr, "filename", name); + sfile->op->type->exec(C, sfile->op); + /* XXX for Ton: the call to WM_operator_free crashes + WM_operator_free(sfile->op); + sfile->op = NULL; + */ + } + break; + case B_FS_CANCEL: + /* XXX for Ton: the call to area_prevspace crashes + area_prevspace(C); + */ + break; + } +} + +void file_draw_buttons(const bContext *C, ARegion *ar) +{ + SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C); + FileSelectParams* params = sfile->params; + uiBlock *block; + int loadbutton; + char name[20]; + char *menu; + float slen; + float parentbut_width = 20; + float bookmarkbut_width = 0.0f; + float file_start_width = 0.0f; + + int filebuty1, filebuty2; + + float xmin = ar->v2d.mask.xmin + 10; + float xmax = ar->v2d.mask.xmax - 10; + + filebuty1= ar->v2d.mask.ymax - IMASEL_BUTTONS_HEIGHT; + filebuty2= filebuty1+IMASEL_BUTTONS_HEIGHT/2 -6; + + /* HEADER */ + sprintf(name, "win %d", 1); // XXX sa-win??? + block = uiBeginBlock(C, ar, name, UI_EMBOSS, UI_HELV); + uiBlockSetHandleFunc(block, do_file_buttons, NULL); + + /* XXXX + uiSetButLock( filelist_gettype(simasel->files)==FILE_MAIN && simasel->returnfunc, NULL); + */ + + /* space available for load/save buttons? */ + slen = BMF_GetStringWidth(G.font, sfile->params->title); + 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) { + loadbutton= 0; + } + */ + } + else { + loadbutton= 0; + } + + /* XXX to channel region */ + menu= fsmenu_build_menu(); + + if (menu[0]&& (params->type != FILE_MAIN)) { + bookmarkbut_width = parentbut_width; + file_start_width = parentbut_width; + } + + uiDefBut(block, TEX, 0 /* XXX B_FS_FILENAME */,"", xmin+file_start_width+bookmarkbut_width+2, filebuty1, xmax-xmin-loadbutton-file_start_width-bookmarkbut_width, 21, params->file, 0.0, (float)FILE_MAXFILE-1, 0, 0, ""); + uiDefBut(block, TEX, 0 /* XXX B_FS_DIRNAME */,"", xmin+parentbut_width, filebuty2, xmax-xmin-loadbutton-parentbut_width, 21, params->dir, 0.0, (float)FILE_MAXFILE-1, 0, 0, ""); + + if(loadbutton) { + uiSetCurFont(block, UI_HELV); + uiDefBut(block, BUT, B_FS_LOAD, params->title, xmax-loadbutton, filebuty2, loadbutton, 21, params->dir, 0.0, (float)FILE_MAXFILE-1, 0, 0, ""); + uiDefBut(block, BUT, B_FS_CANCEL, "Cancel", xmax-loadbutton, filebuty1, loadbutton, 21, params->file, 0.0, (float)FILE_MAXFILE-1, 0, 0, ""); + } + + /* menu[0] = NULL happens when no .Bfs is there, and first time browse + disallow external directory browsing for databrowse */ + + if(menu[0] && (params->type != FILE_MAIN)) { + uiDefButS(block, MENU, 0 /* B_FS_DIR_MENU */, menu, xmin, filebuty1, parentbut_width, 21, ¶ms->menu, 0, 0, 0, 0, ""); + uiDefBut(block, BUT, 0 /* B_FS_BOOKMARK */, "B", xmin+22, filebuty1, bookmarkbut_width, 21, 0, 0, 0, 0, 0, "Bookmark current directory"); + } + + MEM_freeN(menu); + + uiDefBut(block, BUT, 0 /* XXX B_FS_PARDIR */, "P", xmin, filebuty2, parentbut_width, 21, 0, 0, 0, 0, 0, "Move to the parent directory (PKEY)"); + uiEndBlock(C, block); + uiDrawBlock(C, block); +} + + +static void draw_tile(SpaceFile *sfile, short sx, short sy, short width, short height, int colorid) +{ + /* TODO: BIF_ThemeColor seems to need this to show the color, not sure why? - elubie */ + glEnable(GL_BLEND); + glColor4ub(0, 0, 0, 100); + glDisable(GL_BLEND); + + UI_ThemeColor4(colorid); + uiSetRoundBox(15); + glRecti(sx, sy - height, sx + width, sy); + + // uiRoundBox(sx+TILE_BORDER_X, sy - sfile->prv_h - TILE_BORDER_Y*3 - U.fontsize, sx + sfile->prv_w + TILE_BORDER_X*3, sy, 6); +} + +static float shorten_string(char* string, float w) +{ + short shortened = 0; + float sw = 0; + + sw = UI_GetStringWidth(G.font, string,0); + while (sw>w) { + int slen = strlen(string); + string[slen-1] = '\0'; + sw = UI_GetStringWidth(G.font, string,0); + shortened = 1; + } + if (shortened) { + int slen = strlen(string); + if (slen > 3) { + BLI_strncpy(string+slen-3, "...", 4); + } + } + return sw; +} + +static void file_draw_string(short sx, short sy, char* string, short width, short height) +{ + short soffs; + char fname[FILE_MAXFILE]; + float sw; + float x,y; + + BLI_strncpy(fname,string, FILE_MAXFILE); + sw = shorten_string(fname, width ); + soffs = (width - sw) / 2; + x = (float)(sx); + y = (float)(sy-height); + + // XXX was using ui_rasterpos_safe + glRasterPos2f(x, y); + UI_RasterPos(x, y); + + /* XXX TODO: handling of international fonts. + TODO: proper support for utf8 in languages different from ja_JP abd zh_CH + needs update of iconv in lib/windows to support getting the system language string + */ + UI_DrawString(G.font, fname, 0); + +} + +/* returns max number of rows in view */ +static int file_view_rows(SpaceFile* sfile, View2D *v2d) +{ + int height= (v2d->cur.ymax - v2d->cur.ymin - 2*sfile->tile_border_y); + return height / (sfile->tile_h + sfile->tile_border_y); +} + +/* returns max number of columns in view */ +static int file_view_columns(SpaceFile* sfile, View2D *v2d) +{ + int width= (v2d->cur.xmax - v2d->cur.xmin - 2*sfile->tile_border_x); + return width / (sfile->tile_w + sfile->tile_border_x); +} + +void file_calc_previews(const bContext *C, ARegion *ar) +{ + SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C); + FileSelectParams* params = sfile->params; + View2D *v2d= &ar->v2d; + int width=0, height=0; + int rows, columns; + int linestep = U.fontsize*3/2; + + if (params->display) { + sfile->prv_w = 96; + sfile->prv_h = 96; + sfile->tile_border_x = 8; + sfile->tile_border_y = 8; + sfile->prv_border_x = 4; + sfile->prv_border_y = 4; + sfile->tile_w = sfile->prv_w + 2*sfile->prv_border_x; + 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 + height= rows*(sfile->tile_h+sfile->tile_border_y) + sfile->tile_border_y*2; + } else { + sfile->prv_w = 0; + sfile->prv_h = 0; + sfile->tile_border_x = 8; + sfile->tile_border_y = 2; + sfile->prv_border_x = 0; + sfile->prv_border_y = 0; + sfile->tile_w = 240; + 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 + width = columns * (sfile->tile_w + sfile->tile_border_x) + sfile->tile_border_x*2; + } + + UI_view2d_totRect_set(v2d, width, height); +} + +void file_draw_previews(const bContext *C, ARegion *ar) +{ + SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C); + FileSelectParams* params=sfile->params; + View2D *v2d= &ar->v2d; + static double lasttime= 0; + struct FileList* files = params->files; + int numfiles; + struct direntry *file; + + short sx, sy; + int do_load = 1; + + ImBuf* imb=0; + int i; + short type; + int colorid = 0; + int todo; + int offset; + int columns; + + if (!files) return; + /* Reload directory */ + BLI_strncpy(params->dir, filelist_dir(files), FILE_MAX); + + type = filelist_gettype(files); + + filelist_imgsize(files,sfile->prv_w,sfile->prv_h); + + numfiles = filelist_numfiles(files); + + todo = 0; + if (lasttime < 0.001) lasttime = PIL_check_seconds_timer(); + + sx = v2d->cur.xmin + sfile->tile_border_x; + sy = v2d->cur.ymax - sfile->tile_border_y; + columns = file_view_columns(sfile, v2d); + offset = columns*(-v2d->cur.ymax+sfile->tile_border_y)/sfile->tile_h; + offset = (offset/columns-1)*columns; + if (offset<0) offset=0; + for (i=offset; (i < numfiles); ++i) + { + sx = v2d->tot.xmin + sfile->tile_border_x + ((i)%columns)*(sfile->tile_w+sfile->tile_border_x); + sy = v2d->tot.ymax - sfile->tile_border_y - ((i)/columns)*(sfile->tile_h+sfile->tile_border_y); + file = filelist_file(files, i); + + if (params->active_file == i) { + colorid = TH_ACTIVE; + draw_tile(sfile, sx, sy, sfile->tile_w, sfile->tile_h, colorid); + } else if (file->flags & ACTIVE) { + colorid = TH_HILITE; + draw_tile(sfile, sx, sy+sfile->tile_border_y, sfile->tile_w, sfile->tile_h-sfile->tile_border_y, colorid); + } else { + /* + colorid = TH_PANEL; + draw_tile(simasel, sx, sy, tilewidth, tileheight, colorid); + */ + } + +#if 0 + if ( type == FILE_MAIN) { + ID *id; + int icon_id = 0; + int idcode; + idcode= groupname_to_code(sfile->dir); + if (idcode == ID_MA || idcode == ID_TE || idcode == ID_LA || idcode == ID_WO || idcode == ID_IM) { + id = (ID *)file->poin; + icon_id = BKE_icon_getid(id); + } + if (icon_id) { + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + if (do_load) { + UI_icon_draw_preview(sx+2*TILE_BORDER_X, sy-simasel->prv_w-TILE_BORDER_X, icon_id, 0); + } else { + UI_icon_draw_preview(sx+2*TILE_BORDER_X, sy-simasel->prv_w-TILE_BORDER_X, icon_id, 1); + todo++; + } + + glDisable(GL_BLEND); + } + } + else { +#endif + if ( (file->flags & IMAGEFILE) /* || (file->flags & MOVIEFILE) */) + { + if (do_load) { + filelist_loadimage(files, i); + } else { + todo++; + } + imb = filelist_getimage(files, i); + } else { + imb = filelist_getimage(files, i); + } + + if (imb) { + float fx = ((float)sfile->prv_w - (float)imb->x)/2.0f; + float fy = ((float)sfile->prv_h - (float)imb->y)/2.0f; + short dx = (short)(fx + 0.5f + sfile->prv_border_x); + short dy = (short)(fy + 0.5f + sfile->prv_border_y); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + // glaDrawPixelsSafe((float)sx+8 + dx, (float)sy - imgwidth + dy - 8, imb->x, imb->y, imb->x, GL_RGBA, GL_UNSIGNED_BYTE, imb->rect); + glColor4f(1.0, 1.0, 1.0, 1.0); + glaDrawPixelsTex((float)sx + dx, (float)sy - sfile->prv_h + dy, imb->x, imb->y,GL_UNSIGNED_BYTE, imb->rect); + // glDisable(GL_BLEND); + imb = 0; + } +#if 0 + } +#endif + if (type == FILE_MAIN) { + glColor3f(1.0f, 1.0f, 1.0f); + } + else { + if (S_ISDIR(file->type)) { + glColor3f(1.0f, 1.0f, 0.9f); + } + else if (file->flags & IMAGEFILE) { + UI_ThemeColor(TH_SEQ_IMAGE); + } + else if (file->flags & MOVIEFILE) { + UI_ThemeColor(TH_SEQ_MOVIE); + } + else if (file->flags & BLENDERFILE) { + UI_ThemeColor(TH_SEQ_SCENE); + } + else { + if (params->active_file == i) { + UI_ThemeColor(TH_GRID); /* grid used for active text */ + } else if (file->flags & ACTIVE) { + UI_ThemeColor(TH_TEXT_HI); + } else { + UI_ThemeColor(TH_TEXT); + } + } + } + + file_draw_string(sx + sfile->prv_border_x, sy, file->relname, sfile->tile_w, sfile->tile_h); +#if 0 + if(do_load && (PIL_check_seconds_timer() - lasttime > 0.3)) { + lasttime= PIL_check_seconds_timer(); + do_load = 0; + } +#endif + } +#if 0 // XXX solve with threads or add notifier ?? + if (!do_load && todo > 0) /* we broke off loading */ + addafterqueue(sa->win, RENDERPREVIEW, 1); +#endif +} + + +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 direntry *file; + int numfiles; + int colorid = 0; + short sx, sy; + int offset; + short type; + int i; + int rows; + + numfiles = filelist_numfiles(files); + type = filelist_gettype(files); + + sx = ar->v2d.tot.xmin + sfile->tile_border_x/2; + sy = ar->v2d.cur.ymax - sfile->tile_border_y; + + rows = (ar->v2d.cur.ymax - ar->v2d.cur.ymin - 2*sfile->tile_border_y) / (sfile->tile_h+sfile->tile_border_y); + offset = rows*(sx - sfile->tile_border_x)/(sfile->tile_w+sfile->tile_border_x); + offset = (offset/rows-1)*rows; + + while (sx < ar->v2d.cur.xmax) { + sx += (sfile->tile_w+sfile->tile_border_x); + glColor4ub(0xB0,0xB0,0xB0, 0xFF); + sdrawline(sx+1, ar->v2d.cur.ymax - sfile->tile_border_y , sx+1, ar->v2d.cur.ymin + sfile->tile_border_y); + glColor4ub(0x30,0x30,0x30, 0xFF); + sdrawline(sx, ar->v2d.cur.ymax - sfile->tile_border_y , sx, ar->v2d.cur.ymin + sfile->tile_border_y); + } + + sx = ar->v2d.cur.xmin + sfile->tile_border_x; + sy = ar->v2d.cur.ymax - sfile->tile_border_y; + if (offset<0) offset=0; + for (i=offset; (i < numfiles); ++i) + { + sy = ar->v2d.tot.ymax-sfile->tile_border_y - (i%rows)*(sfile->tile_h+sfile->tile_border_y); + sx = ar->v2d.tot.xmin +sfile->tile_border_x + (i/rows)*(sfile->tile_w+sfile->tile_border_x); + + file = filelist_file(files, i); + + if (params->active_file == i) { + colorid = TH_ACTIVE; + draw_tile(sfile, sx, sy, sfile->tile_w, sfile->tile_h, colorid); + } else if (file->flags & ACTIVE) { + colorid = TH_HILITE; + draw_tile(sfile, sx, sy, sfile->tile_w, sfile->tile_h, colorid); + } else { + /* + colorid = TH_PANEL; + draw_tile(simasel, sx, sy, sfile->tile_w, sfile->tile_h, colorid); + */ + } + if (type == FILE_MAIN) { + glColor3f(1.0f, 1.0f, 1.0f); + } + else { + if (S_ISDIR(file->type)) { + glColor3f(1.0f, 1.0f, 0.9f); + } + else if (file->flags & IMAGEFILE) { + UI_ThemeColor(TH_SEQ_IMAGE); + } + else if (file->flags & MOVIEFILE) { + UI_ThemeColor(TH_SEQ_MOVIE); + } + else if (file->flags & BLENDERFILE) { + UI_ThemeColor(TH_SEQ_SCENE); + } + else { + if (params->active_file == i) { + UI_ThemeColor(TH_GRID); /* grid used for active text */ + } else if (file->flags & ACTIVE) { + UI_ThemeColor(TH_TEXT_HI); + } else { + UI_ThemeColor(TH_TEXT); + } + } + } + + file_draw_string(sx, sy, file->relname, sfile->tile_w, sfile->tile_h); + file_draw_string(sx + sfile->tile_w - UI_GetStringWidth(G.font, file->size, 0), sy, + file->size, sfile->tile_w - UI_GetStringWidth(G.font, file->size, 0), sfile->tile_h); + } +} + +void file_draw_fsmenu(const bContext *C, ARegion *ar) +{ + SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C); + FileSelectParams* params = sfile->params; + char bookmark[FILE_MAX]; + int nentries = fsmenu_get_nentries(); + int linestep = U.fontsize*3/2; + int i; + short sx, sy; + int bmwidth = ar->v2d.cur.xmax - ar->v2d.cur.xmin - 2*TILE_BORDER_X; + int fontsize = U.fontsize; + + sx = ar->v2d.cur.xmin + TILE_BORDER_X; + sy = -2*TILE_BORDER_Y; + for (i=0; i< nentries && (sy > ar->v2d.cur.ymin) ;++i) { + char *fname = fsmenu_get_entry(i); + + if (fname) { + int sl; + BLI_strncpy(bookmark, fname, FILE_MAX); + + sl = strlen(bookmark)-1; + while (bookmark[sl] == '\\' || bookmark[sl] == '/') { + bookmark[sl] = '\0'; + sl--; + } + if (params->active_bookmark == i ) { + glColor4ub(0, 0, 0, 100); + UI_ThemeColor(TH_HILITE); + // uiSetRoundBox(15); + // uiRoundBox(simasel->bookmarkrect.xmin + TILE_BORDER_X - 1, sy - linestep*0.25, simasel->bookmarkrect.xmax - TILE_BORDER_X + 1, sy + linestep*0.75, 6); + glRecti(sx, sy - linestep, sx + bmwidth, sy); + UI_ThemeColor(TH_TEXT_HI); + } else { + UI_ThemeColor(TH_TEXT); + } + + file_draw_string(sx, sy, bookmark, bmwidth, fontsize); + sy -= linestep; + } else { + glColor4ub(0xB0,0xB0,0xB0, 0xFF); + sdrawline(sx, sy-1-fontsize/2 , sx + bmwidth, sy-1-fontsize/2); + glColor4ub(0x30,0x30,0x30, 0xFF); + sdrawline(sx, sy-fontsize/2 , sx + bmwidth, sy - fontsize/2); + sy -= linestep; + } + } +}
\ No newline at end of file diff --git a/source/blender/editors/space_file/file_header.c b/source/blender/editors/space_file/file_header.c index ccaa0acbfd3..21f81cd83a7 100644 --- a/source/blender/editors/space_file/file_header.c +++ b/source/blender/editors/space_file/file_header.c @@ -40,10 +40,12 @@ #include "BKE_context.h" #include "BKE_screen.h" +#include "BKE_global.h" #include "ED_screen.h" #include "ED_types.h" #include "ED_util.h" +#include "ED_fileselect.h" #include "WM_api.h" #include "WM_types.h" @@ -51,11 +53,17 @@ #include "BIF_gl.h" #include "BIF_glutil.h" +#include "BMF_Api.h" + #include "UI_interface.h" #include "UI_resources.h" #include "UI_view2d.h" #include "file_intern.h" +#include "filelist.h" + +#define B_SORTIMASELLIST 1 +#define B_RELOADIMASELDIR 2 /* ************************ header area region *********************** */ @@ -91,10 +99,17 @@ static uiBlock *dummy_viewmenu(bContext *C, uiMenuBlockHandle *handle, void *arg return block; } - -static void do_file_buttons(bContext *C, void *arg, int event) +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); + WM_event_add_notifier(C, NC_WINDOW, NULL); + break; + case B_RELOADIMASELDIR: + WM_event_add_notifier(C, NC_WINDOW, NULL); + break; } } @@ -102,11 +117,15 @@ static void do_file_buttons(bContext *C, void *arg, int event) void file_header_buttons(const bContext *C, ARegion *ar) { ScrArea *sa= CTX_wm_area(C); + SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C); + FileSelectParams* params = sfile->params; + uiBlock *block; int xco, yco= 3; + int xcotitle; block= uiBeginBlock(C, ar, "header buttons", UI_EMBOSS, UI_HELV); - uiBlockSetHandleFunc(block, do_file_buttons, NULL); + uiBlockSetHandleFunc(block, do_file_header_buttons, NULL); xco= ED_area_header_standardbuttons(C, block, yco); @@ -122,6 +141,23 @@ void file_header_buttons(const bContext *C, ARegion *ar) xco+=XIC+xmax; } + /* SORT TYPE */ + xco+=XIC; + uiBlockBeginAlign(block); + uiDefIconButS(block, ROW, B_SORTIMASELLIST, ICON_SORTALPHA, xco+=XIC,0,XIC,YIC, ¶ms->sort, 1.0, 0.0, 0, 0, "Sorts files alphabetically"); + uiDefIconButS(block, ROW, B_SORTIMASELLIST, ICON_SORTBYEXT, xco+=XIC,0,XIC,YIC, ¶ms->sort, 1.0, 3.0, 0, 0, "Sorts files by extension"); + uiDefIconButS(block, ROW, B_SORTIMASELLIST, ICON_SORTTIME, xco+=XIC,0,XIC,YIC, ¶ms->sort, 1.0, 1.0, 0, 0, "Sorts files by time"); + uiDefIconButS(block, ROW, B_SORTIMASELLIST, ICON_SORTSIZE, xco+=XIC,0,XIC,YIC, ¶ms->sort, 1.0, 2.0, 0, 0, "Sorts files by size"); + uiBlockEndAlign(block); + xco+=XIC+10; + + if (sfile->params->type != FILE_MAIN) { + uiDefIconButBitS(block, TOG, 1, B_RELOADIMASELDIR, ICON_BOOKMARKS,xco+=XIC,0,XIC,YIC, ¶ms->display, 0, 0, 0, 0, "Toggles Bookmarks on/off"); + xco+=XIC+10; + } + xcotitle= xco; + xco+= BMF_GetStringWidth(G.font, params->title); + uiBlockSetEmboss(block, UI_EMBOSS); /* always as last */ @@ -132,3 +168,4 @@ void file_header_buttons(const bContext *C, ARegion *ar) } + diff --git a/source/blender/editors/space_file/file_intern.h b/source/blender/editors/space_file/file_intern.h index 2322c60f9c9..f5b93a84f39 100644 --- a/source/blender/editors/space_file/file_intern.h +++ b/source/blender/editors/space_file/file_intern.h @@ -34,9 +34,20 @@ /* file_header.c */ void file_header_buttons(const bContext *C, ARegion *ar); -/* filesel.c */ -void freefilelist(SpaceFile *sfile); +/* file_draw.c */ +#define TILE_BORDER_X 8 +#define TILE_BORDER_Y 8 +void file_draw_buttons(const bContext *C, ARegion *ar); +void file_calc_previews(const bContext *C, ARegion *ar); +void file_draw_previews(const bContext *C, ARegion *ar); +void file_draw_list(const bContext *C, ARegion *ar); +void file_draw_fsmenu(const bContext *C, ARegion *ar); + +/* file_ops.h */ +struct wmOperatorType; +void ED_FILE_OT_select(struct wmOperatorType *ot); +void ED_FILE_OT_select_bookmark(struct wmOperatorType *ot); #endif /* ED_FILE_INTERN_H */ diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c new file mode 100644 index 00000000000..2d1617d03a3 --- /dev/null +++ b/source/blender/editors/space_file/file_ops.c @@ -0,0 +1,269 @@ +/** + * $Id: + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2008 Blender Foundation. + * All rights reserved. + * + * + * Contributor(s): Andrea Weikert (c) 2008 Blender Foundation + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include "BKE_context.h" +#include "BKE_screen.h" +#include "BKE_global.h" + +#include "BLI_blenlib.h" +#include "BLI_storage_types.h" +#ifdef WIN32 +#include "BLI_winstuff.h" +#endif +#include "DNA_space_types.h" +#include "DNA_userdef_types.h" + +#include "ED_space_api.h" +#include "ED_screen.h" +#include "ED_fileselect.h" + +#include "WM_api.h" +#include "WM_types.h" + +#include "file_intern.h" +#include "filelist.h" +#include "fsmenu.h" + +#include <stdlib.h> +#include <string.h> +#include <stdio.h> + +/* for events */ +#define NOTACTIVE 0 +#define ACTIVATE 1 +#define INACTIVATE 2 + + +static void set_active_file_thumbs(SpaceFile *sfile, FileSelectParams* params, struct ARegion* ar, short mval[]) +{ + float x,y; + int active_file = -1; + int stridex, stridey; + struct direntry* file; + int offsetx, offsety; + int numfiles = filelist_numfiles(params->files); + int columns; + + View2D* v2d = &ar->v2d; + UI_view2d_region_to_view(v2d, mval[0], mval[1], &x, &y); + + offsetx = (x - (v2d->cur.xmin+sfile->tile_border_x))/(sfile->tile_w + sfile->tile_border_x); + offsety = (-y+sfile->tile_border_y)/(sfile->tile_h + sfile->tile_border_y); + columns = (v2d->cur.xmax - v2d->cur.xmin) / (sfile->tile_w+ sfile->tile_border_x); + + printf("tile (%d, %d, %d)\n", offsetx, offsety, columns); + active_file = offsetx + columns*offsety; + + if (active_file >= 0 && active_file < numfiles ) + { + printf("active file: %d\n", active_file); + params->active_file = active_file; + if (params->selstate & ACTIVATE) { + file = filelist_file(params->files, params->active_file); + printf("active file: %s\n", file->relname); + file->flags |= ACTIVE; + } + } +} + + +static void set_active_file(SpaceFile *sfile, FileSelectParams* params, struct ARegion* ar, short mval[]) +{ + int offsetx, offsety; + float x,y; + int active_file = -1; + int numfiles = filelist_numfiles(params->files); + int rows; + struct direntry* file; + + View2D* v2d = &ar->v2d; + UI_view2d_region_to_view(v2d, mval[0], mval[1], &x, &y); + + offsetx = (x-sfile->tile_border_x)/(sfile->tile_w + sfile->tile_border_x); + offsety = (v2d->cur.ymax-y-sfile->tile_border_y)/(sfile->tile_h + sfile->tile_border_y); + rows = (v2d->cur.ymax - v2d->cur.ymin - 2*sfile->tile_border_y) / (sfile->tile_h+sfile->tile_border_y); + active_file = rows*offsetx + offsety; + printf("offsets (%d, %d)\n", offsetx, offsety); + printf("active_file (%d)\n", active_file); + if ( (active_file >= 0) && (active_file < numfiles) ) + { + params->active_file = active_file; + if (params->selstate & ACTIVATE) { + file = filelist_file(params->files, params->active_file); + file->flags |= ACTIVE; + } + } +} + + +static void set_active_bookmark(SpaceFile *sfile, FileSelectParams* params, struct ARegion* ar, short y) +{ + int nentries = fsmenu_get_nentries(); + short posy = ar->v2d.mask.ymax - TILE_BORDER_Y - y; + params->active_bookmark = ((float)posy / (U.fontsize*3.0f/2.0f)); + printf("active bookmark: %d\n", params->active_bookmark); + if (params->active_bookmark < 0 || params->active_bookmark > nentries) { + params->active_bookmark = -1; + } +} + +static void mouse_select(SpaceFile* sfile, FileSelectParams* params, ARegion* ar, short *mval) +{ + int numfiles = filelist_numfiles(params->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; + if (params->display) { + set_active_file_thumbs(sfile, params, ar, mval); + } else { + 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); + + if(file && S_ISDIR(file->type)) { + /* the path is too long and we are not going up! */ + if (strcmp(file->relname, ".") && + strcmp(file->relname, "..") && + strlen(params->dir) + strlen(file->relname) >= FILE_MAX ) + { + // XXX error("Path too long, cannot enter this directory"); + } else { + if (strcmp(file->relname, "..")==0) { + /* avoids /../../ */ + BLI_parent_dir(params->dir); + } else { + strcat(params->dir, file->relname); + strcat(params->dir,"/"); + params->file[0] = '\0'; + BLI_cleanup_dir(G.sce, params->dir); + } + filelist_setdir(params->files, params->dir); + filelist_free(params->files); + params->active_file = -1; + } + } + else if (file) + { + if (file->relname) { + BLI_strncpy(params->file, file->relname, FILE_MAXFILE); + /* XXX + if(event==MIDDLEMOUSE && filelist_gettype(sfile->files)) + imasel_execute(sfile); + */ + } + + } + /* XXX + if(BIF_filelist_gettype(sfile->files)==FILE_MAIN) { + active_imasel_object(sfile); + } + */ + } + } +} + +static void mouse_select_bookmark(SpaceFile* sfile, ARegion* ar, short *mval) +{ + 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) { + int nentries = fsmenu_get_nentries(); + char *selected; + printf("selecting...\n"); + set_active_bookmark(sfile, sfile->params, ar, mval[1]); + selected= fsmenu_get_entry(sfile->params->active_bookmark); + /* which string */ + if (selected) { + 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); + params->file[0] = '\0'; + params->active_file = -1; + } + } +} + +static int file_select_invoke(bContext *C, wmOperator *op, wmEvent *event) +{ + ScrArea *sa= CTX_wm_area(C); + ARegion *ar= CTX_wm_region(C); + 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); + WM_event_add_notifier(C, NC_WINDOW, 0, NULL); + return OPERATOR_FINISHED; +} + + +void ED_FILE_OT_select(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Activate/Select File"; + ot->idname= "ED_FILE_OT_select"; + + /* api callbacks */ + ot->invoke= file_select_invoke; + ot->poll= ED_operator_file_active; +} + + +static int bookmark_select_invoke(bContext *C, wmOperator *op, wmEvent *event) +{ + ScrArea *sa= CTX_wm_area(C); + ARegion *ar= CTX_wm_region(C); + 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); + ED_area_tag_redraw(sa); + return OPERATOR_FINISHED; +} + +void ED_FILE_OT_select_bookmark(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Select Directory"; + ot->idname= "ED_FILE_OT_select_bookmark"; + + /* api callbacks */ + ot->invoke= bookmark_select_invoke; + ot->poll= ED_operator_file_active; +}
\ No newline at end of file diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c index 5b5ff95d37c..f03ea8d9456 100644 --- a/source/blender/editors/space_file/filelist.c +++ b/source/blender/editors/space_file/filelist.c @@ -72,13 +72,14 @@ #include "DNA_scene_types.h" #include "DNA_userdef_types.h" +#include "ED_datafiles.h" + #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" #include "IMB_thumbs.h" #include "PIL_time.h" -#include "ED_datafiles.h" #include "filelist.h" @@ -908,7 +909,7 @@ void filelist_from_library(struct FileList* filelist) void filelist_append_library(struct FileList *filelist, char *dir, char *file, short flag, int idcode, struct Main *mainvar, struct Scene* scene) { // XXX todo: replace NULL with op->reports - BLO_library_append_(&filelist->libfiledata, filelist->filelist, filelist->numfiles, dir, file, flag, idcode, mainvar, scene, NULL); + BLO_library_append(&filelist->libfiledata, filelist->filelist, filelist->numfiles, dir, file, flag, idcode, mainvar, scene, NULL); } void filelist_from_main(struct FileList *filelist) diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c index ea20758884d..9e991fc861e 100644 --- a/source/blender/editors/space_file/filesel.c +++ b/source/blender/editors/space_file/filesel.c @@ -56,9 +56,11 @@ #include "BKE_context.h" #include "BKE_screen.h" +#include "BKE_global.h" #include "ED_screen.h" #include "ED_util.h" +#include "ED_fileselect.h" #include "WM_api.h" #include "WM_types.h" @@ -71,22 +73,78 @@ #include "UI_view2d.h" #include "file_intern.h" +#include "filelist.h" -void freefilelist(SpaceFile *sfile) +FileSelectParams* ED_fileselect_get_params(const struct bContext *C) { - int num; - - num= sfile->totfile-1; + SpaceLink *sl= CTX_wm_space_data(C); + SpaceFile *sfile; + FileSelectParams *params = 0; + + if (sl->spacetype == SPACE_FILE) { + sfile= (SpaceFile*)sl; + params = sfile->params; + } + return params; +} + +short ED_fileselect_set_params(const struct bContext *C, int type, const char *title, const char *path, + short flag, short display, short filter) +{ + char group[32], name[FILE_MAX], temp[FILE_MAX], dir[FILE_MAX], file[FILE_MAX]; + SpaceLink *sl= CTX_wm_space_data(C); + SpaceFile *sfile; + FileSelectParams *params; + + if (sl->spacetype != SPACE_FILE) { + return 0; + } + sfile= (SpaceFile*)sl; + + if (!sfile->params) { + sfile->params = MEM_callocN(sizeof(FileSelectParams), "fileselparams"); + sfile->params->files = filelist_new(); + } + params = sfile->params; + + params->type = type; + params->flag = flag; + params->display = display; + params->filter = filter; + + BLI_strncpy(params->title, title, sizeof(params->title)); - if (sfile->filelist==0) return; + BLI_strncpy(name, path, sizeof(name)); + BLI_convertstringcode(name, G.sce); - for(; num>=0; num--){ - MEM_freeN(sfile->filelist[num].relname); - - if (sfile->filelist[num].string) MEM_freeN(sfile->filelist[num].string); + switch(type) { + case FILE_MAIN: + break; + case FILE_LOADLIB: + 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 */ + + filelist_settype(params->files, type); + filelist_setdir(params->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); + } + } + break; } - free(sfile->filelist); - sfile->filelist= 0; + + return 1; } diff --git a/source/blender/editors/space_file/fsmenu.c b/source/blender/editors/space_file/fsmenu.c index da363cf4071..b4b2688ed7b 100644 --- a/source/blender/editors/space_file/fsmenu.c +++ b/source/blender/editors/space_file/fsmenu.c @@ -22,13 +22,14 @@ * * The Original Code is: all of this file. * - * Contributor(s): none yet. + * Contributor(s): Andrea Weikert (c) 2008 Blender Foundation. * * ***** END GPL LICENSE BLOCK ***** */ #include <stdlib.h> #include <string.h> +#include <stdio.h> #include <math.h> #include "MEM_guardedalloc.h" @@ -37,6 +38,14 @@ #include "BLI_linklist.h" #include "BLI_dynstr.h" +#ifdef WIN32 +#include <windows.h> /* need to include windows.h so _WIN32_IE is defined */ +#ifndef _WIN32_IE +#define _WIN32_IE 0x0400 /* minimal requirements for SHGetSpecialFolderPath on MINGW MSVC has this defined already */ +#endif +#include <shlobj.h> /* for SHGetSpecialFolderPath, has to be done before BLI_winstuff because 'near' is disabled through BLI_windstuff */ +#include "BLI_winstuff.h" +#endif #include "fsmenu.h" /* include ourselves */ @@ -64,7 +73,7 @@ int fsmenu_get_nentries(void) return count; } -int fsmenu_is_entry_a_seperator(int idx) +int fsmenu_is_entry_a_separator(int idx) { FSMenuEntry *fsme; @@ -233,6 +242,60 @@ void fsmenu_write_file(const char *filename) fclose(fp); } +void fsmenu_read_file(const char *filename) +{ + char line[256]; + FILE *fp; + + #ifdef WIN32 + /* Add the drive names to the listing */ + { + __int64 tmp; + char folder[256]; + char tmps[4]; + int i; + + tmp= GetLogicalDrives(); + + for (i=2; i < 26; i++) { + if ((tmp>>i) & 1) { + tmps[0]='a'+i; + tmps[1]=':'; + tmps[2]='\\'; + tmps[3]=0; + + fsmenu_insert_entry(tmps, 0, 0); + } + } + + /* Adding Desktop and My Documents */ + fsmenu_append_separator(); + + SHGetSpecialFolderPath(0, folder, CSIDL_PERSONAL, 0); + fsmenu_insert_entry(folder, 0, 0); + SHGetSpecialFolderPath(0, folder, CSIDL_DESKTOPDIRECTORY, 0); + fsmenu_insert_entry(folder, 0, 0); + + fsmenu_append_separator(); + } +#endif + + fp = fopen(filename, "w"); + if (!fp) return; + + while ( fgets ( line, 256, fp ) != NULL ) /* read a line */ + { + int len = strlen(line); + if (len>0) { + if (line[len-1] == '\n') { + line[len-1] = '\0'; + } + fsmenu_insert_entry(line, 0, 1); + } + } + fclose(fp); +} + void fsmenu_free(void) { FSMenuEntry *fsme= fsmenu; diff --git a/source/blender/editors/space_file/fsmenu.h b/source/blender/editors/space_file/fsmenu.h index 7cd7f78a363..f4291673a3e 100644 --- a/source/blender/editors/space_file/fsmenu.h +++ b/source/blender/editors/space_file/fsmenu.h @@ -37,10 +37,10 @@ int fsmenu_get_nentries (void); /** Returns true if the fsmenu entry at @a index exists and * is a seperator. */ -int fsmenu_is_entry_a_seperator (int index); +int fsmenu_is_entry_a_separator (int index); /** Returns the fsmenu entry at @a index (or NULL if a bad index) - * or a seperator. + * or a separator. */ char* fsmenu_get_entry (int index); @@ -63,8 +63,11 @@ void fsmenu_insert_entry (char *path, int sorted, short save); /** Removes the fsmenu entry at the given @a index. */ void fsmenu_remove_entry (int index); - /** saves the 'favourites' to the specified file */ + /** saves the 'bookmarks' to the specified file */ void fsmenu_write_file(const char *filename); + + /** reads the 'bookmarks' from the specified file */ +void fsmenu_read_file(const char *filename); /** Free's all the memory associated with the fsmenu */ void fsmenu_free (void); diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c index 3d20dbe39a1..f5e7ffa7773 100644 --- a/source/blender/editors/space_file/space_file.c +++ b/source/blender/editors/space_file/space_file.c @@ -48,6 +48,7 @@ #include "ED_space_api.h" #include "ED_screen.h" +#include "ED_fileselect.h" #include "BIF_gl.h" @@ -59,8 +60,11 @@ #include "UI_view2d.h" #include "ED_markers.h" +#include "ED_fileselect.h" #include "file_intern.h" // own include +#include "fsmenu.h" +#include "filelist.h" /* ******************** default callbacks for file space ***************** */ @@ -70,27 +74,50 @@ static SpaceLink *file_new(const bContext *C) SpaceFile *sfile; sfile= MEM_callocN(sizeof(SpaceFile), "initfile"); - sfile->spacetype= SPACE_FILE; - + sfile->spacetype= SPACE_FILE; + sfile->params= MEM_callocN(sizeof(FileSelectParams), "fileselparams"); + sfile->params->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; + */ + /* header */ ar= MEM_callocN(sizeof(ARegion), "header for file"); - BLI_addtail(&sfile->regionbase, ar); ar->regiontype= RGN_TYPE_HEADER; ar->alignment= RGN_ALIGN_BOTTOM; - + + /* channel list region */ + ar= MEM_callocN(sizeof(ARegion), "channel area for file"); + BLI_addtail(&sfile->regionbase, ar); + ar->regiontype= RGN_TYPE_CHANNELS; + ar->alignment= RGN_ALIGN_LEFT; + + /* ui list region */ + ar= MEM_callocN(sizeof(ARegion), "ui area for file"); + BLI_addtail(&sfile->regionbase, ar); + ar->regiontype= RGN_TYPE_UI; + ar->alignment= RGN_ALIGN_TOP; + /* main area */ ar= MEM_callocN(sizeof(ARegion), "main area for file"); - BLI_addtail(&sfile->regionbase, ar); ar->regiontype= RGN_TYPE_WINDOW; - - /* channel list region XXX */ + ar->v2d.scroll = (V2D_SCROLL_RIGHT | V2D_SCROLL_BOTTOM); + ar->v2d.align = (V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_POS_Y); + ar->v2d.keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_KEEPZOOM|V2D_KEEPASPECT); + ar->v2d.keeptot= V2D_KEEPTOT_STRICT; + ar->v2d.minzoom= ar->v2d.maxzoom= 1.0f; - return (SpaceLink *)sfile; } @@ -98,21 +125,26 @@ static SpaceLink *file_new(const bContext *C) static void file_free(SpaceLink *sl) { SpaceFile *sfile= (SpaceFile *) sl; - - if(sfile->libfiledata) - BLO_blendhandle_close(sfile->libfiledata); - if(sfile->filelist) - freefilelist(sfile); - if(sfile->pupmenu) - MEM_freeN(sfile->pupmenu); + + 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->params->pupmenu) + MEM_freeN(sfile->params->pupmenu); + MEM_freeN(sfile->params); + sfile->params = 0; + } } /* spacetype; init callback */ static void file_init(struct wmWindowManager *wm, ScrArea *sa) -{ - +{ } static SpaceLink *file_duplicate(SpaceLink *sl) @@ -141,34 +173,103 @@ 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 (filelist_empty(params->files)) + { + unsigned int filter = 0; + filelist_hidedot(params->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); + + if(params->sort!=FILE_SORTALPHA) filelist_sort(params->files, params->sort); + } + + /* clear and setup matrix */ UI_GetThemeColor3fv(TH_BACK, col); glClearColor(col[0], col[1], col[2], 0.0); glClear(GL_COLOR_BUFFER_BIT); - UI_view2d_view_ortho(C, v2d); - + file_calc_previews(C,ar); + + /* data... */ + UI_view2d_view_ortho(C, v2d); + + if (params->display) { + file_draw_previews(C, ar); + } else { + file_draw_list(C, ar); + } /* reset view matrix */ UI_view2d_view_restore(C); - /* scrollers? */ + /* scrollers */ + scrollers= UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY); + UI_view2d_scrollers_draw(C, v2d, scrollers); + UI_view2d_scrollers_free(scrollers); + } void file_operatortypes(void) { - + WM_operatortype_append(ED_FILE_OT_select); + WM_operatortype_append(ED_FILE_OT_select_bookmark); } void file_keymap(struct wmWindowManager *wm) { - + ListBase *keymap= WM_keymap_listbase(wm, "File", SPACE_FILE, 0); + WM_keymap_add_item(keymap, "ED_FILE_OT_select", SELECTMOUSE, KM_PRESS, 0, 0); + + keymap= WM_keymap_listbase(wm, "FileBookmark", SPACE_FILE, 0); + WM_keymap_add_item(keymap, "ED_FILE_OT_select_bookmark", SELECTMOUSE, KM_PRESS, 0, 0); +} + + +static void file_channel_area_init(wmWindowManager *wm, ARegion *ar) +{ + ListBase *keymap; + + UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_LIST, ar->winx, ar->winy); + + /* own keymap */ + keymap= WM_keymap_listbase(wm, "FileBookmark", SPACE_FILE, 0); + WM_event_add_keymap_handler_bb(&ar->handlers, keymap, NULL, NULL); +} + +static void file_channel_area_draw(const bContext *C, ARegion *ar) +{ + View2D *v2d= &ar->v2d; + float col[3]; + + UI_GetThemeColor3fv(TH_BACK, col); + glClearColor(col[0], col[1], col[2], 0.0); + glClear(GL_COLOR_BUFFER_BIT); + + /* data... */ + UI_view2d_view_ortho(C, v2d); + + file_draw_fsmenu(C, ar); } /* add handlers, stuff you only do once or on area/region changes */ @@ -199,6 +300,28 @@ static void file_header_area_draw(const bContext *C, ARegion *ar) UI_view2d_view_restore(C); } +/* add handlers, stuff you only do once or on area/region changes */ +static void file_ui_area_init(wmWindowManager *wm, ARegion *ar) +{ + UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy); +} + +static void file_ui_area_draw(const bContext *C, ARegion *ar) +{ + float col[3]; + /* clear */ + UI_GetThemeColor3fv(TH_BACK, col); + glClearColor(col[0], col[1], col[2], 0.0); + glClear(GL_COLOR_BUFFER_BIT); + + /* set view2d view matrix for scrolling (without scrollers) */ + UI_view2d_view_ortho(C, &ar->v2d); + + file_draw_buttons(C, ar); + + UI_view2d_view_restore(C); +} + static void file_main_area_listener(ARegion *ar, wmNotifier *wmn) { /* context changes */ @@ -224,9 +347,8 @@ void ED_spacetype_file(void) art->regionid = RGN_TYPE_WINDOW; art->init= file_main_area_init; art->draw= file_main_area_draw; - art->listener= file_main_area_listener; - art->keymapflag= ED_KEYMAP_VIEW2D; - + // art->listener= file_main_area_listener; + art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D; BLI_addhead(&st->regiontypes, art); /* regions: header */ @@ -234,24 +356,42 @@ void ED_spacetype_file(void) art->regionid = RGN_TYPE_HEADER; art->minsizey= HEADERY; art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D; - art->init= file_header_area_init; art->draw= file_header_area_draw; - BLI_addhead(&st->regiontypes, art); - /* regions: channels */ + /* regions: ui */ + art= MEM_callocN(sizeof(ARegionType), "spacetype file region"); + art->regionid = RGN_TYPE_UI; + art->minsizey= 100; + art->keymapflag= ED_KEYMAP_UI; + art->init= file_ui_area_init; + art->draw= file_ui_area_draw; + BLI_addhead(&st->regiontypes, art); + + /* regions: channels (directories) */ art= MEM_callocN(sizeof(ARegionType), "spacetype file region"); art->regionid = RGN_TYPE_CHANNELS; - art->minsizex= 80; + art->minsizex= 200; art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D; - -// art->init= file_channel_area_init; -// art->draw= file_channel_area_draw; - + art->init= file_channel_area_init; + art->draw= file_channel_area_draw; BLI_addhead(&st->regiontypes, art); - BKE_spacetype_register(st); + } +void ED_file_init(void) +{ + char name[FILE_MAX]; + BLI_make_file_string("/", name, BLI_gethome(), ".Bfs"); + fsmenu_read_file(name); + filelist_init_icons(); +} + +void ED_file_exit(void) +{ + fsmenu_free(); + filelist_free_icons(); +}
\ No newline at end of file |