forked from bartvdbraak/blender
Usablity:
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
This commit is contained in:
parent
c4ae6f2c36
commit
1165236f69
@ -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
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 ********************/
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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";
|
||||
|
||||
|
@ -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 */
|
||||
|
@ -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 ******************* */
|
||||
|
Loading…
Reference in New Issue
Block a user