diff options
Diffstat (limited to 'source/blender/editors/space_file/file_draw.c')
-rw-r--r-- | source/blender/editors/space_file/file_draw.c | 197 |
1 files changed, 80 insertions, 117 deletions
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c index 5f435aa0cbe..041280aaf7e 100644 --- a/source/blender/editors/space_file/file_draw.c +++ b/source/blender/editors/space_file/file_draw.c @@ -1,4 +1,4 @@ -/** +/* * $Id$ * * ***** BEGIN GPL LICENSE BLOCK ***** @@ -26,9 +26,11 @@ * ***** END GPL LICENSE BLOCK ***** */ +#include <math.h> #include <string.h> #include "BLI_blenlib.h" +#include "BLI_utildefines.h" #include "BLI_dynstr.h" #include "BLI_storage_types.h" #ifdef WIN32 @@ -40,6 +42,7 @@ #include "BKE_context.h" #include "BKE_global.h" +#include "BKE_main.h" #include "BLF_api.h" @@ -76,10 +79,10 @@ enum { B_FS_DIRNAME, B_FS_FILENAME -} eFile_ButEvents; +} /*eFile_ButEvents*/; -static void do_file_buttons(bContext *C, void *arg, int event) +static void do_file_buttons(bContext *C, void *UNUSED(arg), int event) { switch(event) { case B_FS_FILENAME: @@ -134,7 +137,7 @@ void file_draw_buttons(const bContext *C, ARegion *ar) ARegion* artmp; /* Initialize UI block. */ - sprintf(name, "win %p", ar); + sprintf(name, "win %p", (void *)ar); block = uiBeginBlock(C, ar, name, UI_EMBOSS); uiBlockSetHandleFunc(block, do_file_buttons, NULL); @@ -172,7 +175,11 @@ void file_draw_buttons(const bContext *C, ARegion *ar) /* Text input fields for directory and file. */ if (available_w > 0) { - but = uiDefBut(block, TEX, B_FS_DIRNAME, "", + int overwrite_alert= file_draw_check_exists(sfile); + /* callbacks for operator check functions */ + uiBlockSetFunc(block, file_draw_check_cb, NULL, NULL); + + but = uiDefButTextO(block, TEX, "FILE_OT_directory", 0, "", min_x, line1_y, line1_w-chan_offs, btn_h, params->dir, 0.0, (float)FILE_MAX-1, 0, 0, "File path."); @@ -182,9 +189,17 @@ void file_draw_buttons(const bContext *C, ARegion *ar) but = uiDefBut(block, TEX, B_FS_FILENAME, "", min_x, line2_y, line2_w-chan_offs, btn_h, params->file, 0.0, (float)FILE_MAXFILE-1, 0, 0, - "File name."); + overwrite_alert ?"File name, overwrite existing." : "File name."); uiButSetCompleteFunc(but, autocomplete_file, NULL); uiButSetFlag(but, UI_BUT_NO_UTF8); + + /* check if this overrides a file and if the operator option is used */ + if(overwrite_alert) { + uiButSetFlag(but, UI_BUT_REDALERT); + } + + /* clear func */ + uiBlockSetFunc(block, NULL, NULL, NULL); } /* Filename number increment / decrement buttons. */ @@ -227,56 +242,6 @@ static void draw_tile(int sx, int sy, int width, int height, int colorid, int sh uiRoundBox(sx, sy - height, sx + width, sy, 5); } -#define FILE_SHORTEN_END 0 -#define FILE_SHORTEN_FRONT 1 - -static float shorten_string(char* string, float w, int flag) -{ - char temp[FILE_MAX]; - short shortened = 0; - float sw = 0; - float pad = 0; - - if (w <= 0) { - *string = '\0'; - return 0.0; - } - - sw = file_string_width(string); - if (flag == FILE_SHORTEN_FRONT) { - char *s = string; - BLI_strncpy(temp, "...", 4); - pad = file_string_width(temp); - while ((*s) && (sw+pad>w)) { - s++; - sw = file_string_width(s); - shortened = 1; - } - if (shortened) { - int slen = strlen(s); - BLI_strncpy(temp+3, s, slen+1); - temp[slen+4] = '\0'; - BLI_strncpy(string, temp, slen+4); - } - } else { - char *s = string; - while (sw>w) { - int slen = strlen(string); - string[slen-1] = '\0'; - sw = file_string_width(s); - shortened = 1; - } - - if (shortened) { - int slen = strlen(string); - if (slen > 3) { - BLI_strncpy(string+slen-3, "...", 4); - } - } - } - - return sw; -} static int get_file_icon(struct direntry *file) { @@ -291,6 +256,8 @@ static int get_file_icon(struct direntry *file) } else if (file->flags & BLENDERFILE) return ICON_FILE_BLEND; + else if (file->flags & BLENDERFILE_BACKUP) + return ICON_FILE_BLEND; else if (file->flags & IMAGEFILE) return ICON_FILE_IMAGE; else if (file->flags & MOVIEFILE) @@ -315,37 +282,37 @@ static void file_draw_icon(uiBlock *block, char *path, int sx, int sy, int icon, { uiBut *but; float x,y; - float alpha=1.0f; + /*float alpha=1.0f;*/ x = (float)(sx); y = (float)(sy-height); - if (icon == ICON_FILE_BLANK) alpha = 0.375f; + /*if (icon == ICON_FILE_BLANK) alpha = 0.375f;*/ but= uiDefIconBut(block, LABEL, 0, icon, x, y, width, height, NULL, 0.0, 0.0, 0, 0, ""); uiButSetDragPath(but, path); } -static void file_draw_string(int sx, int sy, const char* string, float width, int height, int flag) +static void file_draw_string(int sx, int sy, const char* string, float width, int height, short align) { uiStyle *style= U.uistyles.first; - int soffs; + uiFontStyle fs = style->widgetlabel; + rcti rect; char fname[FILE_MAXFILE]; - float sw; - float x,y; + fs.align = align; BLI_strncpy(fname,string, FILE_MAXFILE); - sw = shorten_string(fname, width, flag ); - - soffs = (width - sw) / 2; - x = (float)(sx); - y = (float)(sy-height); + file_shorten_string(fname, width+1.0, 0); - uiStyleFontSet(&style->widget); - BLF_position(style->widget.uifont_id, x, y, 0); - BLF_draw(style->widget.uifont_id, fname); + /* no text clipping needed, uiStyleFontDraw does it but is a bit too strict (for buttons it works) */ + rect.xmin = sx; + rect.xmax = sx + ceil(width+4.0f); + rect.ymin = sy - height; + rect.ymax = sy; + + uiStyleFontDraw(&fs, &rect, fname); } void file_calc_previews(const bContext *C, ARegion *ar) @@ -421,7 +388,7 @@ static void file_draw_preview(uiBlock *block, struct direntry *file, int sx, int } } -static void renamebutton_cb(bContext *C, void *arg1, char *oldname) +static void renamebutton_cb(bContext *C, void *UNUSED(arg1), char *oldname) { char newname[FILE_MAX+12]; char orgname[FILE_MAX+12]; @@ -433,9 +400,9 @@ static void renamebutton_cb(bContext *C, void *arg1, char *oldname) struct direntry *file = (struct direntry *)arg1; #endif - BLI_make_file_string(G.sce, orgname, sfile->params->dir, oldname); + BLI_make_file_string(G.main->name, orgname, sfile->params->dir, oldname); BLI_strncpy(filename, sfile->params->renameedit, sizeof(filename)); - BLI_make_file_string(G.sce, newname, sfile->params->dir, filename); + BLI_make_file_string(G.main->name, newname, sfile->params->dir, filename); if( strcmp(orgname, newname) != 0 ) { if (!BLI_exists(newname)) { @@ -500,9 +467,11 @@ void file_draw_list(const bContext *C, ARegion *ar) int colorid = 0; int sx, sy; int offset; + int textwidth, textheight; int i; - float sw, spos; short is_icon; + short align; + numfiles = filelist_numfiles(files); @@ -525,6 +494,11 @@ void file_draw_list(const bContext *C, ARegion *ar) numfiles_layout += layout->columns; } + textwidth =( FILE_IMGDISPLAY == params->display) ? layout->tile_w : layout->column_widths[COLUMN_NAME]; + textheight = layout->textheight*3.0/2.0 + 0.5; + + align = ( FILE_IMGDISPLAY == params->display) ? UI_STYLE_TEXT_CENTER : UI_STYLE_TEXT_LEFT; + for (i=offset; (i < numfiles) && (i<offset+numfiles_layout); ++i) { ED_fileselect_layout_tilepos(layout, i, &sx, &sy); @@ -535,20 +509,6 @@ void file_draw_list(const bContext *C, ARegion *ar) UI_ThemeColor4(TH_TEXT); - spos = ( FILE_IMGDISPLAY == params->display ) ? sx : sx + ICON_DEFAULT_WIDTH + 4; - - sw = file_string_width(file->relname); - if (file->flags & EDITING) { - int but_width = (FILE_IMGDISPLAY == params->display) ? layout->tile_w : layout->column_widths[COLUMN_NAME]; - - uiBut *but = uiDefBut(block, TEX, 1, "", spos, sy-layout->tile_h-3, - but_width, layout->textheight*2, sfile->params->renameedit, 1.0f, (float)sizeof(sfile->params->renameedit),0,0,""); - uiButSetRenameFunc(but, renamebutton_cb, file); - uiButSetFlag(but, UI_BUT_NO_UTF8); /* allow non utf8 names */ - if ( 0 == uiButActiveOnly(C, block, but)) { - file->flags &= ~EDITING; - } - } if (!(file->flags & EDITING)) { if (params->active_file == i) { @@ -571,58 +531,61 @@ void file_draw_list(const bContext *C, ARegion *ar) } file_draw_preview(block, file, sx, sy, imb, layout, !is_icon && (file->flags & IMAGEFILE)); - } else { file_draw_icon(block, file->path, sx, sy-3, get_file_icon(file), ICON_DEFAULT_WIDTH, ICON_DEFAULT_WIDTH); + sx += ICON_DEFAULT_WIDTH + 4; } UI_ThemeColor4(TH_TEXT); + + if (file->flags & EDITING) { + uiBut *but = uiDefBut(block, TEX, 1, "", sx , sy-layout->tile_h-3, + textwidth, textheight, sfile->params->renameedit, 1.0f, (float)sizeof(sfile->params->renameedit),0,0,""); + uiButSetRenameFunc(but, renamebutton_cb, file); + uiButSetFlag(but, UI_BUT_NO_UTF8); /* allow non utf8 names */ + if ( 0 == uiButActiveOnly(C, block, but)) { + file->flags &= ~EDITING; + } + } + if (!(file->flags & EDITING)) { - float name_width = (FILE_IMGDISPLAY == params->display) ? layout->tile_w : sw; - file_draw_string(spos, sy, file->relname, name_width, layout->tile_h, FILE_SHORTEN_END); + int tpos = (FILE_IMGDISPLAY == params->display) ? sy - layout->tile_h + layout->textheight : sy; + file_draw_string(sx+1, tpos, file->relname, textwidth, textheight, align); } if (params->display == FILE_SHORTDISPLAY) { - spos += layout->column_widths[COLUMN_NAME] + 12; + sx += layout->column_widths[COLUMN_NAME] + 12; if (!(file->type & S_IFDIR)) { - sw = file_string_width(file->size); - file_draw_string(spos, sy, file->size, sw+1, layout->tile_h, FILE_SHORTEN_END); - spos += layout->column_widths[COLUMN_SIZE] + 12; + file_draw_string(sx, sy, file->size, layout->column_widths[COLUMN_SIZE], layout->tile_h, align); + sx += layout->column_widths[COLUMN_SIZE] + 12; } } else if (params->display == FILE_LONGDISPLAY) { - spos += layout->column_widths[COLUMN_NAME] + 12; + sx += layout->column_widths[COLUMN_NAME] + 12; #ifndef WIN32 /* rwx rwx rwx */ - sw = file_string_width(file->mode1); - file_draw_string(spos, sy, file->mode1, sw, layout->tile_h, FILE_SHORTEN_END); - spos += layout->column_widths[COLUMN_MODE1] + 12; + file_draw_string(sx, sy, file->mode1, layout->column_widths[COLUMN_MODE1], layout->tile_h, align); + sx += layout->column_widths[COLUMN_MODE1] + 12; - sw = file_string_width(file->mode2); - file_draw_string(spos, sy, file->mode2, sw, layout->tile_h, FILE_SHORTEN_END); - spos += layout->column_widths[COLUMN_MODE2] + 12; + file_draw_string(sx, sy, file->mode2, layout->column_widths[COLUMN_MODE2], layout->tile_h, align); + sx += layout->column_widths[COLUMN_MODE2] + 12; - sw = file_string_width(file->mode3); - file_draw_string(spos, sy, file->mode3, sw, layout->tile_h, FILE_SHORTEN_END); - spos += layout->column_widths[COLUMN_MODE3] + 12; + file_draw_string(sx, sy, file->mode3, layout->column_widths[COLUMN_MODE3], layout->tile_h, align); + sx += layout->column_widths[COLUMN_MODE3] + 12; - sw = file_string_width(file->owner); - file_draw_string(spos, sy, file->owner, sw, layout->tile_h, FILE_SHORTEN_END); - spos += layout->column_widths[COLUMN_OWNER] + 12; + file_draw_string(sx, sy, file->owner, layout->column_widths[COLUMN_OWNER] , layout->tile_h, align); + sx += layout->column_widths[COLUMN_OWNER] + 12; #endif - sw = file_string_width(file->date); - file_draw_string(spos, sy, file->date, sw, layout->tile_h, FILE_SHORTEN_END); - spos += layout->column_widths[COLUMN_DATE] + 12; + file_draw_string(sx, sy, file->date, layout->column_widths[COLUMN_DATE], layout->tile_h, align); + sx += layout->column_widths[COLUMN_DATE] + 12; - sw = file_string_width(file->time); - file_draw_string(spos, sy, file->time, sw, layout->tile_h, FILE_SHORTEN_END); - spos += layout->column_widths[COLUMN_TIME] + 12; + file_draw_string(sx, sy, file->time, layout->column_widths[COLUMN_TIME] , layout->tile_h, align); + sx += layout->column_widths[COLUMN_TIME] + 12; if (!(file->type & S_IFDIR)) { - sw = file_string_width(file->size); - file_draw_string(spos, sy, file->size, sw, layout->tile_h, FILE_SHORTEN_END); - spos += layout->column_widths[COLUMN_SIZE] + 12; + file_draw_string(sx, sy, file->size, layout->column_widths[COLUMN_SIZE], layout->tile_h, align); + sx += layout->column_widths[COLUMN_SIZE] + 12; } } } |