diff options
Diffstat (limited to 'source/blender/editors/space_file')
-rw-r--r-- | source/blender/editors/space_file/Makefile | 2 | ||||
-rw-r--r-- | source/blender/editors/space_file/file_draw.c | 223 | ||||
-rw-r--r-- | source/blender/editors/space_file/file_header.c | 187 | ||||
-rw-r--r-- | source/blender/editors/space_file/file_intern.h | 32 | ||||
-rw-r--r-- | source/blender/editors/space_file/file_ops.c | 465 | ||||
-rw-r--r-- | source/blender/editors/space_file/file_panels.c | 164 | ||||
-rw-r--r-- | source/blender/editors/space_file/filelist.c | 96 | ||||
-rw-r--r-- | source/blender/editors/space_file/filelist.h | 7 | ||||
-rw-r--r-- | source/blender/editors/space_file/filesel.c | 104 | ||||
-rw-r--r-- | source/blender/editors/space_file/fsmenu.c | 39 | ||||
-rw-r--r-- | source/blender/editors/space_file/fsmenu.h | 13 | ||||
-rw-r--r-- | source/blender/editors/space_file/space_file.c | 212 | ||||
-rw-r--r-- | source/blender/editors/space_file/writeimage.c | 3 |
13 files changed, 1018 insertions, 529 deletions
diff --git a/source/blender/editors/space_file/Makefile b/source/blender/editors/space_file/Makefile index 8f48217473c..2f4180448e5 100644 --- a/source/blender/editors/space_file/Makefile +++ b/source/blender/editors/space_file/Makefile @@ -1,5 +1,5 @@ # -# $Id: Makefile 14 2002-10-13 15:57:19Z hans $ +# $Id$ # # ***** BEGIN GPL LICENSE BLOCK ***** # diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c index 6ed8f87d987..339ebe27fcd 100644 --- a/source/blender/editors/space_file/file_draw.c +++ b/source/blender/editors/space_file/file_draw.c @@ -90,6 +90,8 @@ enum { B_FS_EXEC, B_FS_CANCEL, B_FS_PARENT, + B_FS_DIRNAME, + B_FS_FILENAME } eFile_ButEvents; @@ -105,68 +107,130 @@ static void do_file_buttons(bContext *C, void *arg, int event) case B_FS_PARENT: file_parent_exec(C, NULL); /* file_ops.c */ break; + case B_FS_FILENAME: + file_filename_exec(C, NULL); + break; + case B_FS_DIRNAME: + file_directory_exec(C, NULL); + break; } } -/* note; this function uses pixelspace (0, 0, winx, winy), not view2d */ +/* Note: This function uses pixelspace (0, 0, winx, winy), not view2d. + * The controls are laid out as follows: + * + * ------------------------------------------- + * | Directory input | execute | + * ------------------------------------------- + * | Filename input | + | - | cancel | + * ------------------------------------------- + * + * The input widgets will stretch to fill any excess space. + * When there isn't enough space for all controls to be shown, they are + * hidden in this order: x/-, execute/cancel, input widgets. + */ void file_draw_buttons(const bContext *C, ARegion *ar) { - SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C); + /* Button layout. */ + const short min_x = 10; + const short max_x = ar->winx - 10; + const short line2_y = ar->winy - IMASEL_BUTTONS_HEIGHT - 12; + const short line1_y = line2_y + IMASEL_BUTTONS_HEIGHT/2 + 4; + const short input_minw = 20; + const short btn_h = UI_UNIT_Y; + const short btn_fn_w = UI_UNIT_X; + const short btn_minw = 80; + const short btn_margin = 20; + const short separator = 4; + + /* Additional locals. */ + char name[20]; + short loadbutton; + short fnumbuttons; + short available_w = max_x - min_x; + short line1_w = available_w; + short line2_w = available_w; + + uiBut* but; + uiBlock* block; + SpaceFile* sfile = (SpaceFile*) CTX_wm_space_data(C); FileSelectParams* params = ED_fileselect_get_params(sfile); - uiBlock *block; - int loadbutton; - char name[20]; - float slen; - int filebuty1, filebuty2; - - float xmin = 8; - float xmax = ar->winx - 10; - - filebuty1= ar->winy - IMASEL_BUTTONS_HEIGHT - 12; - filebuty2= filebuty1 + IMASEL_BUTTONS_HEIGHT/2 + 4; - - /* HEADER */ + + /* Initialize UI block. */ sprintf(name, "win %p", ar); block = uiBeginBlock(C, ar, name, UI_EMBOSS); uiBlockSetHandleFunc(block, do_file_buttons, NULL); - - /* XXXX - uiSetButLock( filelist_gettype(simasel->files)==FILE_MAIN && simasel->returnfunc, NULL); - */ - - /* space available for load/save buttons? */ - slen = UI_GetStringWidth(sfile->params->title); - loadbutton= slen > 60 ? slen + 20 : MAX2(80, 20+UI_GetStringWidth(params->title)); - if(ar->winx > loadbutton+20) { - if(params->title[0]==0) { - loadbutton= 0; - } + + /* Is there enough space for the execute / cancel buttons? */ + loadbutton = UI_GetStringWidth(sfile->params->title) + btn_margin; + if (loadbutton < btn_minw) { + loadbutton = MAX2(btn_minw, + btn_margin + UI_GetStringWidth(params->title)); } - else { - loadbutton= 0; + + if (available_w <= loadbutton + separator + input_minw + || params->title[0] == 0) { + loadbutton = 0; + } else { + line1_w -= (loadbutton + separator); + line2_w = line1_w; } - uiDefBut(block, TEX, 0 /* XXX B_FS_FILENAME */,"", xmin+2, filebuty1, xmax-xmin-loadbutton-4, 21, params->file, 0.0, (float)FILE_MAXFILE-1, 0, 0, ""); - uiDefBut(block, TEX, 0 /* XXX B_FS_DIRNAME */,"", xmin+2, filebuty2, xmax-xmin-loadbutton-4, 21, params->dir, 0.0, (float)FILE_MAXFILE-1, 0, 0, ""); + /* Is there enough space for file number increment/decrement buttons? */ + fnumbuttons = 2 * btn_fn_w; + if (!loadbutton || line2_w <= fnumbuttons + separator + input_minw) { + fnumbuttons = 0; + } else { + line2_w -= (fnumbuttons + separator); + } + + /* Text input fields for directory and file. */ + if (available_w > 0) { + but = uiDefBut(block, TEX, B_FS_DIRNAME, "", + min_x, line1_y, line1_w, btn_h, + params->dir, 0.0, (float)FILE_MAXDIR-1, 0, 0, + "File path."); + uiButSetCompleteFunc(but, autocomplete_directory, NULL); + uiDefBut(block, TEX, B_FS_FILENAME, "", + min_x, line2_y, line2_w, btn_h, + params->file, 0.0, (float)FILE_MAXFILE-1, 0, 0, + "File name."); + } + /* Filename number increment / decrement buttons. */ + if (fnumbuttons) { + uiBlockBeginAlign(block); + but = uiDefIconButO(block, BUT, "FILE_OT_filenum", 0, ICON_ZOOMOUT, + min_x + line2_w + separator, line2_y, + btn_fn_w, btn_h, + "Decrement the filename number."); + RNA_int_set(uiButGetOperatorPtrRNA(but), "increment", -1); + + but = uiDefIconButO(block, BUT, "FILE_OT_filenum", 0, ICON_ZOOMIN, + min_x + line2_w + separator + btn_fn_w, line2_y, + btn_fn_w, btn_h, + "Increment the filename number."); + RNA_int_set(uiButGetOperatorPtrRNA(but), "increment", 1); + uiBlockEndAlign(block); + } + + /* Execute / cancel buttons. */ if(loadbutton) { - uiDefBut(block, BUT, B_FS_EXEC, 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, ""); + uiDefBut(block, BUT, B_FS_EXEC, params->title, + max_x - loadbutton, line1_y, loadbutton, btn_h, + params->dir, 0.0, (float)FILE_MAXFILE-1, 0, 0, params->title); + uiDefBut(block, BUT, B_FS_CANCEL, "Cancel", + max_x - loadbutton, line2_y, loadbutton, btn_h, + params->file, 0.0, (float)FILE_MAXFILE-1, 0, 0, "Cancel."); } - + uiEndBlock(C, block); uiDrawBlock(C, block); } static void draw_tile(short sx, short sy, short width, short height, int colorid, int shade) -{ - /* 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); - /* I think it was a missing glDisable() - ton */ - +{ UI_ThemeColorShade(colorid, shade); uiSetRoundBox(15); uiRoundBox(sx, sy - height, sx + width, sy, 6); @@ -550,81 +614,4 @@ void file_draw_list(const bContext *C, ARegion *ar) } } -static void file_draw_fsmenu_category(const bContext *C, ARegion *ar, FSMenuCategory category, const char* category_name, short *starty) -{ - struct FSMenu* fsmenu = fsmenu_get(); - char bookmark[FILE_MAX]; - int nentries = fsmenu_get_nentries(fsmenu, category); - - short sx, sy, xpos, ypos; - int bmwidth = ar->v2d.cur.xmax - ar->v2d.cur.xmin - 2*TILE_BORDER_X - ICON_DEFAULT_WIDTH - 4; - int fontsize = file_font_pointsize(); - int cat_icon; - int i; - - sx = ar->v2d.cur.xmin + TILE_BORDER_X; - sy = *starty; - - UI_ThemeColor(TH_TEXT_HI); - file_draw_string(sx, sy, category_name, bmwidth, fontsize, FILE_SHORTEN_END); - - sy -= fontsize*2.0f; - - switch(category) { - case FS_CATEGORY_SYSTEM: - cat_icon = ICON_DISK_DRIVE; break; - case FS_CATEGORY_BOOKMARKS: - cat_icon = ICON_BOOKMARKS; break; - case FS_CATEGORY_RECENT: - cat_icon = ICON_FILE_FOLDER; break; - } - for (i=0; i< nentries && (sy > ar->v2d.cur.ymin) ;++i) { - char *fname = fsmenu_get_entry(fsmenu, category, i); - - if (fname) { - int sl; - BLI_strncpy(bookmark, fname, FILE_MAX); - - sl = strlen(bookmark)-1; - if (sl > 1) { - while (bookmark[sl] == '\\' || bookmark[sl] == '/') { - bookmark[sl] = '\0'; - sl--; - } - } - - if (fsmenu_is_selected(fsmenu, category, i) ) { - UI_ThemeColor(TH_HILITE); - uiRoundBox(sx, sy - fontsize*2.0f, ar->v2d.cur.xmax - TILE_BORDER_X, sy, 4.0f); - UI_ThemeColor(TH_TEXT); - } else { - UI_ThemeColor(TH_TEXT_HI); - } - - xpos = sx; - ypos = sy - (TILE_BORDER_Y * 0.5); - - file_draw_icon(xpos, ypos, cat_icon, ICON_DEFAULT_WIDTH, ICON_DEFAULT_WIDTH); - xpos += ICON_DEFAULT_WIDTH + 4; - file_draw_string(xpos, ypos, bookmark, bmwidth, fontsize, FILE_SHORTEN_FRONT); - sy -= fontsize*2.0; - fsmenu_set_pos(fsmenu, category, i, xpos, ypos); - } - } - - *starty = sy; -} - -void file_draw_fsmenu(const bContext *C, ARegion *ar) -{ - int linestep = file_font_pointsize()*2.0f; - short sy= ar->v2d.cur.ymax-2*TILE_BORDER_Y; - - file_draw_fsmenu_category(C, ar, FS_CATEGORY_SYSTEM, "SYSTEM", &sy); - sy -= linestep; - file_draw_fsmenu_category(C, ar, FS_CATEGORY_BOOKMARKS, "BOOKMARKS", &sy); - sy -= linestep; - file_draw_fsmenu_category(C, ar, FS_CATEGORY_RECENT, "RECENT", &sy); - -} diff --git a/source/blender/editors/space_file/file_header.c b/source/blender/editors/space_file/file_header.c deleted file mode 100644 index 4799003d6c7..00000000000 --- a/source/blender/editors/space_file/file_header.c +++ /dev/null @@ -1,187 +0,0 @@ -/** - * $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 <string.h> -#include <stdio.h> - -#include "DNA_space_types.h" -#include "DNA_scene_types.h" -#include "DNA_screen_types.h" -#include "DNA_windowmanager_types.h" - -#include "MEM_guardedalloc.h" - -#include "BLI_blenlib.h" - -#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" - -#include "BIF_gl.h" -#include "BIF_glutil.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 -#define B_FILTERIMASELDIR 3 -#define B_HIDEDOTFILES 4 - -/* ************************ header area region *********************** */ - -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->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; - 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); - 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; - } -} - - -void file_header_buttons(const bContext *C, ARegion *ar) -{ - SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C); - FileSelectParams* params = ED_fileselect_get_params(sfile); - - uiBlock *block; - int xco, yco= 3; - int xcotitle; - - block= uiBeginBlock(C, ar, "header buttons", UI_EMBOSS); - uiBlockSetHandleFunc(block, do_file_header_buttons, NULL); - - xco= ED_area_header_standardbuttons(C, block, yco); - - /* - if((sa->flag & HEADER_NO_PULLDOWN)==0) { - int xmax; - - xmax= GetButStringLength("View"); - uiDefPulldownBut(block, dummy_viewmenu, CTX_wm_area(C), - "View", xco, yco-2, xmax-3, 24, ""); - xco+=XIC+xmax; - } - */ - - xco += 5; - - uiBlockBeginAlign(block); - uiDefIconButO(block, BUT, "FILE_OT_parent", WM_OP_INVOKE_DEFAULT, ICON_FILE_PARENT, xco+=XIC, yco, 20, 20, "Navigate to Parent Folder"); - uiDefIconButO(block, BUT, "FILE_OT_refresh", WM_OP_INVOKE_DEFAULT, ICON_FILE_REFRESH, xco+=XIC, yco, 20, 20, "Refresh List of Files"); - uiBlockEndAlign(block); - - xco += 5; - - 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_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"); - uiBlockEndAlign(block); - - xco+=XIC; - - - 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_SORTBYEXT, xco+=XIC, yco, XIC,YIC, ¶ms->sort, 1.0, 3.0, 0, 0, "Sorts files by extension"); - uiDefIconButS(block, ROW, B_SORTIMASELLIST, ICON_SORTTIME, xco+=XIC, yco, XIC,YIC, ¶ms->sort, 1.0, 1.0, 0, 0, "Sorts files by time"); - uiDefIconButS(block, ROW, B_SORTIMASELLIST, ICON_SORTSIZE, xco+=XIC, yco, XIC,YIC, ¶ms->sort, 1.0, 2.0, 0, 0, "Sorts files by size"); - uiBlockEndAlign(block); - - 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"); - xco+=XIC; - 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) { - xco+=4; - uiBlockBeginAlign(block); - uiDefIconButBitS(block, TOG, IMAGEFILE, B_FILTERIMASELDIR, ICON_FILE_IMAGE,xco+=XIC,yco,XIC,YIC, ¶ms->filter, 0, 0, 0, 0, "Show images"); - uiDefIconButBitS(block, TOG, BLENDERFILE, B_FILTERIMASELDIR, ICON_FILE_BLEND,xco+=XIC,yco,XIC,YIC, ¶ms->filter, 0, 0, 0, 0, "Show .blend files"); - uiDefIconButBitS(block, TOG, MOVIEFILE, B_FILTERIMASELDIR, ICON_FILE_MOVIE,xco+=XIC,yco,XIC,YIC, ¶ms->filter, 0, 0, 0, 0, "Show movies"); - uiDefIconButBitS(block, TOG, PYSCRIPTFILE, B_FILTERIMASELDIR, ICON_FILE_SCRIPT,xco+=XIC,yco,XIC,YIC, ¶ms->filter, 0, 0, 0, 0, "Show python scripts"); - uiDefIconButBitS(block, TOG, FTFONTFILE, B_FILTERIMASELDIR, ICON_FILE_FONT,xco+=XIC,yco,XIC,YIC, ¶ms->filter, 0, 0, 0, 0, "Show fonts"); - uiDefIconButBitS(block, TOG, SOUNDFILE, B_FILTERIMASELDIR, ICON_FILE_SOUND,xco+=XIC,yco,XIC,YIC, ¶ms->filter, 0, 0, 0, 0, "Show sound files"); - uiDefIconButBitS(block, TOG, TEXTFILE, B_FILTERIMASELDIR, ICON_FILE_BLANK,xco+=XIC,yco,XIC,YIC, ¶ms->filter, 0, 0, 0, 0, "Show text files"); - uiDefIconButBitS(block, TOG, FOLDERFILE, B_FILTERIMASELDIR, ICON_FILE_FOLDER,xco+=XIC,yco,XIC,YIC, ¶ms->filter, 0, 0, 0, 0, "Show folders"); - uiBlockEndAlign(block); - xco+=XIC; - } - - xcotitle= xco; - xco+= UI_GetStringWidth(params->title); - - uiBlockSetEmboss(block, UI_EMBOSS); - - /* always as last */ - UI_view2d_totRect_set(&ar->v2d, xco+XIC+80, ar->v2d.tot.ymax-ar->v2d.tot.ymin); - - uiEndBlock(C, block); - uiDrawBlock(C, block); -} - - - diff --git a/source/blender/editors/space_file/file_intern.h b/source/blender/editors/space_file/file_intern.h index 642189ad3fd..dce56e05d6b 100644 --- a/source/blender/editors/space_file/file_intern.h +++ b/source/blender/editors/space_file/file_intern.h @@ -30,9 +30,9 @@ /* internal exports only */ - -/* file_header.c */ -void file_header_buttons(const bContext *C, ARegion *ar); +struct ARegion; +struct ARegionType; +struct SpaceFile; /* file_ops.c */ struct ARegion *file_buttons_region(struct ScrArea *sa); @@ -45,7 +45,6 @@ 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; @@ -56,21 +55,44 @@ void FILE_OT_select(struct wmOperatorType *ot); void FILE_OT_select_all_toggle(struct wmOperatorType *ot); void FILE_OT_select_border(struct wmOperatorType *ot); void FILE_OT_select_bookmark(struct wmOperatorType *ot); +void FILE_OT_add_bookmark(struct wmOperatorType *ot); +void FILE_OT_delete_bookmark(struct wmOperatorType *ot); +void FILE_OT_hidedot(struct wmOperatorType *ot); void FILE_OT_loadimages(struct wmOperatorType *ot); void FILE_OT_exec(struct wmOperatorType *ot); void FILE_OT_cancel(struct wmOperatorType *ot); void FILE_OT_parent(struct wmOperatorType *ot); +void FILE_OT_directory_new(struct wmOperatorType *ot); +void FILE_OT_filename(struct wmOperatorType *ot); +void FILE_OT_previous(struct wmOperatorType *ot); +void FILE_OT_next(struct wmOperatorType *ot); void FILE_OT_refresh(struct wmOperatorType *ot); void FILE_OT_bookmark_toggle(struct wmOperatorType *ot); +void FILE_OT_filenum(struct wmOperatorType *ot); +void FILE_OT_delete(struct wmOperatorType *ot); int file_exec(bContext *C, struct wmOperator *unused); int file_cancel_exec(bContext *C, struct wmOperator *unused); int file_parent_exec(bContext *C, struct wmOperator *unused); -int file_hilight_set(SpaceFile *sfile, ARegion *ar, int mx, int my); +int file_previous_exec(bContext *C, struct wmOperator *unused); +int file_next_exec(bContext *C, struct wmOperator *unused); +int file_filename_exec(bContext *C, struct wmOperator *unused); +int file_directory_exec(bContext *C, struct wmOperator *unused); +int file_directory_new_exec(bContext *C,struct wmOperator *unused); +int file_delete_exec(bContext *C, struct wmOperator *unused); + +int file_hilight_set(struct SpaceFile *sfile, struct ARegion *ar, int mx, int my); + /* filesel.c */ float file_string_width(const char* str); float file_font_pointsize(); +void file_change_dir(struct SpaceFile *sfile); +int file_select_match(struct SpaceFile *sfile, const char *pattern); +void autocomplete_directory(struct bContext *C, char *str, void *arg_v); + +/* file_panels.c */ +void file_panels_register(struct ARegionType *art); #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 index 0c6cadc05c1..0d36bac7505 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -42,6 +42,8 @@ #include "ED_screen.h" #include "ED_fileselect.h" +#include "MEM_guardedalloc.h" + #include "RNA_access.h" #include "RNA_define.h" @@ -135,25 +137,16 @@ static void file_select(SpaceFile* sfile, ARegion* ar, const rcti* rect, short v params->active_file = last_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 ) + /* the path is too long! */ + if (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(sfile->files, params->dir); - filelist_free(sfile->files); - params->active_file = -1; + BLI_cleanup_dir(G.sce, params->dir); + strcat(params->dir, file->relname); + BLI_add_slash(params->dir); + params->file[0] = '\0'; + file_change_dir(sfile); } } else if (file) @@ -190,7 +183,7 @@ static int file_border_select_exec(bContext *C, wmOperator *op) rect.xmax= RNA_int_get(op->ptr, "xmax"); rect.ymax= RNA_int_get(op->ptr, "ymax"); - BLI_isect_rctf(&(ar->v2d.mask), &rect, &rect); + BLI_isect_rcti(&(ar->v2d.mask), &rect, &rect); file_select(sfile, ar, &rect, val ); WM_event_add_notifier(C, NC_WINDOW, NULL); @@ -234,7 +227,7 @@ static int file_select_invoke(bContext *C, wmOperator *op, wmEvent *event) /* single select, deselect all selected first */ file_deselect_all(sfile); file_select(sfile, ar, &rect, val ); - WM_event_add_notifier(C, NC_WINDOW, NULL); + WM_event_add_notifier(C, NC_FILE|ND_PARAMS, NULL); } return OPERATOR_FINISHED; } @@ -299,89 +292,104 @@ void FILE_OT_select_all_toggle(wmOperatorType *ot) /* ---------- BOOKMARKS ----------- */ -static int file_select_bookmark_category(SpaceFile* sfile, ARegion* ar, short x, short y, FSMenuCategory category) +static int bookmark_select_invoke(bContext *C, wmOperator *op, wmEvent *event) { - struct FSMenu* fsmenu = fsmenu_get(); - int nentries = fsmenu_get_nentries(fsmenu, category); - int linestep = file_font_pointsize()*2.0f; - short xs, ys; - int i; - int selected = -1; + SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C); - for (i=0; i < nentries; ++i) { - fsmenu_get_pos(fsmenu, category, i, &xs, &ys); - if ( (y<=ys) && (y>ys-linestep) ) { - fsmenu_select_entry(fsmenu, category, i); - selected = i; - break; - } + if(RNA_struct_find_property(op->ptr, "dir")) { + char entry[256]; + FileSelectParams* params = sfile->params; + + RNA_string_get(op->ptr, "dir", entry); + BLI_strncpy(params->dir, entry, sizeof(params->dir)); + BLI_cleanup_dir(G.sce, params->dir); + file_change_dir(sfile); + params->file[0] = '\0'; + + WM_event_add_notifier(C, NC_FILE|ND_PARAMS, NULL); } - return selected; + + return OPERATOR_FINISHED; } -static void file_select_bookmark(SpaceFile* sfile, ARegion* ar, short x, short y) +void FILE_OT_select_bookmark(wmOperatorType *ot) { - float fx, fy; - int selected; - FSMenuCategory category = FS_CATEGORY_SYSTEM; - - if (BLI_in_rcti(&ar->v2d.mask, x, y)) { - char *entry; + /* identifiers */ + ot->name= "Select Directory"; + ot->idname= "FILE_OT_select_bookmark"; + + /* api callbacks */ + ot->invoke= bookmark_select_invoke; + ot->poll= ED_operator_file_active; - UI_view2d_region_to_view(&ar->v2d, x, y, &fx, &fy); - selected = file_select_bookmark_category(sfile, ar, fx, fy, FS_CATEGORY_SYSTEM); - if (selected<0) { - category = FS_CATEGORY_BOOKMARKS; - selected = file_select_bookmark_category(sfile, ar, fx, fy, category); - } - if (selected<0) { - category = FS_CATEGORY_RECENT; - selected = file_select_bookmark_category(sfile, ar, fx, fy, category); - } - - if (selected>=0) { - entry= fsmenu_get_entry(fsmenu_get(), category, selected); - /* which string */ - if (entry) { - FileSelectParams* params = sfile->params; - BLI_strncpy(params->dir, entry, sizeof(params->dir)); - BLI_cleanup_dir(G.sce, params->dir); - filelist_free(sfile->files); - filelist_setdir(sfile->files, params->dir); - params->file[0] = '\0'; - params->active_file = -1; - } - } - } + RNA_def_string(ot->srna, "dir", "", 256, "Dir", ""); } -static int bookmark_select_invoke(bContext *C, wmOperator *op, wmEvent *event) +static int bookmark_add_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); + struct FSMenu* fsmenu = fsmenu_get(); + struct FileSelectParams* params= ED_fileselect_get_params(sfile); - short x, y; - - x = event->x - ar->winrct.xmin; - y = event->y - ar->winrct.ymin; + if (params->dir[0] != '\0') { + char name[FILE_MAX]; + + fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, params->dir, 0, 1); + BLI_make_file_string("/", name, BLI_gethome(), ".Bfs"); + fsmenu_write_file(fsmenu, name); + } - file_select_bookmark(sfile, ar, x, y); ED_area_tag_redraw(sa); return OPERATOR_FINISHED; } -void FILE_OT_select_bookmark(wmOperatorType *ot) +void FILE_OT_add_bookmark(wmOperatorType *ot) { /* identifiers */ - ot->name= "Select Directory"; - ot->idname= "FILE_OT_select_bookmark"; + ot->name= "Add Bookmark"; + ot->idname= "FILE_OT_add_bookmark"; /* api callbacks */ - ot->invoke= bookmark_select_invoke; + ot->invoke= bookmark_add_invoke; ot->poll= ED_operator_file_active; } +static int bookmark_delete_invoke(bContext *C, wmOperator *op, wmEvent *event) +{ + ScrArea *sa= CTX_wm_area(C); + struct FSMenu* fsmenu = fsmenu_get(); + int nentries = fsmenu_get_nentries(fsmenu, FS_CATEGORY_BOOKMARKS); + + if(RNA_struct_find_property(op->ptr, "index")) { + int index = RNA_int_get(op->ptr, "index"); + if ( (index >-1) && (index < nentries)) { + char name[FILE_MAX]; + + fsmenu_remove_entry(fsmenu, FS_CATEGORY_BOOKMARKS, index); + BLI_make_file_string("/", name, BLI_gethome(), ".Bfs"); + fsmenu_write_file(fsmenu, name); + ED_area_tag_redraw(sa); + } + } + + return OPERATOR_FINISHED; +} + +void FILE_OT_delete_bookmark(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Delete Bookmark"; + ot->idname= "FILE_OT_delete_bookmark"; + + /* api callbacks */ + ot->invoke= bookmark_delete_invoke; + ot->poll= ED_operator_file_active; + + RNA_def_int(ot->srna, "index", -1, -1, 20000, "Index", "", -1, 20000); +} + + static int loadimages_invoke(bContext *C, wmOperator *op, wmEvent *event) { ScrArea *sa= CTX_wm_area(C); @@ -455,7 +463,10 @@ void FILE_OT_highlight(struct wmOperatorType *ot) int file_cancel_exec(bContext *C, wmOperator *unused) { SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C); - + + folderlist_free(sfile->folders_prev); + folderlist_free(sfile->folders_next); + WM_event_fileselect_event(C, sfile->op, EVT_FILESELECT_CANCEL); sfile->op = NULL; @@ -517,6 +528,9 @@ int file_exec(bContext *C, wmOperator *unused) } } + folderlist_free(sfile->folders_prev); + folderlist_free(sfile->folders_next); + fsmenu_insert_entry(fsmenu_get(), FS_CATEGORY_RECENT, sfile->params->dir,0, 1); BLI_make_file_string(G.sce, name, BLI_gethome(), ".Bfs"); fsmenu_write_file(fsmenu_get(), name); @@ -543,13 +557,14 @@ int file_parent_exec(bContext *C, wmOperator *unused) SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C); if(sfile->params) { - BLI_parent_dir(sfile->params->dir); - filelist_setdir(sfile->files, sfile->params->dir); - filelist_free(sfile->files); - sfile->params->active_file = -1; + if (BLI_has_parent(sfile->params->dir)) { + BLI_parent_dir(sfile->params->dir); + BLI_cleanup_dir(G.sce, sfile->params->dir); + file_change_dir(sfile); + WM_event_add_notifier(C, NC_FILE|ND_FILELIST, NULL); + } } - ED_area_tag_redraw(CTX_wm_area(C)); - + return OPERATOR_FINISHED; } @@ -571,15 +586,168 @@ int file_refresh_exec(bContext *C, wmOperator *unused) { SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C); + file_change_dir(sfile); + + WM_event_add_notifier(C, NC_FILE|ND_FILELIST, NULL); + + return OPERATOR_FINISHED; + +} + +void FILE_OT_previous(struct wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Previous Folder"; + ot->idname= "FILE_OT_previous"; + + /* api callbacks */ + ot->exec= file_previous_exec; + ot->poll= ED_operator_file_active; /* <- important, handler is on window level */ +} + +int file_previous_exec(bContext *C, wmOperator *unused) +{ + SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C); + if(sfile->params) { - filelist_setdir(sfile->files, sfile->params->dir); - filelist_free(sfile->files); - sfile->params->active_file = -1; + if (!sfile->folders_next) + sfile->folders_next = folderlist_new(); + + folderlist_pushdir(sfile->folders_next, sfile->params->dir); + folderlist_popdir(sfile->folders_prev, sfile->params->dir); + folderlist_pushdir(sfile->folders_next, sfile->params->dir); + + file_change_dir(sfile); + } + WM_event_add_notifier(C, NC_FILE|ND_FILELIST, NULL); + + return OPERATOR_FINISHED; +} + +void FILE_OT_next(struct wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Next Folder"; + ot->idname= "FILE_OT_next"; + + /* api callbacks */ + ot->exec= file_next_exec; + ot->poll= ED_operator_file_active; /* <- important, handler is on window level */ +} + +int file_next_exec(bContext *C, wmOperator *unused) +{ + SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C); + if(sfile->params) { + if (!sfile->folders_next) + sfile->folders_next = folderlist_new(); + + folderlist_pushdir(sfile->folders_prev, sfile->params->dir); + folderlist_popdir(sfile->folders_next, sfile->params->dir); + + // update folder_prev so we can check for it in folderlist_clear_next() + folderlist_pushdir(sfile->folders_prev, sfile->params->dir); + + file_change_dir(sfile); + } + WM_event_add_notifier(C, NC_FILE|ND_FILELIST, NULL); + + return OPERATOR_FINISHED; +} + +int file_directory_new_exec(bContext *C, wmOperator *unused) +{ + char tmpstr[FILE_MAX]; + char tmpdir[FILE_MAXFILE]; + int i = 1; + + SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C); + + if(sfile->params) { + + BLI_strncpy(tmpstr, sfile->params->dir, FILE_MAX); + BLI_join_dirfile(tmpstr, tmpstr, "New Folder"); + while (BLI_exists(tmpstr)) { + BLI_snprintf(tmpdir, FILE_MAXFILE, "New Folder(%d)", i++); + BLI_strncpy(tmpstr, sfile->params->dir, FILE_MAX); + BLI_join_dirfile(tmpstr, tmpstr, tmpdir); + } + BLI_recurdir_fileops(tmpstr); + if (!BLI_exists(tmpstr)) { + filelist_free(sfile->files); + filelist_parent(sfile->files); + BLI_strncpy(sfile->params->dir, filelist_dir(sfile->files), FILE_MAX); + } + } + WM_event_add_notifier(C, NC_FILE|ND_FILELIST, NULL); + + return OPERATOR_FINISHED; +} + + +void FILE_OT_directory_new(struct wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Create New Directory"; + ot->idname= "FILE_OT_directory_new"; + + /* api callbacks */ + ot->invoke= WM_operator_confirm; + ot->exec= file_directory_new_exec; + ot->poll= ED_operator_file_active; /* <- important, handler is on window level */ +} + +int file_directory_exec(bContext *C, wmOperator *unused) +{ + char tmpstr[FILE_MAX]; + + SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C); + + if(sfile->params) { + + if ( sfile->params->dir[0] == '~' ) { + if (sfile->params->dir[1] == '\0') { + BLI_strncpy(sfile->params->dir, BLI_gethome(), sizeof(sfile->params->dir) ); + } else { + /* replace ~ with home */ + char homestr[FILE_MAX]; + char *d = &sfile->params->dir[1]; + + while ( (*d == '\\') || (*d == '/') ) + d++; + BLI_strncpy(homestr, BLI_gethome(), FILE_MAX); + BLI_add_slash(homestr); + BLI_join_dirfile(tmpstr, homestr, d); + BLI_strncpy(sfile->params->dir, tmpstr, sizeof(sfile->params->dir)); + } + } +#ifdef WIN32 + if (sfile->params->dir[0] == '\0') + get_default_root(sfile->params->dir); +#endif + BLI_cleanup_dir(G.sce, sfile->params->dir); + BLI_add_slash(sfile->params->dir); + file_change_dir(sfile); + WM_event_add_notifier(C, NC_FILE|ND_FILELIST, NULL); } - ED_area_tag_redraw(CTX_wm_area(C)); + return OPERATOR_FINISHED; +} + +int file_filename_exec(bContext *C, wmOperator *unused) +{ + SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C); + + if(sfile->params) { + if (file_select_match(sfile, sfile->params->file)) + { + sfile->params->file[0] = '\0'; + WM_event_add_notifier(C, NC_FILE|ND_PARAMS, NULL); + } + } + return OPERATOR_FINISHED; } @@ -594,14 +762,58 @@ void FILE_OT_refresh(struct wmOperatorType *ot) ot->poll= ED_operator_file_active; /* <- important, handler is on window level */ } +int file_hidedot_exec(bContext *C, wmOperator *unused) +{ + SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C); + + if(sfile->params) { + sfile->params->flag ^= FILE_HIDE_DOT; + filelist_free(sfile->files); + sfile->params->active_file = -1; + WM_event_add_notifier(C, NC_FILE|ND_FILELIST, NULL); + } + + return OPERATOR_FINISHED; + +} + + +void FILE_OT_hidedot(struct wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Toggle Hide Dot Files"; + ot->idname= "FILE_OT_hidedot"; + + /* api callbacks */ + ot->exec= file_hidedot_exec; + ot->poll= ED_operator_file_active; /* <- important, handler is on window level */ +} + struct ARegion *file_buttons_region(struct ScrArea *sa) { - ARegion *ar; + ARegion *ar, *arnew; for(ar= sa->regionbase.first; ar; ar= ar->next) if(ar->regiontype==RGN_TYPE_CHANNELS) return ar; - return NULL; + + /* add subdiv level; after header */ + for(ar= sa->regionbase.first; ar; ar= ar->next) + if(ar->regiontype==RGN_TYPE_HEADER) + break; + + /* is error! */ + if(ar==NULL) return NULL; + + arnew= MEM_callocN(sizeof(ARegion), "buttons for file panels"); + + BLI_insertlinkafter(&sa->regionbase, ar, arnew); + arnew->regiontype= RGN_TYPE_CHANNELS; + arnew->alignment= RGN_ALIGN_LEFT; + + arnew->flag = RGN_FLAG_HIDDEN; + + return arnew; } int file_bookmark_toggle_exec(bContext *C, wmOperator *unused) @@ -629,3 +841,78 @@ void FILE_OT_bookmark_toggle(struct wmOperatorType *ot) ot->exec= file_bookmark_toggle_exec; ot->poll= ED_operator_file_active; /* <- important, handler is on window level */ } + + +int file_filenum_exec(bContext *C, wmOperator *op) +{ + SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C); + + int inc = RNA_int_get(op->ptr, "increment"); + if(sfile->params && (inc != 0)) { + BLI_newname(sfile->params->file, inc); + WM_event_add_notifier(C, NC_WINDOW, NULL); + } + + return OPERATOR_FINISHED; + +} + +void FILE_OT_filenum(struct wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Increment Number in Filename"; + ot->idname= "FILE_OT_filenum"; + + /* api callbacks */ + ot->exec= file_filenum_exec; + ot->poll= ED_operator_file_active; /* <- important, handler is on window level */ + + /* props */ + RNA_def_int(ot->srna, "increment", 1, 0, 100, "Increment", "", 0,100); +} + +int file_delete_poll(bContext *C) +{ + int poll = ED_operator_file_active(C); + SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C); + struct direntry* file; + + if(!sfile->params ) poll= 0; + + if (sfile->params->active_file < 0) { + poll= 0; + } else { + file = filelist_file(sfile->files, sfile->params->active_file); + if (file && S_ISDIR(file->type)) poll= 0; + } + return poll; +} + +int file_delete_exec(bContext *C, wmOperator *op) +{ + char str[FILE_MAX]; + SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C); + struct direntry* file; + + + file = filelist_file(sfile->files, sfile->params->active_file); + BLI_make_file_string(G.sce, str, sfile->params->dir, file->relname); + BLI_delete(str, 0, 0); + WM_event_add_notifier(C, NC_FILE | ND_FILELIST, NULL); + + return OPERATOR_FINISHED; + +} + +void FILE_OT_delete(struct wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Delete File"; + ot->idname= "FILE_OT_delete"; + + /* api callbacks */ + ot->invoke= WM_operator_confirm; + ot->exec= file_delete_exec; + ot->poll= file_delete_poll; /* <- important, handler is on window level */ +} + diff --git a/source/blender/editors/space_file/file_panels.c b/source/blender/editors/space_file/file_panels.c new file mode 100644 index 00000000000..96366b9f82b --- /dev/null +++ b/source/blender/editors/space_file/file_panels.c @@ -0,0 +1,164 @@ +/** + * $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) 2009 Blender Foundation. + * All rights reserved. + * + * + * Contributor(s): Blender Foundation, Andrea Weikert + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include "BKE_context.h" +#include "BKE_screen.h" + +#include "BLI_blenlib.h" + +#include "DNA_screen_types.h" +#include "DNA_space_types.h" +#include "DNA_userdef_types.h" +#include "DNA_windowmanager_types.h" + +#include "MEM_guardedalloc.h" + +#include "RNA_access.h" + +#include "UI_interface.h" +#include "UI_resources.h" +#include "UI_view2d.h" + +#include "file_intern.h" +#include "fsmenu.h" + +#include <string.h> + +static void do_file_panel_events(bContext *C, void *arg, int event) +{ + +} + +static void file_panel_category(const bContext *C, Panel *pa, FSMenuCategory category, int icon, int allow_delete) +{ + uiBlock *block; + struct FSMenu* fsmenu = fsmenu_get(); + int nentries = fsmenu_get_nentries(fsmenu, category); + int i; + + uiLayoutSetAlignment(pa->layout, UI_LAYOUT_ALIGN_LEFT); + block= uiLayoutFreeBlock(pa->layout); + uiBlockSetHandleFunc(block, do_file_panel_events, NULL); + uiBlockSetEmboss(block, UI_EMBOSSP); + uiBlockBeginAlign(block); + for (i=0; i< nentries;++i) { + char dir[FILE_MAX]; + char temp[FILE_MAX]; + uiLayout* layout = uiLayoutRow(pa->layout, UI_LAYOUT_ALIGN_LEFT); + char *entry = fsmenu_get_entry(fsmenu, category, i); + + /* create nice bookmark name, shows last directory in the full path currently */ + BLI_strncpy(temp, entry, FILE_MAX); + BLI_add_slash(temp); + BLI_getlastdir(temp, dir, FILE_MAX); + BLI_del_slash(dir); + + /* operator shows the short bookmark name, should eventually have tooltip */ + uiItemStringO(layout, dir, icon, "FILE_OT_select_bookmark", "dir", entry); + if (allow_delete && fsmenu_can_save(fsmenu, category, i) ) + uiItemIntO(layout, "", ICON_X, "FILE_OT_delete_bookmark", "index", i); + } + uiBlockEndAlign(block); +} + +static void file_panel_system(const bContext *C, Panel *pa) +{ + file_panel_category(C, pa, FS_CATEGORY_SYSTEM, ICON_DISK_DRIVE, 0); +} + +static void file_panel_bookmarks(const bContext *C, Panel *pa) +{ + file_panel_category(C, pa, FS_CATEGORY_BOOKMARKS, ICON_BOOKMARKS, 1); +} + + +static void file_panel_recent(const bContext *C, Panel *pa) +{ + file_panel_category(C, pa, FS_CATEGORY_RECENT, ICON_FILE_FOLDER, 0); +} + + +static void file_panel_operator(const bContext *C, Panel *pa) +{ + SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C); + struct wmOperator *op = sfile ? sfile->op : NULL; + uiBlock *block; + int sy; + + block= uiLayoutFreeBlock(pa->layout); + uiBlockSetHandleFunc(block, do_file_panel_events, NULL); + + sy= 0; + if (op) { + uiBlockBeginAlign(block); + RNA_STRUCT_BEGIN(op->ptr, prop) { + if(strcmp(RNA_property_identifier(prop), "rna_type") == 0) + continue; + if(strcmp(RNA_property_identifier(prop), "filename") == 0) + continue; + + uiItemFullR(pa->layout, NULL, 0, op->ptr, prop, -1, 0, 0, 0, 0); + } + RNA_STRUCT_END; + uiBlockEndAlign(block); + } + uiBlockLayoutResolve(C, block, NULL, &sy); + uiEndBlock(C, block); + uiDrawBlock(C, block); +} + + +void file_panels_register(ARegionType *art) +{ + PanelType *pt; + + pt= MEM_callocN(sizeof(PanelType), "spacetype file system directories"); + strcpy(pt->idname, "FILE_PT_system"); + strcpy(pt->label, "System"); + pt->draw= file_panel_system; + BLI_addtail(&art->paneltypes, pt); + + pt= MEM_callocN(sizeof(PanelType), "spacetype file bookmarks"); + strcpy(pt->idname, "FILE_PT_bookmarks"); + strcpy(pt->label, "Bookmarks"); + pt->draw= file_panel_bookmarks; + BLI_addtail(&art->paneltypes, pt); + + pt= MEM_callocN(sizeof(PanelType), "spacetype file recent directories"); + strcpy(pt->idname, "FILE_PT_recent"); + strcpy(pt->label, "Recent"); + pt->draw= file_panel_recent; + BLI_addtail(&art->paneltypes, pt); + + pt= MEM_callocN(sizeof(PanelType), "spacetype file operator properties"); + strcpy(pt->idname, "FILE_PT_operator"); + strcpy(pt->label, "Operator"); + pt->draw= file_panel_operator; + BLI_addtail(&art->paneltypes, pt); +} + diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c index 766dec7c064..6e442c654ca 100644 --- a/source/blender/editors/space_file/filelist.c +++ b/source/blender/editors/space_file/filelist.c @@ -123,6 +123,12 @@ typedef struct FileList ListBase threads; } FileList; +typedef struct FolderList +{ + struct FolderList *next, *prev; + char *foldername; +} FolderList; + #define SPECIAL_IMG_SIZE 48 #define SPECIAL_IMG_ROWS 4 #define SPECIAL_IMG_COLS 4 @@ -354,6 +360,86 @@ void filelist_free_icons() } } +//-----------------FOLDERLIST (previous/next) --------------// +struct ListBase* folderlist_new() +{ + ListBase* p = MEM_callocN( sizeof(ListBase), "folderlist" ); + return p; +} + +void folderlist_popdir(struct ListBase* folderlist, char *dir) +{ + const char *prev_dir; + struct FolderList *folder; + folder = folderlist->last; + + if(folder){ + // remove the current directory + MEM_freeN(folder->foldername); + BLI_freelinkN(folderlist, folder); + + folder = folderlist->last; + if(folder){ + prev_dir = folder->foldername; + BLI_strncpy(dir, prev_dir, FILE_MAXDIR); + } + } + // delete the folder next or use setdir directly before PREVIOUS OP +} + +void folderlist_pushdir(ListBase* folderlist, const char *dir) +{ + struct FolderList *folder, *previous_folder; + previous_folder = folderlist->last; + + // check if already exists + if(previous_folder){ + if(! strcmp(previous_folder->foldername, dir)){ + return; + } + } + + // create next folder element + folder = (FolderList*)MEM_mallocN(sizeof(FolderList),"FolderList"); + folder->foldername = (char*)MEM_mallocN(sizeof(char)*(strlen(dir)+1), "foldername"); + folder->foldername[0] = '\0'; + + BLI_strncpy(folder->foldername, dir, FILE_MAXDIR); + + // add it to the end of the list + BLI_addtail(folderlist, folder); +} + +int folderlist_clear_next(struct SpaceFile *sfile) +{ + struct FolderList *folder; + + // if there is no folder_next there is nothing we can clear + if (!sfile->folders_next) + return 0; + + // if previous_folder, next_folder or refresh_folder operators are executed it doesn't clear folder_next + folder = sfile->folders_prev->last; + if ((!folder) ||(!strcmp(folder->foldername, sfile->params->dir))) + return 0; + + // eventually clear flist->folders_next + return 1; +} + +void folderlist_free(ListBase* folderlist) +{ + FolderList *folder; + if (folderlist){ + for(folder= folderlist->last; folder; folder= folderlist->last) { + MEM_freeN(folder->foldername); + BLI_freelinkN(folderlist, folder); + } + } + folderlist= NULL; +} + +//------------------FILELIST------------------------// struct FileList* filelist_new() { FileList* p = MEM_callocN( sizeof(FileList), "filelist" ); @@ -375,7 +461,7 @@ void filelist_free(struct FileList* filelist) int i; if (!filelist) { - printf("Attemtping to delete empty filelist.\n"); + printf("Attempting to delete empty filelist.\n"); return; } @@ -823,16 +909,16 @@ void filelist_sort(struct FileList* filelist, short sort) int num;/* , act= 0; */ switch(sort) { - case FILE_SORTALPHA: + case FILE_SORT_ALPHA: qsort(filelist->filelist, filelist->numfiles, sizeof(struct direntry), compare_name); break; - case FILE_SORTDATE: + case FILE_SORT_TIME: qsort(filelist->filelist, filelist->numfiles, sizeof(struct direntry), compare_date); break; - case FILE_SORTSIZE: + case FILE_SORT_SIZE: qsort(filelist->filelist, filelist->numfiles, sizeof(struct direntry), compare_size); break; - case FILE_SORTEXTENS: + case FILE_SORT_EXTENSION: qsort(filelist->filelist, filelist->numfiles, sizeof(struct direntry), compare_extension); } diff --git a/source/blender/editors/space_file/filelist.h b/source/blender/editors/space_file/filelist.h index f10c89926d6..dd3c2c766c1 100644 --- a/source/blender/editors/space_file/filelist.h +++ b/source/blender/editors/space_file/filelist.h @@ -38,6 +38,7 @@ extern "C" { #endif struct FileList; +struct FolderList; struct direntry; struct BlendHandle; struct Scene; @@ -49,7 +50,6 @@ void filelist_free_icons(); struct FileList * filelist_copy(struct FileList* filelist); int filelist_find(struct FileList* filelist, char *file); void filelist_free(struct FileList* filelist); -void filelist_freelib(struct FileList* filelist); void filelist_sort(struct FileList* filelist, short sort); int filelist_numfiles(struct FileList* filelist); const char * filelist_dir(struct FileList* filelist); @@ -71,6 +71,11 @@ int filelist_empty(struct FileList* filelist); void filelist_parent(struct FileList* filelist); void filelist_setfiletypes(struct FileList* filelist, short has_quicktime); +struct ListBase * folderlist_new(); +void folderlist_free(struct ListBase* folderlist); +void folderlist_popdir(struct ListBase* folderlist, char *dir); +void folderlist_pushdir(struct ListBase* folderlist, const char *dir); +int folderlist_clear_next(struct SpaceFile* sfile); #ifdef __cplusplus } diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c index d57fc7f90bc..30712ea0b07 100644 --- a/source/blender/editors/space_file/filesel.c +++ b/source/blender/editors/space_file/filesel.c @@ -80,16 +80,27 @@ #include "file_intern.h" #include "filelist.h" +#if defined __BeOS +static int fnmatch(const char *pattern, const char *string, int flags) +{ + return 0; +} +#elif defined WIN32 && !defined _LIBC + /* use fnmatch included in blenlib */ + #include "BLI_fnmatch.h" +#else + #include <fnmatch.h> +#endif FileSelectParams* ED_fileselect_get_params(struct SpaceFile *sfile) { if (!sfile->params) { - ED_fileselect_set_params(sfile, "", "/", 0, FILE_SHORTDISPLAY, 0, FILE_SORTALPHA); + ED_fileselect_set_params(sfile, "", NULL, "/", 0, FILE_SHORTDISPLAY, 0, FILE_SORT_ALPHA); } return sfile->params; } -short ED_fileselect_set_params(SpaceFile *sfile, const char *title, const char *path, +short ED_fileselect_set_params(SpaceFile *sfile, const char *title, const char *last_dir, const char *path, short flag, short display, short filter, short sort) { char name[FILE_MAX], dir[FILE_MAX], file[FILE_MAX]; @@ -107,14 +118,19 @@ short ED_fileselect_set_params(SpaceFile *sfile, const char *title, const char * params->sort = sort; BLI_strncpy(params->title, title, sizeof(params->title)); - - BLI_strncpy(name, path, sizeof(name)); - BLI_convertstringcode(name, G.sce); - 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 */ + if(last_dir){ + BLI_strncpy(params->dir, last_dir, sizeof(params->dir)); + } + else { + BLI_strncpy(name, path, sizeof(name)); + BLI_convertstringcode(name, G.sce); + + 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 */ + } return 1; } @@ -131,6 +147,9 @@ int ED_fileselect_layout_offset(FileLayout* layout, int x, int y) int offsetx, offsety; int active_file; + if (layout == NULL) + return NULL; + offsetx = (x)/(layout->tile_w + 2*layout->tile_border_x); offsety = (y)/(layout->tile_h + 2*layout->tile_border_y); @@ -159,7 +178,7 @@ float file_string_width(const char* str) { uiStyle *style= U.uistyles.first; uiStyleFontSet(&style->widget); - return BLF_width(str); + return BLF_width((char *)str); } float file_font_pointsize() @@ -279,3 +298,68 @@ FileLayout* ED_fileselect_get_layout(struct SpaceFile *sfile, struct ARegion *ar } return sfile->layout; } + +void file_change_dir(struct SpaceFile *sfile) +{ + if (sfile->params) { + if (BLI_exists(sfile->params->dir)) { + filelist_setdir(sfile->files, sfile->params->dir); + + if(folderlist_clear_next(sfile)) + folderlist_free(sfile->folders_next); + + folderlist_pushdir(sfile->folders_prev, sfile->params->dir); + + filelist_free(sfile->files); + sfile->params->active_file = -1; + } else { + BLI_strncpy(sfile->params->dir, filelist_dir(sfile->files), FILE_MAX); + } + } +} + +int file_select_match(struct SpaceFile *sfile, const char *pattern) +{ + int match = 0; + if (strchr(pattern, '*') || strchr(pattern, '?') || strchr(pattern, '[')) { + int i; + struct direntry *file; + int n = filelist_numfiles(sfile->files); + + for (i = 0; i < n; i++) { + file = filelist_file(sfile->files, i); + if (fnmatch(pattern, file->relname, 0) == 0) { + file->flags |= ACTIVE; + match = 1; + } + } + } + return match; +} + + +void autocomplete_directory(struct bContext *C, char *str, void *arg_v) +{ + char tmp[FILE_MAX]; + SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C); + + /* search if str matches the beginning of name */ + if(str[0] && sfile->files) { + AutoComplete *autocpl= autocomplete_begin(str, FILE_MAX); + int nentries = filelist_numfiles(sfile->files); + int i; + + for(i= 0; i<nentries; ++i) { + struct direntry* file = filelist_file(sfile->files, i); + char* dir = filelist_dir(sfile->files); + if (file && S_ISDIR(file->type)) { + BLI_make_file_string(G.sce, tmp, dir, file->relname); + autocomplete_do_name(autocpl,tmp); + } + } + autocomplete_end(autocpl, str); + if (BLI_exists(str)) { + BLI_add_slash(str); + } + } +}
\ No newline at end of file diff --git a/source/blender/editors/space_file/fsmenu.c b/source/blender/editors/space_file/fsmenu.c index 59e8dcf82e6..a87ad4c4fd8 100644 --- a/source/blender/editors/space_file/fsmenu.c +++ b/source/blender/editors/space_file/fsmenu.c @@ -65,7 +65,6 @@ struct _FSMenuEntry { char *path; short save; - short xs, ys; }; typedef struct FSMenu @@ -74,9 +73,6 @@ typedef struct FSMenu FSMenuEntry *fsmenu_bookmarks; FSMenuEntry *fsmenu_recent; - FSMenuCategory selected_category; - int selected_entry; - } FSMenu; static FSMenu *g_fsmenu = NULL; @@ -89,17 +85,6 @@ struct FSMenu* fsmenu_get(void) return g_fsmenu; } -void fsmenu_select_entry(struct FSMenu* fsmenu, FSMenuCategory category, int index) -{ - fsmenu->selected_category = category; - fsmenu->selected_entry = index; -} - -int fsmenu_is_selected(struct FSMenu* fsmenu, FSMenuCategory category, int index) -{ - return (category==fsmenu->selected_category) && (index==fsmenu->selected_entry); -} - static FSMenuEntry *fsmenu_get_category(struct FSMenu* fsmenu, FSMenuCategory category) { FSMenuEntry *fsms = NULL; @@ -154,36 +139,16 @@ char *fsmenu_get_entry(struct FSMenu* fsmenu, FSMenuCategory category, int idx) return fsme?fsme->path:NULL; } -void fsmenu_set_pos(struct FSMenu* fsmenu, FSMenuCategory category, int idx, short xs, short ys) +short fsmenu_can_save (struct FSMenu* fsmenu, FSMenuCategory category, int idx) { FSMenuEntry *fsme; for (fsme= fsmenu_get_category(fsmenu, category); fsme && idx; fsme= fsme->next) idx--; - if (fsme) { - fsme->xs = xs; - fsme->ys = ys; - } + return fsme?fsme->save:0; } -int fsmenu_get_pos (struct FSMenu* fsmenu, FSMenuCategory category, int idx, short* xs, short* ys) -{ - FSMenuEntry *fsme; - - for (fsme= fsmenu_get_category(fsmenu, category); fsme && idx; fsme= fsme->next) - idx--; - - if (fsme) { - *xs = fsme->xs; - *ys = fsme->ys; - return 1; - } - - return 0; -} - - void fsmenu_insert_entry(struct FSMenu* fsmenu, FSMenuCategory category, char *path, int sorted, short save) { FSMenuEntry *prev; diff --git a/source/blender/editors/space_file/fsmenu.h b/source/blender/editors/space_file/fsmenu.h index c51c45b7dc4..2cab622d523 100644 --- a/source/blender/editors/space_file/fsmenu.h +++ b/source/blender/editors/space_file/fsmenu.h @@ -52,22 +52,15 @@ int fsmenu_get_nentries (struct FSMenu* fsmenu, FSMenuCategory category); */ char* fsmenu_get_entry (struct FSMenu* fsmenu, FSMenuCategory category, int index); -void fsmenu_select_entry (struct FSMenu* fsmenu, FSMenuCategory category, int index); - -int fsmenu_is_selected (struct FSMenu* fsmenu, FSMenuCategory category, int index); - - /** Sets the position of the fsmenu entry at @a index */ -void fsmenu_set_pos (struct FSMenu* fsmenu, FSMenuCategory category, int index, short xs, short ys); - - /** Returns the position of the fsmenu entry at @a index. return value is 1 if successful, 0 otherwise */ -int fsmenu_get_pos (struct FSMenu* fsmenu, FSMenuCategory category, int index, short* xs, short* ys); - /** Inserts a new fsmenu entry with the given @a path. * Duplicate entries are not added. * @param sorted Should entry be inserted in sorted order? */ void fsmenu_insert_entry (struct FSMenu* fsmenu, FSMenuCategory category, char *path, int sorted, short save); + /** Return whether the entry was created by the user and can be saved and deleted */ +short fsmenu_can_save (struct FSMenu* fsmenu, FSMenuCategory category, int index); + /** Removes the fsmenu entry at the given @a index. */ void fsmenu_remove_entry (struct FSMenu* fsmenu, FSMenuCategory category, int index); diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c index 37d8f2bffa4..5af79eb2800 100644 --- a/source/blender/editors/space_file/space_file.c +++ b/source/blender/editors/space_file/space_file.c @@ -34,6 +34,8 @@ #include "DNA_scene_types.h" #include "DNA_screen_types.h" +#include "RNA_access.h" + #include "MEM_guardedalloc.h" #include "BIF_gl.h" @@ -122,6 +124,18 @@ static void file_free(SpaceLink *sl) sfile->files= NULL; } + if(sfile->folders_prev) { + folderlist_free(sfile->folders_prev); + MEM_freeN(sfile->folders_prev); + sfile->folders_prev= NULL; + } + + if(sfile->folders_next) { + folderlist_free(sfile->folders_next); + MEM_freeN(sfile->folders_next); + sfile->folders_next= NULL; + } + if (sfile->params) { if(sfile->params->pupmenu) MEM_freeN(sfile->params->pupmenu); @@ -151,11 +165,15 @@ static SpaceLink *file_duplicate(SpaceLink *sl) sfilen->op = NULL; /* file window doesn't own operators */ sfilen->files = filelist_new(); - + if(sfileo->folders_prev) + sfilen->folders_prev = MEM_dupallocN(sfileo->folders_prev); + + if(sfileo->folders_next) + sfilen->folders_next = MEM_dupallocN(sfileo->folders_next); + if(sfileo->params) { sfilen->params= MEM_dupallocN(sfileo->params); - - filelist_setdir(sfilen->files, sfilen->params->dir); + file_change_dir(sfilen); } if (sfileo->layout) { sfilen->layout= MEM_dupallocN(sfileo->layout); @@ -163,6 +181,48 @@ static SpaceLink *file_duplicate(SpaceLink *sl) return (SpaceLink *)sfilen; } +static void file_refresh(const bContext *C, ScrArea *sa) +{ + SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C); + FileSelectParams *params = ED_fileselect_get_params(sfile); + + if (!sfile->folders_prev) + sfile->folders_prev = folderlist_new(); + if (!sfile->files) { + sfile->files = filelist_new(); + file_change_dir(sfile); + params->active_file = -1; // added this so it opens nicer (ton) + } + filelist_hidedot(sfile->files, params->flag & FILE_HIDE_DOT); + if (filelist_empty(sfile->files)) + { + filelist_readdir(sfile->files); + } + filelist_setfilter(sfile->files, params->flag & FILE_FILTER ? params->filter : 0); + if(params->sort!=FILE_SORT_NONE) filelist_sort(sfile->files, params->sort); +} + +static void file_listener(ScrArea *sa, wmNotifier *wmn) +{ + SpaceFile* sfile = (SpaceFile*)sa->spacedata.first; + + /* context changes */ + switch(wmn->category) { + case NC_FILE: + switch (wmn->data) { + case ND_FILELIST: + if (sfile->files) filelist_free(sfile->files); + ED_area_tag_refresh(sa); + ED_area_tag_redraw(sa); + break; + case ND_PARAMS: + ED_area_tag_refresh(sa); + ED_area_tag_redraw(sa); + break; + } + break; + } +} /* add handlers, stuff you only do once or on area/region changes */ static void file_main_area_init(wmWindowManager *wm, ARegion *ar) @@ -171,8 +231,11 @@ static void file_main_area_init(wmWindowManager *wm, ARegion *ar) UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_LIST, ar->winx, ar->winy); - /* own keymap */ - keymap= WM_keymap_listbase(wm, "File", SPACE_FILE, 0); /* XXX weak? */ + /* own keymaps */ + keymap= WM_keymap_listbase(wm, "File", SPACE_FILE, 0); + WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + + keymap= WM_keymap_listbase(wm, "FileMain", SPACE_FILE, 0); WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); @@ -188,31 +251,9 @@ static void file_main_area_draw(const bContext *C, ARegion *ar) View2D *v2d= &ar->v2d; View2DScrollers *scrollers; float col[3]; - - if (!sfile->files) { - sfile->files = filelist_new(); - filelist_setdir(sfile->files, params->dir); - params->active_file = -1; // added this so it opens nicer (ton) - } layout = ED_fileselect_get_layout(sfile, ar); - if (filelist_empty(sfile->files)) - { - unsigned int filter = 0; - filelist_hidedot(sfile->files, params->flag & FILE_HIDE_DOT); - if (params->flag & FILE_FILTER) { - filter = params->filter ; - } else { - filter = 0; - } - - filelist_setfilter(sfile->files, filter); - filelist_readdir(sfile->files); - - if(params->sort!=FILE_SORTALPHA) filelist_sort(sfile->files, params->sort); - } - /* clear and setup matrix */ UI_GetThemeColor3fv(TH_BACK, col); glClearColor(col[0], col[1], col[2], 0.0); @@ -272,24 +313,68 @@ void file_operatortypes(void) WM_operatortype_append(FILE_OT_exec); WM_operatortype_append(FILE_OT_cancel); WM_operatortype_append(FILE_OT_parent); + WM_operatortype_append(FILE_OT_previous); + WM_operatortype_append(FILE_OT_next); WM_operatortype_append(FILE_OT_refresh); WM_operatortype_append(FILE_OT_bookmark_toggle); + WM_operatortype_append(FILE_OT_add_bookmark); + WM_operatortype_append(FILE_OT_delete_bookmark); + WM_operatortype_append(FILE_OT_hidedot); + WM_operatortype_append(FILE_OT_filenum); + WM_operatortype_append(FILE_OT_directory_new); + WM_operatortype_append(FILE_OT_delete); } /* NOTE: do not add .blend file reading on this level */ void file_keymap(struct wmWindowManager *wm) { + wmKeymapItem *kmi; + /* keys for all areas */ ListBase *keymap= WM_keymap_listbase(wm, "File", SPACE_FILE, 0); + WM_keymap_add_item(keymap, "FILE_OT_bookmark_toggle", NKEY, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "FILE_OT_parent", PKEY, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "FILE_OT_add_bookmark", BKEY, KM_PRESS, KM_CTRL, 0); + WM_keymap_add_item(keymap, "FILE_OT_hidedot", HKEY, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "FILE_OT_previous", BACKSPACEKEY, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "FILE_OT_next", BACKSPACEKEY, KM_PRESS, KM_SHIFT, 0); + /* WM_keymap_add_item(keymap, "FILE_OT_directory_new", IKEY, KM_PRESS, 0, 0); */ /* XXX needs button */ + WM_keymap_add_item(keymap, "FILE_OT_delete", XKEY, KM_PRESS, 0, 0); + + /* keys for main area */ + keymap= WM_keymap_listbase(wm, "FileMain", SPACE_FILE, 0); WM_keymap_add_item(keymap, "FILE_OT_select", LEFTMOUSE, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "FILE_OT_select_all_toggle", AKEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "FILE_OT_select_border", BKEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "FILE_OT_highlight", MOUSEMOVE, KM_ANY, 0, 0); - WM_keymap_add_item(keymap, "FILE_OT_parent", PKEY, KM_PRESS, 0, 0); - WM_keymap_add_item(keymap, "FILE_OT_loadimages", TIMER1, KM_ANY, KM_ANY, 0); - - keymap= WM_keymap_listbase(wm, "FileBookmark", SPACE_FILE, 0); - WM_keymap_add_item(keymap, "FILE_OT_select_bookmark", LEFTMOUSE, KM_PRESS, 0, 0); + kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADPLUSKEY, KM_PRESS, 0, 0); + RNA_int_set(kmi->ptr, "increment", 1); + kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADPLUSKEY, KM_PRESS, KM_SHIFT, 0); + RNA_int_set(kmi->ptr, "increment", 10); + kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADPLUSKEY, KM_PRESS, KM_CTRL, 0); + RNA_int_set(kmi->ptr, "increment", 100); + kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADMINUS, KM_PRESS, 0,0); + RNA_int_set(kmi->ptr, "increment", -1); + kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADMINUS, KM_PRESS, KM_SHIFT, 0); + RNA_int_set(kmi->ptr, "increment", -10); + kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADMINUS, KM_PRESS, KM_CTRL, 0); + RNA_int_set(kmi->ptr, "increment",-100); + + /* keys for button area (top) */ + keymap= WM_keymap_listbase(wm, "FileButtons", SPACE_FILE, 0); + WM_keymap_add_item(keymap, "FILE_OT_filenum", PADPLUSKEY, KM_PRESS, 0, 0); + kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADPLUSKEY, KM_PRESS, 0, 0); + RNA_int_set(kmi->ptr, "increment", 1); + kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADPLUSKEY, KM_PRESS, KM_SHIFT, 0); + RNA_int_set(kmi->ptr, "increment", 10); + kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADPLUSKEY, KM_PRESS, KM_CTRL, 0); + RNA_int_set(kmi->ptr, "increment", 100); + kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADMINUS, KM_PRESS, 0, 0); + RNA_int_set(kmi->ptr, "increment", -1); + kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADMINUS, KM_PRESS, KM_SHIFT,0); + RNA_int_set(kmi->ptr, "increment", -10); + kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADMINUS, KM_PRESS, KM_CTRL,0); + RNA_int_set(kmi->ptr, "increment",-100); } @@ -297,60 +382,50 @@ 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); + ED_region_panels_init(wm, ar); - /* own keymap */ - keymap= WM_keymap_listbase(wm, "FileBookmark", SPACE_FILE, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, NULL, NULL); + /* own keymaps */ + keymap= WM_keymap_listbase(wm, "File", SPACE_FILE, 0); + WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); } static void file_channel_area_draw(const bContext *C, ARegion *ar) { - View2D *v2d= &ar->v2d; - float col[3]; - - UI_GetThemeColor3fv(TH_PANEL, col); - glClearColor(col[0], col[1], col[2], 0.0); - glClear(GL_COLOR_BUFFER_BIT); - - /* data... */ - UI_view2d_view_ortho(C, v2d); + ED_region_panels(C, ar, 1, NULL); +} - file_draw_fsmenu(C, ar); +static void file_channel_area_listener(ARegion *ar, wmNotifier *wmn) +{ + /* context changes */ + switch(wmn->category) { + + } } /* add handlers, stuff you only do once or on area/region changes */ static void file_header_area_init(wmWindowManager *wm, ARegion *ar) { - UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy); + ED_region_header_init(ar); } static void file_header_area_draw(const bContext *C, ARegion *ar) { - float col[3]; - - /* clear */ - if(ED_screen_area_active(C)) - UI_GetThemeColor3fv(TH_HEADER, col); - else - UI_GetThemeColor3fv(TH_HEADERDESEL, 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_header_buttons(C, ar); - - /* restore view matrix? */ - UI_view2d_view_restore(C); + ED_region_header(C, ar); } /* add handlers, stuff you only do once or on area/region changes */ static void file_ui_area_init(wmWindowManager *wm, ARegion *ar) { + ListBase *keymap; + UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy); + + /* own keymap */ + keymap= WM_keymap_listbase(wm, "File", SPACE_FILE, 0); /* XXX weak? */ + WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + + keymap= WM_keymap_listbase(wm, "FileButtons", SPACE_FILE, 0); /* XXX weak? */ + WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); } static void file_ui_area_draw(const bContext *C, ARegion *ar) @@ -386,6 +461,8 @@ void ED_spacetype_file(void) st->free= file_free; st->init= file_init; st->duplicate= file_duplicate; + st->refresh= file_refresh; + st->listener= file_listener; st->operatortypes= file_operatortypes; st->keymap= file_keymap; @@ -405,6 +482,7 @@ void ED_spacetype_file(void) art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D; art->init= file_header_area_init; art->draw= file_header_area_draw; + // art->listener= file_header_area_listener; BLI_addhead(&st->regiontypes, art); /* regions: ui */ @@ -421,10 +499,12 @@ void ED_spacetype_file(void) art->regionid = RGN_TYPE_CHANNELS; art->minsizex= 240; art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D; + art->listener= file_channel_area_listener; art->init= file_channel_area_init; art->draw= file_channel_area_draw; BLI_addhead(&st->regiontypes, art); - + file_panels_register(art); + BKE_spacetype_register(st); } diff --git a/source/blender/editors/space_file/writeimage.c b/source/blender/editors/space_file/writeimage.c index 25890953320..ac15ed93ad0 100644 --- a/source/blender/editors/space_file/writeimage.c +++ b/source/blender/editors/space_file/writeimage.c @@ -153,6 +153,9 @@ void save_image_filesel_str(Scene *scene, char *str) strcpy(str, "Save Radiance HDR"); break; case R_FFMPEG: + case R_H264: + case R_XVID: + case R_THEORA: case R_PNG: strcpy(str, "Save PNG"); break; |