2.5: File browse button in ui layouts now works, e.g. for render

output path or fluidsim path.
This commit is contained in:
2009-07-28 18:51:06 +00:00
parent 5d7a7525a4
commit 9a874da36c
7 changed files with 121 additions and 4 deletions

View File

@@ -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);

View File

@@ -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) {

View File

@@ -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

View File

@@ -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 */

View File

@@ -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 */

View File

@@ -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);
}

View File

@@ -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)