forked from bartvdbraak/blender
use directory selector for properties defined as PROP_DIRPATH, user preferences 'File' buttons for eg.
This commit is contained in:
parent
fd24c99b5d
commit
dce577ad85
@ -534,7 +534,10 @@ static uiBut *ui_item_with_label(uiLayout *layout, uiBlock *block, const char *n
|
||||
uiDefAutoButR(block, ptr, prop, index, "", icon, x, y, w-UI_UNIT_X, h);
|
||||
|
||||
/* 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, NULL);
|
||||
but= uiDefIconButO(block, BUT, subtype==PROP_DIRPATH ?
|
||||
"BUTTONS_OT_directory_browse" :
|
||||
"BUTTONS_OT_file_browse",
|
||||
WM_OP_INVOKE_DEFAULT, ICON_FILESEL, x, y, UI_UNIT_X, h, NULL);
|
||||
}
|
||||
else if(flag & UI_ITEM_R_EVENT) {
|
||||
uiDefButR(block, KEYEVT, 0, name, x, y, w, h, ptr, RNA_property_identifier(prop), index, 0, 0, -1, -1, NULL);
|
||||
|
@ -71,6 +71,7 @@ extern const char *buttons_context_dir[]; /* doc access */
|
||||
|
||||
/* buttons_ops.c */
|
||||
void BUTTONS_OT_file_browse(struct wmOperatorType *ot);
|
||||
void BUTTONS_OT_directory_browse(struct wmOperatorType *ot);
|
||||
void BUTTONS_OT_toolbox(struct wmOperatorType *ot);
|
||||
|
||||
#endif /* ED_BUTTONS_INTERN_H */
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -187,6 +187,7 @@ static void buttons_operatortypes(void)
|
||||
{
|
||||
WM_operatortype_append(BUTTONS_OT_toolbox);
|
||||
WM_operatortype_append(BUTTONS_OT_file_browse);
|
||||
WM_operatortype_append(BUTTONS_OT_directory_browse);
|
||||
}
|
||||
|
||||
static void buttons_keymap(struct wmKeyConfig *keyconf)
|
||||
|
Loading…
Reference in New Issue
Block a user