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/space_buttons/buttons_ops.c | |
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/space_buttons/buttons_ops.c')
-rw-r--r-- | source/blender/editors/space_buttons/buttons_ops.c | 71 |
1 files changed, 71 insertions, 0 deletions
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); +} + |