diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-06-16 19:28:39 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-06-16 19:28:39 +0400 |
commit | dce577ad85e9c3349000143cf4e7647254c01cb9 (patch) | |
tree | b8b55655d65391ad35af1493dea1a76313cecdf4 /source/blender/editors/space_buttons/buttons_ops.c | |
parent | fd24c99b5ddd251ee64f95ae227ba76bcf9cb561 (diff) |
use directory selector for properties defined as PROP_DIRPATH, user preferences 'File' buttons for eg.
Diffstat (limited to 'source/blender/editors/space_buttons/buttons_ops.c')
-rw-r--r-- | source/blender/editors/space_buttons/buttons_ops.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/source/blender/editors/space_buttons/buttons_ops.c b/source/blender/editors/space_buttons/buttons_ops.c index 9b914df1b3c..99e5c6d693e 100644 --- a/source/blender/editors/space_buttons/buttons_ops.c +++ b/source/blender/editors/space_buttons/buttons_ops.c @@ -104,11 +104,12 @@ static int file_browse_exec(bContext *C, wmOperator *op) FileBrowseOp *fbo= op->customdata; ID *id; char *base, *str, path[FILE_MAX]; + const char *path_prop= RNA_struct_find_property(op->ptr, "directory") ? "directory" : "filepath"; - if (RNA_property_is_set(op->ptr, "filepath")==0 || fbo==NULL) + if (RNA_property_is_set(op->ptr, path_prop)==0 || fbo==NULL) return OPERATOR_CANCELLED; - str= RNA_string_get_alloc(op->ptr, "filepath", NULL, 0); + str= RNA_string_get_alloc(op->ptr, path_prop, NULL, 0); /* add slash for directories, important for some properties */ if(RNA_property_subtype(fbo->prop) == PROP_DIRPATH) { @@ -191,12 +192,13 @@ static int file_browse_invoke(bContext *C, wmOperator *op, wmEvent *event) return OPERATOR_CANCELLED; } else { + const char *path_prop= RNA_struct_find_property(op->ptr, "directory") ? "directory" : "filepath"; fbo= MEM_callocN(sizeof(FileBrowseOp), "FileBrowseOp"); fbo->ptr= ptr; fbo->prop= prop; op->customdata= fbo; - RNA_string_set(op->ptr, "filepath", str); + RNA_string_set(op->ptr, path_prop, str); MEM_freeN(str); if(RNA_struct_find_property(op->ptr, "relative_path")) { @@ -227,3 +229,19 @@ void BUTTONS_OT_file_browse(wmOperatorType *ot) WM_operator_properties_filesel(ot, 0, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_FILEPATH|WM_FILESEL_RELPATH); } +/* second operator, only difference from BUTTONS_OT_file_browse is WM_FILESEL_DIRECTORY */ +void BUTTONS_OT_directory_browse(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Accept"; + ot->description="Open a directory browser, Hold Shift to open the file, Alt to browse containing directory"; + ot->idname= "BUTTONS_OT_directory_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, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_DIRECTORY|WM_FILESEL_RELPATH); +} |