diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-07-28 22:51:06 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-07-28 22:51:06 +0400 |
commit | 9a874da36c2e9eb5a4d48c8c7bbce3db48f882a9 (patch) | |
tree | d0b93897f73e1b2b461b57b85b73911dccdfa77a /source/blender/editors | |
parent | 5d7a7525a4a5d593fd708801d5fd54f4d5a3035a (diff) |
2.5: File browse button in ui layouts now works, e.g. for render
output path or fluidsim path.
Diffstat (limited to 'source/blender/editors')
7 files changed, 121 insertions, 4 deletions
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index d818f298de7..70fbad3216d 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -142,6 +142,7 @@ typedef struct uiLayout uiLayout; #define UI_BUT_ANIMATED_KEY (1<<21) #define UI_BUT_DRIVEN (1<<22) #define UI_BUT_INACTIVE (1<<23) +#define UI_BUT_LAST_ACTIVE (1<<24) #define UI_PANEL_WIDTH 340 #define UI_COMPACT_PANEL_WIDTH 160 @@ -674,9 +675,9 @@ void uiItemMenuF(uiLayout *layout, char *name, int icon, uiMenuCreateFunc func); void uiItemMenuEnumO(uiLayout *layout, char *name, int icon, char *opname, char *propname); void uiItemMenuEnumR(uiLayout *layout, char *name, int icon, struct PointerRNA *ptr, char *propname); -/* Animation */ - +/* Helpers for Operators */ void uiAnimContextProperty(const struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA **prop, int *index); +void uiFileBrowseContextProperty(const struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA **prop); /* Styled text draw */ void uiStyleFontSet(struct uiFontStyle *fs); diff --git a/source/blender/editors/interface/interface_anim.c b/source/blender/editors/interface/interface_anim.c index 4a2ef50a31b..d2e9236fcff 100644 --- a/source/blender/editors/interface/interface_anim.c +++ b/source/blender/editors/interface/interface_anim.c @@ -165,6 +165,10 @@ void uiAnimContextProperty(const bContext *C, struct PointerRNA *ptr, struct Pro uiBlock *block; uiBut *but; + memset(ptr, 0, sizeof(*ptr)); + *prop= NULL; + *index= 0; + if(ar) { for(block=ar->uiblocks.first; block; block=block->next) { for(but=block->buttons.first; but; but= but->next) { diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 50877439e89..93293a6f352 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -3687,6 +3687,7 @@ static void button_activate_init(bContext *C, ARegion *ar, uiBut *but, uiButtonA static void button_activate_exit(bContext *C, uiHandleButtonData *data, uiBut *but, int mousemove) { uiBlock *block= but->block; + uiBut *bt; /* ensure we are in the exit state */ if(data->state != BUTTON_STATE_EXIT) @@ -3712,7 +3713,14 @@ static void button_activate_exit(bContext *C, uiHandleButtonData *data, uiBut *b if(!data->cancel) ui_apply_autokey_undo(C, but); - /* disable tooltips until mousemove */ + /* disable tooltips until mousemove + last active flag */ + for(block=data->region->uiblocks.first; block; block=block->next) { + for(bt=block->buttons.first; bt; bt=bt->next) + bt->flag &= ~UI_BUT_LAST_ACTIVE; + + block->tooltipdisabled= 1; + } + ui_blocks_set_tooltips(data->region, 0); /* clean up */ @@ -3728,6 +3736,7 @@ static void button_activate_exit(bContext *C, uiHandleButtonData *data, uiBut *b MEM_freeN(but->active); but->active= NULL; but->flag &= ~(UI_ACTIVE|UI_SELECT); + but->flag |= UI_BUT_LAST_ACTIVE; ui_check_but(but); /* adds empty mousemove in queue for re-init handler, in case mouse is diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index 2705cde27c9..6932ad350b0 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -486,7 +486,9 @@ static uiBut *ui_item_with_label(uiLayout *layout, uiBlock *block, char *name, i if(subtype == PROP_FILEPATH || subtype == PROP_DIRPATH) { uiBlockSetCurLayout(block, uiLayoutRow(sub, 1)); uiDefAutoButR(block, ptr, prop, index, "", icon, x, y, w-UI_UNIT_X, h); - but= uiDefIconBut(block, BUT, 0, ICON_FILESEL, x, y, UI_UNIT_X, h, NULL, 0.0f, 0.0f, 0.0f, 0.0f, "DUMMY file select button"); /* XXX */ + + /* BUTTONS_OT_file_browse calls uiFileBrowseContextProperty */ + but= uiDefIconButO(block, BUT, "BUTTONS_OT_file_browse", WM_OP_INVOKE_DEFAULT, ICON_FILESEL, x, y, UI_UNIT_X, h, "Browse for file or directory."); } else but= uiDefAutoButR(block, ptr, prop, index, "", icon, x, y, w, h); @@ -495,6 +497,34 @@ static uiBut *ui_item_with_label(uiLayout *layout, uiBlock *block, char *name, i return but; } +void uiFileBrowseContextProperty(const bContext *C, PointerRNA *ptr, PropertyRNA **prop) +{ + ARegion *ar= CTX_wm_region(C); + uiBlock *block; + uiBut *but, *prevbut; + + memset(ptr, 0, sizeof(*ptr)); + *prop= NULL; + + if(!ar) + return; + + for(block=ar->uiblocks.first; block; block=block->next) { + for(but=block->buttons.first; but; but= but->next) { + prevbut= but->prev; + + /* find the button before the active one */ + if((but->flag & UI_BUT_LAST_ACTIVE) && prevbut && prevbut->rnapoin.id.data) { + if(RNA_property_type(prevbut->rnaprop) == PROP_STRING) { + *ptr= prevbut->rnapoin; + *prop= prevbut->rnaprop; + return; + } + } + } + } +} + /********************* Button Items *************************/ /* disabled item */ diff --git a/source/blender/editors/space_buttons/buttons_intern.h b/source/blender/editors/space_buttons/buttons_intern.h index c505c7fdb18..8ed17ab1fa8 100644 --- a/source/blender/editors/space_buttons/buttons_intern.h +++ b/source/blender/editors/space_buttons/buttons_intern.h @@ -89,6 +89,7 @@ void PARTICLE_OT_target_move_down(struct wmOperatorType *ot); void SCENE_OT_render_layer_add(struct wmOperatorType *ot); void SCENE_OT_render_layer_remove(struct wmOperatorType *ot); +void BUTTONS_OT_file_browse(struct wmOperatorType *ot); void BUTTONS_OT_toolbox(struct wmOperatorType *ot); #endif /* ED_BUTTONS_INTERN_H */ diff --git a/source/blender/editors/space_buttons/buttons_ops.c b/source/blender/editors/space_buttons/buttons_ops.c index b1ffc7249f4..e52efe8508d 100644 --- a/source/blender/editors/space_buttons/buttons_ops.c +++ b/source/blender/editors/space_buttons/buttons_ops.c @@ -72,6 +72,7 @@ #include "RNA_define.h" #include "UI_interface.h" +#include "UI_resources.h" #include "buttons_intern.h" // own include @@ -935,3 +936,73 @@ void BUTTONS_OT_toolbox(wmOperatorType *ot) ot->invoke= toolbox_invoke; } +/********************** filebrowse operator *********************/ + +typedef struct FileBrowseOp { + PointerRNA ptr; + PropertyRNA *prop; +} FileBrowseOp; + +static int file_browse_exec(bContext *C, wmOperator *op) +{ + FileBrowseOp *fbo= op->customdata; + char *str; + + str= RNA_string_get_alloc(op->ptr, "filename", 0, 0); + RNA_property_string_set(&fbo->ptr, fbo->prop, str); + RNA_property_update(C, &fbo->ptr, fbo->prop); + MEM_freeN(str); + + MEM_freeN(op->customdata); + return OPERATOR_FINISHED; +} + +static int file_browse_cancel(bContext *C, wmOperator *op) +{ + MEM_freeN(op->customdata); + op->customdata= NULL; + + return OPERATOR_CANCELLED; +} + +static int file_browse_invoke(bContext *C, wmOperator *op, wmEvent *event) +{ + PointerRNA ptr; + PropertyRNA *prop; + FileBrowseOp *fbo; + char *str; + + uiFileBrowseContextProperty(C, &ptr, &prop); + + if(!prop) + return OPERATOR_CANCELLED; + + fbo= MEM_callocN(sizeof(FileBrowseOp), "FileBrowseOp"); + fbo->ptr= ptr; + fbo->prop= prop; + op->customdata= fbo; + + str= RNA_property_string_get_alloc(&ptr, prop, 0, 0); + RNA_string_set(op->ptr, "filename", str); + MEM_freeN(str); + + WM_event_add_fileselect(C, op); + + return OPERATOR_RUNNING_MODAL; +} + +void BUTTONS_OT_file_browse(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "File Browse"; + ot->idname= "BUTTONS_OT_file_browse"; + + /* api callbacks */ + ot->invoke= file_browse_invoke; + ot->exec= file_browse_exec; + ot->cancel= file_browse_cancel; + + /* properties */ + WM_operator_properties_filesel(ot, 0); +} + diff --git a/source/blender/editors/space_buttons/space_buttons.c b/source/blender/editors/space_buttons/space_buttons.c index 0195ba4b18d..0f57152cef6 100644 --- a/source/blender/editors/space_buttons/space_buttons.c +++ b/source/blender/editors/space_buttons/space_buttons.c @@ -209,6 +209,7 @@ void buttons_operatortypes(void) WM_operatortype_append(SCENE_OT_render_layer_remove); WM_operatortype_append(BUTTONS_OT_toolbox); + WM_operatortype_append(BUTTONS_OT_file_browse); } void buttons_keymap(struct wmWindowManager *wm) |