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.
This commit is contained in:
2011-02-15 01:24:12 +00:00
parent dab76a3ccf
commit b47bfd85e8
4 changed files with 31 additions and 9 deletions

View File

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

View File

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

View File

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

View File

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