diff options
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/include/UI_interface.h | 5 | ||||
-rw-r--r-- | source/blender/editors/interface/interface.c | 18 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_layout.c | 17 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_region_popover.c | 10 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_ui.c | 17 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_operators.c | 4 |
6 files changed, 70 insertions, 1 deletions
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 7d28c538780..80f58a9548b 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -201,6 +201,8 @@ enum { UI_BUT_LIST_ITEM = 1 << 24, /** edit this button as well as the active button (not just dragging) */ UI_BUT_DRAG_MULTI = 1 << 25, + /** Use for popups to start editing the button on initialization. */ + UI_BUT_ACTIVATE_ON_INIT = 1 << 26, /** #uiBut.str contains #UI_SEP_CHAR, used for key shortcuts */ UI_BUT_HAS_SEP_CHAR = 1 << 27, @@ -631,6 +633,7 @@ void UI_but_type_set_menu_from_pulldown(uiBut *but); /* special button case, only draw it when used actively, for outliner etc */ bool UI_but_active_only(const struct bContext *C, struct ARegion *ar, uiBlock *block, uiBut *but); +bool UI_block_active_only_flagged_buttons(const struct bContext *C, struct ARegion *ar, struct uiBlock *block); void UI_but_execute(const struct bContext *C, uiBut *but); @@ -1053,6 +1056,7 @@ void uiLayoutSetContextFromBut(uiLayout *layout, uiBut *but); void uiLayoutSetOperatorContext(uiLayout *layout, int opcontext); void uiLayoutSetActive(uiLayout *layout, bool active); +void uiLayoutSetActivateInit(uiLayout *layout, bool active); void uiLayoutSetEnabled(uiLayout *layout, bool enabled); void uiLayoutSetRedAlert(uiLayout *layout, bool redalert); void uiLayoutSetAlignment(uiLayout *layout, char alignment); @@ -1068,6 +1072,7 @@ int uiLayoutGetLocalDir(const uiLayout *layout); int uiLayoutGetOperatorContext(uiLayout *layout); bool uiLayoutGetActive(uiLayout *layout); +bool uiLayoutGetActivateInit(uiLayout *layout); bool uiLayoutGetEnabled(uiLayout *layout); bool uiLayoutGetRedAlert(uiLayout *layout); int uiLayoutGetAlignment(uiLayout *layout); diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 1e079835ec5..16c87b7a7d7 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -823,6 +823,24 @@ bool UI_but_active_only(const bContext *C, ARegion *ar, uiBlock *block, uiBut *b return true; } +bool UI_block_active_only_flagged_buttons(const bContext *C, ARegion *ar, uiBlock *block) +{ + bool done = false; + for (uiBut *but = block->buttons.first; but; but = but->next) { + if (!done && ui_but_is_editable(but)) { + if (but->flag & UI_BUT_ACTIVATE_ON_INIT) { + if (UI_but_active_only(C, ar, block, but)) { + done = true; + } + } + } + but->flag &= ~UI_BUT_ACTIVATE_ON_INIT; + } + return done; +} + + + /* simulate button click */ void UI_but_execute(const bContext *C, uiBut *but) { diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index a828c19be54..95791dc8811 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -160,6 +160,7 @@ struct uiLayout { short space; bool align; bool active; + bool activate_init; bool enabled; bool redalert; bool keepaspect; @@ -1818,6 +1819,9 @@ void uiItemFullR(uiLayout *layout, PointerRNA *ptr, PropertyRNA *prop, int index if (layout->redalert) UI_but_flag_enable(but, UI_BUT_REDALERT); + + if (layout->activate_init) + UI_but_flag_enable(but, UI_BUT_ACTIVATE_ON_INIT); } /* single button */ else { @@ -1831,6 +1835,9 @@ void uiItemFullR(uiLayout *layout, PointerRNA *ptr, PropertyRNA *prop, int index if (layout->redalert) UI_but_flag_enable(but, UI_BUT_REDALERT); + + if (layout->activate_init) + UI_but_flag_enable(but, UI_BUT_ACTIVATE_ON_INIT); } /* Mark non-embossed textfields inside a listbox. */ @@ -3949,6 +3956,11 @@ void uiLayoutSetActive(uiLayout *layout, bool active) layout->active = active; } +void uiLayoutSetActivateInit(uiLayout *layout, bool activate_init) +{ + layout->activate_init = activate_init; +} + void uiLayoutSetEnabled(uiLayout *layout, bool enabled) { layout->enabled = enabled; @@ -4019,6 +4031,11 @@ bool uiLayoutGetActive(uiLayout *layout) return layout->active; } +bool uiLayoutGetActivateInit(uiLayout *layout) +{ + return layout->activate_init; +} + bool uiLayoutGetEnabled(uiLayout *layout) { return layout->enabled; diff --git a/source/blender/editors/interface/interface_region_popover.c b/source/blender/editors/interface/interface_region_popover.c index d15eb7a3246..3176c7a454a 100644 --- a/source/blender/editors/interface/interface_region_popover.c +++ b/source/blender/editors/interface/interface_region_popover.c @@ -302,16 +302,24 @@ int UI_popover_panel_invoke( return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH); } + uiBlock *block = NULL; if (keep_open) { - ui_popover_panel_create(C, NULL, NULL, ui_item_paneltype_func, pt); + uiPopupBlockHandle *handle = ui_popover_panel_create(C, NULL, NULL, ui_item_paneltype_func, pt); + uiPopover *pup = handle->popup_create_vars.arg; + block = pup->block; + } else { uiPopover *pup = UI_popover_begin(C, U.widget_unit * pt->ui_units_x); layout = UI_popover_layout(pup); UI_paneltype_draw(C, pt, layout); UI_popover_end(C, pup, NULL); + block = pup->block; } + if (block) { + UI_block_active_only_flagged_buttons(C, CTX_wm_region(C), block); + } return OPERATOR_INTERFACE; } diff --git a/source/blender/makesrna/intern/rna_ui.c b/source/blender/makesrna/intern/rna_ui.c index 5bc647493cc..7c10b3eff77 100644 --- a/source/blender/makesrna/intern/rna_ui.c +++ b/source/blender/makesrna/intern/rna_ui.c @@ -881,6 +881,16 @@ static void rna_UILayout_active_set(PointerRNA *ptr, bool value) uiLayoutSetActive(ptr->data, value); } +static bool rna_UILayout_activate_init_get(PointerRNA *ptr) +{ + return uiLayoutGetActivateInit(ptr->data); +} + +static void rna_UILayout_activate_init_set(PointerRNA *ptr, bool value) +{ + uiLayoutSetActivateInit(ptr->data, value); +} + static bool rna_UILayout_alert_get(PointerRNA *ptr) { return uiLayoutGetRedAlert(ptr->data); @@ -1056,6 +1066,13 @@ static void rna_def_ui_layout(BlenderRNA *brna) prop = RNA_def_property(srna, "active", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_funcs(prop, "rna_UILayout_active_get", "rna_UILayout_active_set"); + prop = RNA_def_property(srna, "activate_init", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_funcs(prop, "rna_UILayout_activate_init_get", "rna_UILayout_activate_init_set"); + RNA_def_property_ui_text( + prop, "Activate on Init", + "When true, buttons defined in popups will be activated on first display " + "(use so you can type into a field without having to click on it first)"); + prop = RNA_def_property(srna, "operator_context", PROP_ENUM, PROP_NONE); RNA_def_property_enum_items(prop, rna_enum_operator_context_items); RNA_def_property_enum_funcs(prop, "rna_UILayout_op_context_get", "rna_UILayout_op_context_set", NULL); diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index ac7d496ea35..979473cf761 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -1154,6 +1154,8 @@ static uiBlock *wm_block_dialog_create(bContext *C, ARegion *ar, void *userData) /* center around the mouse */ UI_block_bounds_set_popup(block, 4, (const int[2]){data->width / -2, data->height / 2}); + UI_block_active_only_flagged_buttons(C, ar, block); + return block; } @@ -1179,6 +1181,8 @@ static uiBlock *wm_operator_ui_create(bContext *C, ARegion *ar, void *userData) UI_block_bounds_set_popup(block, 4, NULL); + UI_block_active_only_flagged_buttons(C, ar, block); + return block; } |