UI Tweaks: Text field in Rename Markers popup now gets focus when the
authorJoshua Leung <aligorith@gmail.com>
Tue, 15 Feb 2011 01:24:12 +0000 (01:24 +0000)
committerJoshua Leung <aligorith@gmail.com>
Tue, 15 Feb 2011 01:24:12 +0000 (01:24 +0000)
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.

source/blender/editors/include/UI_interface.h
source/blender/editors/interface/interface.c
source/blender/editors/interface/interface_layout.c
source/blender/editors/interface/interface_templates.c

index 76c9e765188c063bfd56559e60be680c4712ad86..3e607b370673c550c96157d9bc860a27e43dae54 100644 (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.
index 5929eb5402679b42ef38fd9c6fcb599182c53b79..559249fd17dc716f5b35ef12eac7061b4066ad6c 100644 (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)
index 330c81fbcb2736e7cf7b401ae74e66b3bb20cd03..4398e7a2287c6099004779d198095b548fc3a527 100644 (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);
+                       }
+               }
        }
 }
index b0707a8b34bdac0f523b798777efcbfd26ec129b..5be5c6fa0c4b8b252a77ffb41ab9e5f24e7f7ad0 100644 (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;
 }