diff options
author | Joshua Leung <aligorith@gmail.com> | 2011-02-15 04:24:12 +0300 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2011-02-15 04:24:12 +0300 |
commit | b47bfd85e8364ae5f97f1318d0ced0cbe5755512 (patch) | |
tree | 7b326763385045e793d548553b4e0e272a80ee66 | |
parent | dab76a3ccfba7dd72543d671461b449e939ac1e2 (diff) |
UI Tweaks: Text field in Rename Markers popup now gets focus when the
popup appears, saving an extra click
I've separated out the "XXX"-'d event-adding-hack section from the
search-menu code into a separate API function (as recommended there).
This call is used to make sure that textboxes in popups can get
activated by default, to allow typing immediately.
-rw-r--r-- | source/blender/editors/include/UI_interface.h | 2 | ||||
-rw-r--r-- | source/blender/editors/interface/interface.c | 16 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_layout.c | 13 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_templates.c | 9 |
4 files changed, 31 insertions, 9 deletions
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 76c9e765188..3e607b37067 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -548,6 +548,8 @@ void uiButSetCompleteFunc(uiBut *but, uiButCompleteFunc func, void *arg); void uiBlockSetDrawExtraFunc(uiBlock *block, void (*func)(const struct bContext *C, void *, void *, void *, struct rcti *rect), void *arg1, void *arg2); +void uiButSetFocusOnEnter (struct wmWindow *win, uiBut *but); + /* Autocomplete * * Tab complete helper functions, for use in uiButCompleteFunc callbacks. diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 5929eb54026..559249fd17d 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -3510,6 +3510,22 @@ void uiButSetSearchFunc(uiBut *but, uiButSearchFunc sfunc, void *arg, uiButHandl } } +/* push a new event onto event queue to activate the given button + * (usually a text-field) upon entering a popup + */ +void uiButSetFocusOnEnter(wmWindow *win, uiBut *but) +{ + wmEvent event; + + event= *(win->eventstate); + event.type= EVT_BUT_OPEN; + event.val= KM_PRESS; + event.customdata= but; + event.customdatafree= FALSE; + + wm_event_add(win, &event); +} + /* Program Init/Exit */ void UI_init(void) diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index 330c81fbcb2..4398e7a2287 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -2733,11 +2733,20 @@ void uiLayoutOperatorButs(const bContext *C, uiLayout *layout, wmOperator *op,in } } - /* no undo for buttons for operator redo panels */ + /* set various special settings for buttons */ { uiBut *but; - for(but= uiLayoutGetBlock(layout)->buttons.first; but; but= but->next) + for(but= uiLayoutGetBlock(layout)->buttons.first; but; but= but->next) { + /* no undo for buttons for operator redo panels */ uiButClearFlag(but, UI_BUT_UNDO); + + /* if button is operator's default property, and a text-field, enable focus for it + * - this is used for allowing operators with popups to rename stuff with fewer clicks + */ + if ((but->rnaprop == op->type->prop) && (but->type == TEX)) { + uiButSetFocusOnEnter(CTX_wm_window(C), but); + } + } } } diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index b0707a8b34b..5be5c6fa0c4 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -144,7 +144,6 @@ static uiBlock *id_search_menu(bContext *C, ARegion *ar, void *arg_litem) static char search[256]; static TemplateID template; PointerRNA idptr; - wmEvent event; wmWindow *win= CTX_wm_window(C); uiBlock *block; uiBut *but; @@ -185,12 +184,8 @@ static uiBlock *id_search_menu(bContext *C, ARegion *ar, void *arg_litem) uiBlockSetDirection(block, UI_DOWN); uiEndBlock(C, block); - event= *(win->eventstate); /* XXX huh huh? make api call */ - event.type= EVT_BUT_OPEN; - event.val= KM_PRESS; - event.customdata= but; - event.customdatafree= FALSE; - wm_event_add(win, &event); + /* give search-field focus */ + uiButSetFocusOnEnter(win, but); return block; } |