diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2011-02-17 21:55:17 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2011-02-17 21:55:17 +0300 |
commit | 0abc0e0468f0cb384f11eed4bf72f6d6cbc8eff8 (patch) | |
tree | 8b21eab36c19d482ba5a7eed2978422fc9ea2a7b /source/blender/editors/space_text/text_ops.c | |
parent | f697247f0e567f87dcce76fa389c9b6a62fcef6a (diff) |
Split cursor_set into two operators:
- cursor_set which just sets cursor position immediatelly
- selection_set which could be used to select block of text
Now there're could be operators binded to mouse double-click event
Diffstat (limited to 'source/blender/editors/space_text/text_ops.c')
-rw-r--r-- | source/blender/editors/space_text/text_ops.c | 102 |
1 files changed, 72 insertions, 30 deletions
diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index 3d862030e40..4294be121ea 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -2009,11 +2009,11 @@ static void screen_skip(SpaceText *st, ARegion *ar, int lines) } /* quick enum for tsc->zone (scroller handles) */ -static enum { +enum { SCROLLHANDLE_BAR, SCROLLHANDLE_MIN_OUTSIDE, SCROLLHANDLE_MAX_OUTSIDE -} TextScrollerHandle_Zone; +}; typedef struct TextScroll { short old[2]; @@ -2286,13 +2286,13 @@ void TEXT_OT_scroll_bar(wmOperatorType *ot) RNA_def_int(ot->srna, "lines", 1, INT_MIN, INT_MAX, "Lines", "Number of lines to scroll.", -100, 100); } -/******************* set cursor operator **********************/ +/******************* set selection operator **********************/ -typedef struct SetCursor { +typedef struct SetSelection { int selecting; int selc, sell; short old[2]; -} SetCursor; +} SetSelection; static void set_cursor_to_pos(SpaceText *st, ARegion *ar, int x, int y, int sel) { @@ -2458,10 +2458,10 @@ static void set_cursor_apply(bContext *C, wmOperator *op, wmEvent *event) { SpaceText *st= CTX_wm_space_text(C); ARegion *ar= CTX_wm_region(C); - SetCursor *scu= op->customdata; + SetSelection *ssel= op->customdata; if(event->mval[1]<0 || event->mval[1]>ar->winy) { - int d= (scu->old[1]-event->mval[1])*st->pix_per_line; + int d= (ssel->old[1]-event->mval[1])*st->pix_per_line; if(d) screen_skip(st, ar, d); set_cursor_to_pos(st, ar, event->mval[0], event->mval[1]<0?0:ar->winy, 1); @@ -2485,8 +2485,8 @@ static void set_cursor_apply(bContext *C, wmOperator *op, wmEvent *event) text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, st->text); - scu->old[0]= event->mval[0]; - scu->old[1]= event->mval[1]; + ssel->old[0]= event->mval[0]; + ssel->old[1]= event->mval[1]; } } @@ -2494,7 +2494,7 @@ static void set_cursor_exit(bContext *C, wmOperator *op) { SpaceText *st= CTX_wm_space_text(C); Text *text= st->text; - SetCursor *scu= op->customdata; + SetSelection *ssel= op->customdata; int linep2, charp2; char *buffer; @@ -2507,29 +2507,29 @@ static void set_cursor_exit(bContext *C, wmOperator *op) linep2= txt_get_span(st->text->lines.first, st->text->sell); charp2= st->text->selc; - if(scu->sell!=linep2 || scu->selc!=charp2) - txt_undo_add_toop(st->text, UNDO_STO, scu->sell, scu->selc, linep2, charp2); + if(ssel->sell!=linep2 || ssel->selc!=charp2) + txt_undo_add_toop(st->text, UNDO_STO, ssel->sell, ssel->selc, linep2, charp2); text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, st->text); - MEM_freeN(scu); + MEM_freeN(ssel); } -static int set_cursor_invoke(bContext *C, wmOperator *op, wmEvent *event) +static int set_selection_invoke(bContext *C, wmOperator *op, wmEvent *event) { SpaceText *st= CTX_wm_space_text(C); ARegion *ar= CTX_wm_region(C); - SetCursor *scu; + SetSelection *ssel; - op->customdata= MEM_callocN(sizeof(SetCursor), "SetCursor"); - scu= op->customdata; - scu->selecting= RNA_boolean_get(op->ptr, "select"); + op->customdata= MEM_callocN(sizeof(SetSelection), "SetCursor"); + ssel= op->customdata; + ssel->selecting= RNA_boolean_get(op->ptr, "select"); - scu->old[0]= event->mval[0]; - scu->old[1]= event->mval[1]; + ssel->old[0]= event->mval[0]; + ssel->old[1]= event->mval[1]; - if(!scu->selecting) { + if(!ssel->selecting) { int curl= txt_get_span(st->text->lines.first, st->text->curl); int curc= st->text->curc; int linep2, charp2; @@ -2543,8 +2543,8 @@ static int set_cursor_invoke(bContext *C, wmOperator *op, wmEvent *event) txt_undo_add_toop(st->text, UNDO_CTO, curl, curc, linep2, charp2); } - scu->sell= txt_get_span(st->text->lines.first, st->text->sell); - scu->selc= st->text->selc; + ssel->sell= txt_get_span(st->text->lines.first, st->text->sell); + ssel->selc= st->text->selc; WM_event_add_modal_handler(C, op); @@ -2553,7 +2553,7 @@ static int set_cursor_invoke(bContext *C, wmOperator *op, wmEvent *event) return OPERATOR_RUNNING_MODAL; } -static int set_cursor_modal(bContext *C, wmOperator *op, wmEvent *event) +static int set_selection_modal(bContext *C, wmOperator *op, wmEvent *event) { switch(event->type) { case LEFTMOUSE: @@ -2569,27 +2569,69 @@ static int set_cursor_modal(bContext *C, wmOperator *op, wmEvent *event) return OPERATOR_RUNNING_MODAL; } -static int set_cursor_cancel(bContext *C, wmOperator *op) +static int set_selection_cancel(bContext *C, wmOperator *op) { set_cursor_exit(C, op); return OPERATOR_FINISHED; } +void TEXT_OT_selection_set(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Set Selection"; + ot->idname= "TEXT_OT_selection_set"; + ot->description= "Set cursor selection"; + + /* api callbacks */ + ot->invoke= set_selection_invoke; + ot->modal= set_selection_modal; + ot->cancel= set_selection_cancel; + ot->poll= text_region_edit_poll; + + /* properties */ + RNA_def_boolean(ot->srna, "select", 0, "Select", "Set selection end rather than cursor."); +} + +/******************* set cursor operator **********************/ + +static int set_cursor_exec(bContext *C, wmOperator *op) +{ + SpaceText *st= CTX_wm_space_text(C); + ARegion *ar= CTX_wm_region(C); + int x= RNA_int_get(op->ptr, "x"); + int y= RNA_int_get(op->ptr, "y"); + + set_cursor_to_pos(st, ar, x, y, 0); + + text_update_cursor_moved(C); + WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, st->text); + + return OPERATOR_FINISHED; +} + +static int set_cursor_invoke(bContext *C, wmOperator *op, wmEvent *event) +{ + RNA_int_set(op->ptr, "x", event->mval[0]); + RNA_int_set(op->ptr, "y", event->mval[1]); + + return set_cursor_exec(C, op); +} + void TEXT_OT_cursor_set(wmOperatorType *ot) { /* identifiers */ ot->name= "Set Cursor"; ot->idname= "TEXT_OT_cursor_set"; - ot->description= "Set cursor selection"; - + ot->description= "Set cursor position"; + /* api callbacks */ ot->invoke= set_cursor_invoke; - ot->modal= set_cursor_modal; - ot->cancel= set_cursor_cancel; + ot->exec= set_cursor_exec; ot->poll= text_region_edit_poll; /* properties */ - RNA_def_boolean(ot->srna, "select", 0, "Select", "Set selection end rather than cursor."); + RNA_def_boolean(ot->srna, "x", 0, "X", "X-coordinate to set cursor to."); + RNA_def_boolean(ot->srna, "y", 0, "Y", "X-coordinate to set cursor to."); } /******************* line number operator **********************/ |