Usablity:
authorTon Roosendaal <ton@blender.org>
Sun, 24 Mar 2013 13:43:40 +0000 (13:43 +0000)
committerTon Roosendaal <ton@blender.org>
Sun, 24 Mar 2013 13:43:40 +0000 (13:43 +0000)
In text editor, the CTRL+F find now opens property region (or keeps it) and
activates the search button for input.

That's already nice! But next step should be to do a search on exit of
the button (or while typing). That's stuff I need Campbell to help with though.

Notes:
- Probably Py api for property buttons could get an "operator=" arg?
- The warning menu "not found" should go away
- I also suggest to make "wrap" search default for new editors

source/blender/editors/include/UI_interface.h
source/blender/editors/interface/interface_handlers.c
source/blender/editors/space_text/space_text.c
source/blender/editors/space_text/text_header.c
source/blender/editors/space_text/text_intern.h
source/blender/editors/space_text/text_ops.c
source/blender/makesdna/DNA_space_types.h
source/blender/windowmanager/intern/wm_event_system.c

index 3b4415703d5e1c2d1aeb40f2c57a7e606ac8caeb..a446b1d98a3820b96746a99b6985b5943d8cda2e 100644 (file)
@@ -643,6 +643,8 @@ void    uiBlockSetDrawExtraFunc(uiBlock *block,
                                 void (*func)(const struct bContext *C, void *, void *, void *, struct rcti *rect),
                                 void *arg1, void *arg2);
 
+void UI_textbutton_activate_event(const struct bContext *C, struct ARegion *ar, void *basepoin, const char *identifier);
+
 void uiButSetFocusOnEnter(struct wmWindow *win, uiBut *but);
 
 /* Autocomplete
index b34f4c9653fd0e835477ceb864af3d910763e56c..3652e569711cfe81f302b100c219e7112f702562 100644 (file)
@@ -7456,4 +7456,35 @@ void UI_remove_popup_handlers(ListBase *handlers, uiPopupBlockHandle *popup)
        WM_event_remove_ui_handler(handlers, ui_handler_popup, ui_handler_remove_popup, popup, FALSE);
 }
 
+void UI_textbutton_activate_event(const bContext *C, ARegion *ar, void *basepoin, const char *identifier)
+{
+       uiBlock *block;
+       uiBut *but;
+       
+       for (block = ar->uiblocks.first; block; block = block->next) {
+               for (but = block->buttons.first; but; but = but->next) {
+                       if (but->type == TEX) {
+                               if (but->rnaprop && but->rnapoin.data == basepoin)
+                                       if (strcmp(RNA_property_identifier(but->rnaprop), identifier)==0)
+                                               break;
+                               
+                       }
+               }
+               if (but)
+                       break;
+       }
+       
+       if (but) {
+               wmWindow *win = CTX_wm_window(C);
+               wmEvent event;
+               
+               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);
+
+       }
+}
 
index 58e45bc766f0876ca7893a9d5ea53580aa368620..600cbdb326bafb547c46e19b2dd02e58bf2e0038 100644 (file)
@@ -220,6 +220,8 @@ static void text_operatortypes(void)
        WM_operatortype_append(TEXT_OT_replace);
        WM_operatortype_append(TEXT_OT_replace_set_selected);
 
+       WM_operatortype_append(TEXT_OT_start_find);
+       
        WM_operatortype_append(TEXT_OT_to_3d_object);
 
        WM_operatortype_append(TEXT_OT_resolve_conflict);
@@ -233,9 +235,9 @@ static void text_keymap(struct wmKeyConfig *keyconf)
        wmKeyMapItem *kmi;
        
        keymap = WM_keymap_find(keyconf, "Text Generic", SPACE_TEXT, 0);
-       WM_keymap_add_item(keymap, "TEXT_OT_properties", FKEY, KM_PRESS, KM_CTRL, 0);
+       WM_keymap_add_item(keymap, "TEXT_OT_start_find", FKEY, KM_PRESS, KM_CTRL, 0);
 #ifdef __APPLE__
-       WM_keymap_add_item(keymap, "TEXT_OT_properties", FKEY, KM_PRESS, KM_OSKEY, 0);
+       WM_keymap_add_item(keymap, "TEXT_OT_start_find", FKEY, KM_PRESS, KM_OSKEY, 0);
 #endif
        
        keymap = WM_keymap_find(keyconf, "Text", SPACE_TEXT, 0);
@@ -515,7 +517,16 @@ static void text_properties_area_init(wmWindowManager *wm, ARegion *ar)
 
 static void text_properties_area_draw(const bContext *C, ARegion *ar)
 {
+       SpaceText *st = CTX_wm_space_text(C);
+       
        ED_region_panels(C, ar, 1, NULL, -1);
+       
+       /* this flag trick is make sure buttons have been added already */
+       if (st->flags & ST_FIND_ACTIVATE) {
+               
+               UI_textbutton_activate_event(C, ar, st, "find_text");
+               st->flags &= ~ST_FIND_ACTIVATE;
+       }
 }
 
 /********************* registration ********************/
index 605a08e587aecd40542d9eb3b4c9a385c336193f..aaeea40c1a5fef1ce471fb44dbc14b34fac01e0f 100644 (file)
@@ -113,6 +113,38 @@ void TEXT_OT_properties(wmOperatorType *ot)
        ot->poll = text_properties_poll;
 }
 
+static int text_text_search_exec(bContext *C, wmOperator *UNUSED(op))
+{
+       ScrArea *sa = CTX_wm_area(C);
+       ARegion *ar = text_has_properties_region(sa);
+       SpaceText *st = CTX_wm_space_text(C);
+       
+       if (ar) {
+               if (ar->flag & RGN_FLAG_HIDDEN)
+                       ED_region_toggle_hidden(C, ar);
+               
+               /* cannot send a button activate yet for case when region wasn't visible yet */
+               /* flag gets checked and cleared in main draw callback */
+               st->flags |= ST_FIND_ACTIVATE;
+               
+               ED_region_tag_redraw(ar);
+       }
+       return OPERATOR_FINISHED;
+}
+
+
+void TEXT_OT_start_find(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name = "Find";
+       ot->description = "Start searching text";
+       ot->idname = "TEXT_OT_start_find";
+       
+       /* api callbacks */
+       ot->exec = text_text_search_exec;
+       ot->poll = text_properties_poll;
+}
+
 /******************** XXX popup menus *******************/
 
 #if 0
index 799bc49b6246c4d6d33c19fd0aaa752377bb9b3b..371ccfd9bd9c437ae06e1cac726cb1eda9e805bf 100644 (file)
@@ -134,11 +134,15 @@ void TEXT_OT_line_number(struct wmOperatorType *ot);
 
 void TEXT_OT_properties(struct wmOperatorType *ot);
 
+/* find = find indicated text */
 void TEXT_OT_find(struct wmOperatorType *ot);
 void TEXT_OT_find_set_selected(struct wmOperatorType *ot);
 void TEXT_OT_replace(struct wmOperatorType *ot);
 void TEXT_OT_replace_set_selected(struct wmOperatorType *ot);
 
+/* text_find = open properties, activate search button */
+void TEXT_OT_start_find(struct wmOperatorType *ot);
+
 void TEXT_OT_to_3d_object(struct wmOperatorType *ot);
 
 void TEXT_OT_resolve_conflict(struct wmOperatorType *ot);
index cdbb3e7c600fc61b37f6dcebeefd0951f716c07a..b4dc4f553684c269aac01ab9873f559b2b35f2bf 100644 (file)
@@ -2966,7 +2966,7 @@ static int text_find_exec(bContext *C, wmOperator *op)
 void TEXT_OT_find(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name = "Find";
+       ot->name = "Find Next";
        ot->idname = "TEXT_OT_find";
        ot->description = "Find specified text";
        
index a810f4219e00318df2c8a6db527d08ff540637d9..e5e38d66de5b049d1126f6c8eb2e2910df52b582 100644 (file)
@@ -840,6 +840,8 @@ typedef enum eSpaceText_Flags {
        ST_FIND_ALL             = (1 << 6),
        ST_SHOW_MARGIN          = (1 << 7),
        ST_MATCH_CASE           = (1 << 8),
+       
+       ST_FIND_ACTIVATE                = (1 << 9),
 } eSpaceText_Flags;
 
 /* stext->findstr/replacestr */
index b2647626f3aaa039dc62e955575c8797f422f3bf..6c129ec0a924da299c1bb15aa52da79d385a66a8 100644 (file)
@@ -339,7 +339,7 @@ void wm_event_do_notifiers(bContext *C)
 static int wm_event_always_pass(wmEvent *event)
 {
        /* some events we always pass on, to ensure proper communication */
-       return ISTIMER(event->type) || (event->type == WINDEACTIVATE);
+       return ISTIMER(event->type) || (event->type == WINDEACTIVATE) || (event->type == EVT_BUT_OPEN);
 }
 
 /* ********************* ui handler ******************* */