diff options
author | Andrea Weikert <elubie@gmx.net> | 2009-03-14 16:12:11 +0300 |
---|---|---|
committer | Andrea Weikert <elubie@gmx.net> | 2009-03-14 16:12:11 +0300 |
commit | b907b9fd9b625bacb4500fb21b791bb109e1d10d (patch) | |
tree | 9e1b06a9d8137e552f7a0bd04905aba7fbafdf29 /source/blender/editors/space_file | |
parent | 2aa71b42266a2b1ad278eba0a343f6008a0d1418 (diff) |
2.5 filebrowser
* added filter buttons to header
* changed large icon for movie files to match small icon
* fixed small stack corruption in interface_draw.c (Matt, check if this is ok)
* moved nice display of file size to storage.c, where string is created.
Diffstat (limited to 'source/blender/editors/space_file')
-rw-r--r-- | source/blender/editors/space_file/file_draw.c | 58 | ||||
-rw-r--r-- | source/blender/editors/space_file/file_header.c | 29 | ||||
-rw-r--r-- | source/blender/editors/space_file/filelist.c | 6 |
3 files changed, 37 insertions, 56 deletions
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c index c532a18f54e..bf71f2294c0 100644 --- a/source/blender/editors/space_file/file_draw.c +++ b/source/blender/editors/space_file/file_draw.c @@ -190,8 +190,6 @@ static void draw_tile(short sx, short sy, short width, short height, int colorid #define FILE_SHORTEN_END 0 #define FILE_SHORTEN_FRONT 1 -#define FILE_SHORTEN_FSIZE 2 -#define FILE_SHORTEN_FSIZE_WIDTHONLY 3 static float shorten_string(char* string, float w, int flag) { @@ -235,50 +233,6 @@ static float shorten_string(char* string, float w, int flag) return sw; } -static float shorten_filesize(char* string, int flag) -{ - float sw = 0; - char tmp[FILE_MAX]; - int slen = strlen(string); - char *s = string; - int i; - float size; - - /* note: - * input file size is stored as a string, 15 chars long including - * whitespace at the start, and spaces in between sections. - * i.e. the maximum size is 999 999 999 999 bytes. - */ - - /* get rid of whitespace and convert to a float representing size in bytes */ - for (i=0; i < slen; i++) { - s++; - if (s[0] != ' ') - strncat(tmp, s, 1); - } - size = atof(tmp); - - if (size > 1024*1024*1024) { - sprintf(tmp, "%.2f GB", size/(1024*1024*1024)); - } - else if (size > 1024*1024) { - sprintf(tmp, "%.1f MB", size/(1024*1024)); - } - else if (size > 1024) { - sprintf(tmp, "%d KB", (int)(size/1024)); - } - else { - sprintf(tmp, "%d B", (int)size); - } - - sw = UI_GetStringWidth(G.font, tmp, 0); - - if (flag != FILE_SHORTEN_FSIZE_WIDTHONLY) - strcpy(string, tmp); - - return sw; -} - static int get_file_icon(struct direntry *file) { if (file->type & S_IFDIR) @@ -324,11 +278,8 @@ static void file_draw_string(short sx, short sy, const char* string, short width float x,y; BLI_strncpy(fname,string, FILE_MAXFILE); - if (ELEM(flag, FILE_SHORTEN_END, FILE_SHORTEN_FRONT)) - sw = shorten_string(fname, width, flag ); - else if (flag == FILE_SHORTEN_FSIZE) - sw = shorten_filesize(fname, flag); - + sw = shorten_string(fname, width, flag ); + soffs = (width - sw) / 2; x = (float)(sx); y = (float)(sy-height); @@ -552,13 +503,14 @@ void file_draw_list(const bContext *C, ARegion *ar) UI_ThemeColor4(TH_TEXT); - sw = shorten_filesize(file->size, FILE_SHORTEN_FSIZE_WIDTHONLY); + // sw = shorten_filesize(file->size, FILE_SHORTEN_FSIZE_WIDTHONLY); + sw = UI_GetStringWidth(G.font, file->size, 0); file_draw_string(spos, sy, file->relname, layout->tile_w - sw - 5, layout->tile_h, FILE_SHORTEN_END); spos += filelist_maxnamelen(sfile->files); if (params->display == FILE_SHOWSHORT) { if (!(file->type & S_IFDIR)) - file_draw_string(sx + layout->tile_w - layout->tile_border_x - sw, sy, file->size, sw, layout->tile_h, FILE_SHORTEN_FSIZE); + file_draw_string(sx + layout->tile_w - layout->tile_border_x - sw, sy, file->size, sw, layout->tile_h, FILE_SHORTEN_END); } else { #if 0 // XXX TODO: add this for non-windows systems /* rwx rwx rwx */ diff --git a/source/blender/editors/space_file/file_header.c b/source/blender/editors/space_file/file_header.c index b967e21c99c..b9d6c7f7c10 100644 --- a/source/blender/editors/space_file/file_header.c +++ b/source/blender/editors/space_file/file_header.c @@ -63,7 +63,7 @@ #define B_SORTIMASELLIST 1 #define B_RELOADIMASELDIR 2 - +#define B_FILTERIMASELDIR 3 /* ************************ header area region *********************** */ @@ -108,6 +108,17 @@ static void do_file_header_buttons(bContext *C, void *arg, int event) case B_RELOADIMASELDIR: WM_event_add_notifier(C, NC_WINDOW, NULL); break; + case B_FILTERIMASELDIR: + if(sfile->params) { + if (sfile->params->flag & FILE_FILTER) { + filelist_setfilter(sfile->files,sfile->params->filter); + filelist_filter(sfile->files); + } else { + filelist_setfilter(sfile->files,0); + filelist_filter(sfile->files); + } + } + WM_event_add_notifier(C, NC_WINDOW, NULL); } } @@ -180,6 +191,22 @@ void file_header_buttons(const bContext *C, ARegion *ar) } */ + uiDefIconButBitS(block, TOG, FILE_FILTER, B_FILTERIMASELDIR, ICON_FILTER,xco+=XIC,0,XIC,YIC, ¶ms->flag, 0, 0, 0, 0, "Filter files"); + if (params->flag & FILE_FILTER) { + xco+=4; + uiBlockBeginAlign(block); + uiDefIconButBitS(block, TOG, IMAGEFILE, B_FILTERIMASELDIR, ICON_FILE_IMAGE,xco+=XIC,0,XIC,YIC, ¶ms->filter, 0, 0, 0, 0, "Show images"); + uiDefIconButBitS(block, TOG, BLENDERFILE, B_FILTERIMASELDIR, ICON_FILE_BLEND,xco+=XIC,0,XIC,YIC, ¶ms->filter, 0, 0, 0, 0, "Show .blend files"); + uiDefIconButBitS(block, TOG, MOVIEFILE, B_FILTERIMASELDIR, ICON_FILE_MOVIE,xco+=XIC,0,XIC,YIC, ¶ms->filter, 0, 0, 0, 0, "Show movies"); + uiDefIconButBitS(block, TOG, PYSCRIPTFILE, B_FILTERIMASELDIR, ICON_FILE_SCRIPT,xco+=XIC,0,XIC,YIC, ¶ms->filter, 0, 0, 0, 0, "Show python scripts"); + uiDefIconButBitS(block, TOG, FTFONTFILE, B_FILTERIMASELDIR, ICON_FILE_FONT,xco+=XIC,0,XIC,YIC, ¶ms->filter, 0, 0, 0, 0, "Show fonts"); + uiDefIconButBitS(block, TOG, SOUNDFILE, B_FILTERIMASELDIR, ICON_FILE_SOUND,xco+=XIC,0,XIC,YIC, ¶ms->filter, 0, 0, 0, 0, "Show sound files"); + uiDefIconButBitS(block, TOG, TEXTFILE, B_FILTERIMASELDIR, ICON_FILE_BLANK,xco+=XIC,0,XIC,YIC, ¶ms->filter, 0, 0, 0, 0, "Show text files"); + uiDefIconButBitS(block, TOG, FOLDERFILE, B_FILTERIMASELDIR, ICON_FILE_FOLDER,xco+=XIC,0,XIC,YIC, ¶ms->filter, 0, 0, 0, 0, "Show folders"); + uiBlockEndAlign(block); + xco+=XIC; + } + xcotitle= xco; xco+= UI_GetStringWidth(G.font, params->title, 0); diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c index 2ab43e59e66..2a2aa610f96 100644 --- a/source/blender/editors/space_file/filelist.c +++ b/source/blender/editors/space_file/filelist.c @@ -692,8 +692,10 @@ void filelist_readdir(struct FileList* filelist) for (i=0; (i < filelist->numfiles); ++i) { struct direntry* file = filelist_file(filelist, i); - int len = UI_GetStringWidth(G.font, file->relname,0)+UI_GetStringWidth(G.font, file->size,0); - if (len > filelist->maxnamelen) filelist->maxnamelen = len; + if (file) { + int len = UI_GetStringWidth(G.font, file->relname,0)+UI_GetStringWidth(G.font, file->size,0); + if (len > filelist->maxnamelen) filelist->maxnamelen = len; + } } } |