diff options
author | Andrea Weikert <elubie@gmx.net> | 2009-06-30 00:23:40 +0400 |
---|---|---|
committer | Andrea Weikert <elubie@gmx.net> | 2009-06-30 00:23:40 +0400 |
commit | 5e20f574310626c453b7372c6e3d0dcf2c575b74 (patch) | |
tree | c65adf1d04a2ae6f45d5080e933ac00d3aa070d2 /source/blender/editors/space_file/file_ops.c | |
parent | 5d491681e0d1e6b8450dedc64bd45408bb9066cd (diff) |
2.5 filebrowser
* start of filebrowser RNA
* system files, bookmarks, etc. now nicely inside panels to allow collapsing etc.
* filebrowser header now defined in space_filebrowser.py
TODO:
* button type for bookmarks etc. not final yet, at least should get centered still. Suggestions welcome here.
Diffstat (limited to 'source/blender/editors/space_file/file_ops.c')
-rw-r--r-- | source/blender/editors/space_file/file_ops.c | 109 |
1 files changed, 40 insertions, 69 deletions
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index ab02147d020..ebece6dd5e6 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" @@ -234,7 +236,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,75 +301,25 @@ 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) -{ - 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; - - 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; - } - } - return selected; -} - -static void file_select_bookmark(SpaceFile* sfile, ARegion* ar, short x, short y) -{ - float fx, fy; - int selected; - FSMenuCategory category = FS_CATEGORY_SYSTEM; - - if (BLI_in_rcti(&ar->v2d.mask, x, y)) { - char *entry; - - 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; - } - } - } -} - 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 x, y; + if(RNA_struct_find_property(op->ptr, "dir")) { + char entry[256]; + FileSelectParams* params = sfile->params; - x = event->x - ar->winrct.xmin; - y = event->y - ar->winrct.ymin; + RNA_string_get(op->ptr, "dir", entry); + 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; - file_select_bookmark(sfile, ar, x, y); - ED_area_tag_redraw(sa); + WM_event_add_notifier(C, NC_FILE|ND_PARAMS, NULL); + } + return OPERATOR_FINISHED; } @@ -380,6 +332,8 @@ void FILE_OT_select_bookmark(wmOperatorType *ot) /* api callbacks */ ot->invoke= bookmark_select_invoke; ot->poll= ED_operator_file_active; + + RNA_def_string(ot->srna, "dir", "", 256, "Dir", ""); } static int loadimages_invoke(bContext *C, wmOperator *op, wmEvent *event) @@ -548,7 +502,7 @@ int file_parent_exec(bContext *C, wmOperator *unused) filelist_free(sfile->files); sfile->params->active_file = -1; } - ED_area_tag_redraw(CTX_wm_area(C)); + WM_event_add_notifier(C, NC_FILE|ND_FILELIST, NULL); return OPERATOR_FINISHED; @@ -575,8 +529,8 @@ int file_refresh_exec(bContext *C, wmOperator *unused) filelist_setdir(sfile->files, sfile->params->dir); filelist_free(sfile->files); sfile->params->active_file = -1; - } - ED_area_tag_redraw(CTX_wm_area(C)); + } + WM_event_add_notifier(C, NC_FILE|ND_FILELIST, NULL); return OPERATOR_FINISHED; @@ -596,12 +550,29 @@ void FILE_OT_refresh(struct wmOperatorType *ot) 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) |