Split cursor_set into two operators:
authorSergey Sharybin <sergey.vfx@gmail.com>
Thu, 17 Feb 2011 18:55:17 +0000 (18:55 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Thu, 17 Feb 2011 18:55:17 +0000 (18:55 +0000)
- 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

source/blender/editors/space_text/space_text.c
source/blender/editors/space_text/text_intern.h
source/blender/editors/space_text/text_ops.c

index 6e88e2cd6b201fdf6966fd0d0e92906561d8c956..c5a0edaed8dcfb4ebcd3656d188c9ddbb3701735 100644 (file)
@@ -193,6 +193,7 @@ static void text_operatortypes(void)
        WM_operatortype_append(TEXT_OT_delete);
        WM_operatortype_append(TEXT_OT_overwrite_toggle);
 
+       WM_operatortype_append(TEXT_OT_selection_set);
        WM_operatortype_append(TEXT_OT_cursor_set);
        WM_operatortype_append(TEXT_OT_scroll);
        WM_operatortype_append(TEXT_OT_scroll_bar);
@@ -340,9 +341,10 @@ static void text_keymap(struct wmKeyConfig *keyconf)
 
        WM_keymap_add_item(keymap, "TEXT_OT_scroll", MIDDLEMOUSE, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "TEXT_OT_scroll", MOUSEPAN, 0, 0, 0);
-       WM_keymap_add_item(keymap, "TEXT_OT_scroll_bar", LEFTMOUSE, KM_PRESS, 0, 0);
+       WM_keymap_add_item(keymap, "TEXT_OT_scroll_bar", EVT_TWEAK_L, KM_ANY, 0, 0);
+       WM_keymap_add_item(keymap, "TEXT_OT_selection_set", EVT_TWEAK_L, KM_ANY, 0, 0);
        WM_keymap_add_item(keymap, "TEXT_OT_cursor_set", LEFTMOUSE, KM_PRESS, 0, 0);
-       RNA_boolean_set(WM_keymap_add_item(keymap, "TEXT_OT_cursor_set", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "select", 1);
+       RNA_boolean_set(WM_keymap_add_item(keymap, "TEXT_OT_selection_set", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "select", 1);
        RNA_int_set(WM_keymap_add_item(keymap, "TEXT_OT_scroll", WHEELUPMOUSE, KM_PRESS, 0, 0)->ptr, "lines", -1);
        RNA_int_set(WM_keymap_add_item(keymap, "TEXT_OT_scroll", WHEELDOWNMOUSE, KM_PRESS, 0, 0)->ptr, "lines", 1);
 
index 6b0ab523075ba7365e8b8ae80b930bd616502988..7311ac37634ee8276194dfdf0ac1a7ee2d3ce57f 100644 (file)
@@ -142,6 +142,7 @@ void TEXT_OT_overwrite_toggle(struct wmOperatorType *ot);
 
 void TEXT_OT_scroll(struct wmOperatorType *ot);
 void TEXT_OT_scroll_bar(struct wmOperatorType *ot);
+void TEXT_OT_selection_set(struct wmOperatorType *ot);
 void TEXT_OT_cursor_set(struct wmOperatorType *ot);
 void TEXT_OT_line_number(struct wmOperatorType *ot);
 
index 3d862030e4065542510f5f5d6eeb60154c1f435c..4294be121eac0d2172108c5a21bd2d9e11c8b5b6 100644 (file)
@@ -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 **********************/