4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * Contributor(s): Campbell Barton
22 * ***** END GPL LICENSE BLOCK *****
27 #include <ctype.h> /* ispunct */
30 #include "MEM_guardedalloc.h"
32 #include "DNA_userdef_types.h"
34 #include "BLI_blenlib.h"
35 #include "BLI_dynstr.h"
37 #include "BKE_context.h"
38 #include "BKE_text.h" /* only for character utility funcs */
43 #include "UI_view2d.h"
44 #include "ED_screen.h"
46 #include "RNA_access.h"
47 #include "RNA_define.h"
49 #include "console_intern.h"
51 static void console_textview_update_rect(SpaceConsole *sc, ARegion *ar)
53 View2D *v2d= &ar->v2d;
55 UI_view2d_totRect_set(v2d, ar->winx-1, console_textview_height(sc, ar));
58 static void console_select_offset(SpaceConsole *sc, const int offset)
60 sc->sel_start += offset;
61 sc->sel_end += offset;
64 void console_history_free(SpaceConsole *sc, ConsoleLine *cl)
66 BLI_remlink(&sc->history, cl);
70 void console_scrollback_free(SpaceConsole *sc, ConsoleLine *cl)
72 BLI_remlink(&sc->scrollback, cl);
77 void console_scrollback_limit(SpaceConsole *sc)
81 if (U.scrollback < 32) U.scrollback= 128; // XXX - save in user defaults
83 for(tot= BLI_countlist(&sc->scrollback); tot > U.scrollback; tot--)
84 console_scrollback_free(sc, sc->scrollback.first);
87 static ConsoleLine * console_history_find(SpaceConsole *sc, const char *str, ConsoleLine *cl_ignore)
91 for(cl= sc->history.last; cl; cl= cl->prev) {
95 if(strcmp(str, cl->line)==0)
102 /* return 0 if no change made, clamps the range */
103 static int console_line_cursor_set(ConsoleLine *cl, int cursor)
107 if(cursor < 0) cursor_new= 0;
108 else if(cursor > cl->len) cursor_new= cl->len;
109 else cursor_new= cursor;
111 if(cursor_new == cl->cursor)
114 cl->cursor= cursor_new;
118 static char cursor_char(ConsoleLine *cl)
120 /* assume cursor is clamped */
121 return cl->line[cl->cursor];
124 static char cursor_char_prev(ConsoleLine *cl)
126 /* assume cursor is clamped */
130 return cl->line[cl->cursor-1];
134 static char cursor_char_next(ConsoleLine *cl)
136 /* assume cursor is clamped */
137 if(cl->cursor + 1 >= cl->len)
140 return cl->line[cl->cursor+1];
143 static void console_lb_debug__internal(ListBase *lb)
147 printf("%d: ", BLI_countlist(lb));
148 for(cl= lb->first; cl; cl= cl->next)
149 printf("<%s> ", cl->line);
154 static void console_history_debug(const bContext *C)
156 SpaceConsole *sc= CTX_wm_space_console(C);
159 console_lb_debug__internal(&sc->history);
163 static ConsoleLine *console_lb_add__internal(ListBase *lb, ConsoleLine *from)
165 ConsoleLine *ci= MEM_callocN(sizeof(ConsoleLine), "ConsoleLine Add");
168 ci->line= BLI_strdup(from->line);
169 ci->len= strlen(ci->line);
170 ci->len_alloc= ci->len;
172 ci->cursor= from->cursor;
173 ci->type= from->type;
175 ci->line= MEM_callocN(64, "console-in-line");
184 static ConsoleLine *console_history_add(const bContext *C, ConsoleLine *from)
186 SpaceConsole *sc= CTX_wm_space_console(C);
188 return console_lb_add__internal(&sc->history, from);
191 #if 0 /* may use later ? */
192 static ConsoleLine *console_scrollback_add(const bContext *C, ConsoleLine *from)
194 SpaceConsole *sc= CTX_wm_space_console(C);
196 return console_lb_add__internal(&sc->scrollback, from);
200 static ConsoleLine *console_lb_add_str__internal(ListBase *lb, char *str, int own)
202 ConsoleLine *ci= MEM_callocN(sizeof(ConsoleLine), "ConsoleLine Add");
203 if(own) ci->line= str;
204 else ci->line= BLI_strdup(str);
206 ci->len = ci->len_alloc = strlen(str);
211 ConsoleLine *console_history_add_str(SpaceConsole *sc, char *str, int own)
213 return console_lb_add_str__internal(&sc->history, str, own);
215 ConsoleLine *console_scrollback_add_str(SpaceConsole *sc, char *str, int own)
217 ConsoleLine *ci= console_lb_add_str__internal(&sc->scrollback, str, own);
218 console_select_offset(sc, ci->len + 1);
222 ConsoleLine *console_history_verify(const bContext *C)
224 SpaceConsole *sc= CTX_wm_space_console(C);
225 ConsoleLine *ci= sc->history.last;
227 ci= console_history_add(C, NULL);
233 static void console_line_verify_length(ConsoleLine *ci, int len)
235 /* resize the buffer if needed */
236 if(len >= ci->len_alloc) {
237 int new_len= len * 2; /* new length */
238 char *new_line= MEM_callocN(new_len, "console line");
239 memcpy(new_line, ci->line, ci->len);
243 ci->len_alloc= new_len;
247 static int console_line_insert(ConsoleLine *ci, char *str)
249 int len = strlen(str);
251 if(len>0 && str[len-1]=='\n') {/* stop new lines being pasted at the end of lines */
259 console_line_verify_length(ci, len + ci->len);
261 memmove(ci->line+ci->cursor+len, ci->line+ci->cursor, (ci->len - ci->cursor)+1);
262 memcpy(ci->line+ci->cursor, str, len);
270 /* static funcs for text editing */
272 /* similar to the text editor, with some not used. keep compatible */
273 static EnumPropertyItem move_type_items[]= {
274 {LINE_BEGIN, "LINE_BEGIN", 0, "Line Begin", ""},
275 {LINE_END, "LINE_END", 0, "Line End", ""},
276 {PREV_CHAR, "PREVIOUS_CHARACTER", 0, "Previous Character", ""},
277 {NEXT_CHAR, "NEXT_CHARACTER", 0, "Next Character", ""},
278 {PREV_WORD, "PREVIOUS_WORD", 0, "Previous Word", ""},
279 {NEXT_WORD, "NEXT_WORD", 0, "Next Word", ""},
280 {0, NULL, 0, NULL, NULL}};
282 static int move_exec(bContext *C, wmOperator *op)
284 ConsoleLine *ci= console_history_verify(C);
286 int type= RNA_enum_get(op->ptr, "type");
291 done= console_line_cursor_set(ci, 0);
294 done= console_line_cursor_set(ci, INT_MAX);
297 done= console_line_cursor_set(ci, ci->cursor-1);
300 done= console_line_cursor_set(ci, ci->cursor+1);
303 /* - if the character is a delimiter then skip delimiters (including white space)
304 * - when jump over the word */
306 while(text_check_delim(cursor_char_prev(ci)))
307 if(console_line_cursor_set(ci, ci->cursor-1)==FALSE)
310 while(text_check_delim(cursor_char_prev(ci))==FALSE)
311 if(console_line_cursor_set(ci, ci->cursor-1)==FALSE)
314 /* This isnt used for NEXT_WORD because when going back
315 * its more useful to have the cursor directly after a word then whitespace */
316 while(text_check_whitespace(cursor_char_prev(ci))==TRUE)
317 if(console_line_cursor_set(ci, ci->cursor-1)==FALSE)
320 done= 1; /* assume changed */
323 while(text_check_delim(cursor_char(ci))==TRUE)
324 if (console_line_cursor_set(ci, ci->cursor+1)==FALSE)
327 while(text_check_delim(cursor_char(ci))==FALSE)
328 if (console_line_cursor_set(ci, ci->cursor+1)==FALSE)
331 done= 1; /* assume changed */
336 ED_area_tag_redraw(CTX_wm_area(C));
339 return OPERATOR_FINISHED;
342 void CONSOLE_OT_move(wmOperatorType *ot)
345 ot->name= "Move Cursor";
346 ot->description= "Move cursor position";
347 ot->idname= "CONSOLE_OT_move";
351 ot->poll= ED_operator_console_active;
354 RNA_def_enum(ot->srna, "type", move_type_items, LINE_BEGIN, "Type", "Where to move cursor to.");
358 static int insert_exec(bContext *C, wmOperator *op)
360 SpaceConsole *sc= CTX_wm_space_console(C);
361 ARegion *ar= CTX_wm_region(C);
362 ConsoleLine *ci= console_history_verify(C);
363 char *str= RNA_string_get_alloc(op->ptr, "text", NULL, 0);
366 // XXX, alligned tab key hack
367 if(str[0]=='\t' && str[1]=='\0') {
368 int len= TAB_LENGTH - (ci->cursor % TAB_LENGTH);
370 str= MEM_mallocN(len + 1, "insert_exec");
371 memset(str, ' ', len);
375 len= console_line_insert(ci, str);
380 return OPERATOR_CANCELLED;
383 SpaceConsole *sc= CTX_wm_space_console(C);
384 console_select_offset(sc, len);
387 console_textview_update_rect(sc, ar);
388 ED_area_tag_redraw(CTX_wm_area(C));
390 return OPERATOR_FINISHED;
393 static int insert_invoke(bContext *C, wmOperator *op, wmEvent *event)
395 // if(!RNA_property_is_set(op->ptr, "text")) { /* always set from keymap XXX */
396 if(!RNA_string_length(op->ptr, "text")) {
397 /* if alt/ctrl/super are pressed pass through */
398 if(event->ctrl || event->oskey) {
399 return OPERATOR_PASS_THROUGH;
403 str[0]= event->ascii;
406 RNA_string_set(op->ptr, "text", str);
409 return insert_exec(C, op);
412 void CONSOLE_OT_insert(wmOperatorType *ot)
416 ot->description= "Insert text at cursor position";
417 ot->idname= "CONSOLE_OT_insert";
420 ot->exec= insert_exec;
421 ot->invoke= insert_invoke;
422 ot->poll= ED_operator_console_active;
425 RNA_def_string(ot->srna, "text", "", 0, "Text", "Text to insert at the cursor position.");
429 static EnumPropertyItem delete_type_items[]= {
430 {DEL_NEXT_CHAR, "NEXT_CHARACTER", 0, "Next Character", ""},
431 {DEL_PREV_CHAR, "PREVIOUS_CHARACTER", 0, "Previous Character", ""},
432 // {DEL_NEXT_WORD, "NEXT_WORD", 0, "Next Word", ""},
433 // {DEL_PREV_WORD, "PREVIOUS_WORD", 0, "Previous Word", ""},
434 {0, NULL, 0, NULL, NULL}};
436 static int delete_exec(bContext *C, wmOperator *op)
438 SpaceConsole *sc= CTX_wm_space_console(C);
439 ARegion *ar= CTX_wm_region(C);
440 ConsoleLine *ci= console_history_verify(C);
442 const short type= RNA_enum_get(op->ptr, "type");
446 return OPERATOR_CANCELLED;
451 if(ci->cursor < ci->len) {
452 memmove(ci->line + ci->cursor, ci->line + ci->cursor+1, (ci->len - ci->cursor)+1);
459 ci->cursor--; /* same as above */
460 memmove(ci->line + ci->cursor, ci->line + ci->cursor+1, (ci->len - ci->cursor)+1);
468 return OPERATOR_CANCELLED;
471 SpaceConsole *sc= CTX_wm_space_console(C);
472 console_select_offset(sc, -1);
475 console_textview_update_rect(sc, ar);
476 ED_area_tag_redraw(CTX_wm_area(C));
478 return OPERATOR_FINISHED;
482 void CONSOLE_OT_delete(wmOperatorType *ot)
486 ot->description= "Delete text by cursor position";
487 ot->idname= "CONSOLE_OT_delete";
490 ot->exec= delete_exec;
491 ot->poll= ED_operator_console_active;
494 RNA_def_enum(ot->srna, "type", delete_type_items, DEL_NEXT_CHAR, "Type", "Which part of the text to delete.");
498 /* the python exec operator uses this */
499 static int clear_exec(bContext *C, wmOperator *op)
501 SpaceConsole *sc= CTX_wm_space_console(C);
502 ARegion *ar= CTX_wm_region(C);
504 short scrollback= RNA_boolean_get(op->ptr, "scrollback");
505 short history= RNA_boolean_get(op->ptr, "history");
507 /*ConsoleLine *ci= */ console_history_verify(C);
509 if(scrollback) { /* last item in mistory */
510 while(sc->scrollback.first)
511 console_scrollback_free(sc, sc->scrollback.first);
515 while(sc->history.first)
516 console_history_free(sc, sc->history.first);
519 console_textview_update_rect(sc, ar);
520 ED_area_tag_redraw(CTX_wm_area(C));
522 return OPERATOR_FINISHED;
525 void CONSOLE_OT_clear(wmOperatorType *ot)
529 ot->description= "Clear text by type";
530 ot->idname= "CONSOLE_OT_clear";
533 ot->exec= clear_exec;
534 ot->poll= ED_operator_console_active;
537 RNA_def_boolean(ot->srna, "scrollback", 1, "Scrollback", "Clear the scrollback history");
538 RNA_def_boolean(ot->srna, "history", 0, "History", "Clear the command history");
543 /* the python exec operator uses this */
544 static int history_cycle_exec(bContext *C, wmOperator *op)
546 SpaceConsole *sc= CTX_wm_space_console(C);
547 ARegion *ar= CTX_wm_region(C);
549 ConsoleLine *ci= console_history_verify(C); /* TODO - stupid, just prevernts crashes when no command line */
550 short reverse= RNA_boolean_get(op->ptr, "reverse"); /* assumes down, reverse is up */
551 int prev_len= ci->len;
553 /* keep a copy of the line above so when history is cycled
554 * this is the only function that needs to know about the double-up */
556 ConsoleLine *ci_prev= (ConsoleLine *)ci->prev;
558 if(strcmp(ci->line, ci_prev->line)==0)
559 console_history_free(sc, ci_prev);
562 if(reverse) { /* last item in mistory */
563 ci= sc->history.last;
564 BLI_remlink(&sc->history, ci);
565 BLI_addhead(&sc->history, ci);
568 ci= sc->history.first;
569 BLI_remlink(&sc->history, ci);
570 BLI_addtail(&sc->history, ci);
573 { /* add a duplicate of the new arg and remove all other instances */
575 while((cl= console_history_find(sc, ci->line, ci)))
576 console_history_free(sc, cl);
578 console_history_add(C, (ConsoleLine *)sc->history.last);
581 ci= sc->history.last;
582 console_select_offset(sc, ci->len - prev_len);
584 /* could be wrapped so update scroll rect */
585 console_textview_update_rect(sc, ar);
586 ED_area_tag_redraw(CTX_wm_area(C));
588 return OPERATOR_FINISHED;
591 void CONSOLE_OT_history_cycle(wmOperatorType *ot)
594 ot->name= "History Cycle";
595 ot->description= "Cycle through history";
596 ot->idname= "CONSOLE_OT_history_cycle";
599 ot->exec= history_cycle_exec;
600 ot->poll= ED_operator_console_active;
603 RNA_def_boolean(ot->srna, "reverse", 0, "Reverse", "reverse cycle history");
607 /* the python exec operator uses this */
608 static int history_append_exec(bContext *C, wmOperator *op)
610 SpaceConsole *sc= CTX_wm_space_console(C);
611 ScrArea *sa= CTX_wm_area(C);
612 ConsoleLine *ci= console_history_verify(C);
613 char *str= RNA_string_get_alloc(op->ptr, "text", NULL, 0); /* own this text in the new line, dont free */
614 int cursor= RNA_int_get(op->ptr, "current_character");
615 short rem_dupes= RNA_boolean_get(op->ptr, "remove_duplicates");
616 int prev_len= ci->len;
619 SpaceConsole *sc= CTX_wm_space_console(C);
622 while((cl= console_history_find(sc, ci->line, ci)))
623 console_history_free(sc, cl);
625 if(strcmp(str, ci->line)==0) {
627 return OPERATOR_FINISHED;
631 ci= console_history_add_str(sc, str, 1); /* own the string */
632 console_select_offset(sc, ci->len - prev_len);
633 console_line_cursor_set(ci, cursor);
635 ED_area_tag_redraw(sa);
637 return OPERATOR_FINISHED;
640 void CONSOLE_OT_history_append(wmOperatorType *ot)
643 ot->name= "History Append";
644 ot->description= "Append history at cursor position";
645 ot->idname= "CONSOLE_OT_history_append";
648 ot->exec= history_append_exec;
649 ot->poll= ED_operator_console_active;
652 RNA_def_string(ot->srna, "text", "", 0, "Text", "Text to insert at the cursor position.");
653 RNA_def_int(ot->srna, "current_character", 0, 0, INT_MAX, "Cursor", "The index of the cursor.", 0, 10000);
654 RNA_def_boolean(ot->srna, "remove_duplicates", 0, "Remove Duplicates", "Remove duplicate items in the history");
658 /* the python exec operator uses this */
659 static int scrollback_append_exec(bContext *C, wmOperator *op)
661 SpaceConsole *sc= CTX_wm_space_console(C);
662 ARegion *ar= CTX_wm_region(C);
664 ConsoleLine *ci= console_history_verify(C);
666 char *str= RNA_string_get_alloc(op->ptr, "text", NULL, 0); /* own this text in the new line, dont free */
667 int type= RNA_enum_get(op->ptr, "type");
669 ci= console_scrollback_add_str(sc, str, 1); /* own the string */
672 console_scrollback_limit(sc);
674 console_textview_update_rect(sc, ar);
675 ED_area_tag_redraw(CTX_wm_area(C));
677 return OPERATOR_FINISHED;
680 void CONSOLE_OT_scrollback_append(wmOperatorType *ot)
682 /* defined in DNA_space_types.h */
683 static EnumPropertyItem console_line_type_items[] = {
684 {CONSOLE_LINE_OUTPUT, "OUTPUT", 0, "Output", ""},
685 {CONSOLE_LINE_INPUT, "INPUT", 0, "Input", ""},
686 {CONSOLE_LINE_INFO, "INFO", 0, "Information", ""},
687 {CONSOLE_LINE_ERROR, "ERROR", 0, "Error", ""},
688 {0, NULL, 0, NULL, NULL}};
691 ot->name= "Scrollback Append";
692 ot->description= "Append scrollback text by type";
693 ot->idname= "CONSOLE_OT_scrollback_append";
696 ot->exec= scrollback_append_exec;
697 ot->poll= ED_operator_console_active;
700 RNA_def_string(ot->srna, "text", "", 0, "Text", "Text to insert at the cursor position.");
701 RNA_def_enum(ot->srna, "type", console_line_type_items, CONSOLE_LINE_OUTPUT, "Type", "Console output type.");
705 static int copy_exec(bContext *C, wmOperator *UNUSED(op))
707 SpaceConsole *sc= CTX_wm_space_console(C);
710 DynStr *buf_dyn= BLI_dynstr_new();
717 ConsoleLine cl_dummy= {0};
720 /* copy whole file */
721 for(cl= sc->scrollback.first; cl; cl= cl->next) {
722 BLI_dynstr_append(buf_dyn, cl->line);
723 BLI_dynstr_append(buf_dyn, "\n");
727 if(sc->sel_start == sc->sel_end)
728 return OPERATOR_CANCELLED;
730 console_scrollback_prompt_begin(sc, &cl_dummy);
732 for(cl= sc->scrollback.first; cl; cl= cl->next) {
733 offset += cl->len + 1;
737 console_scrollback_prompt_end(sc, &cl_dummy);
738 return OPERATOR_CANCELLED;
742 sel[0]= offset - sc->sel_end;
743 sel[1]= offset - sc->sel_start;
745 for(cl= sc->scrollback.first; cl; cl= cl->next) {
746 if(sel[0] <= cl->len && sel[1] >= 0) {
747 int sta= MAX2(sel[0], 0);
748 int end= MIN2(sel[1], cl->len);
750 if(BLI_dynstr_get_len(buf_dyn))
751 BLI_dynstr_append(buf_dyn, "\n");
753 BLI_dynstr_nappend(buf_dyn, cl->line + sta, end - sta);
756 sel[0] -= cl->len + 1;
757 sel[1] -= cl->len + 1;
760 buf_str= BLI_dynstr_get_cstring(buf_dyn);
761 buf_len= BLI_dynstr_get_len(buf_dyn);
762 BLI_dynstr_free(buf_dyn);
763 WM_clipboard_text_set(buf_str, 0);
767 console_scrollback_prompt_end(sc, &cl_dummy);
769 return OPERATOR_FINISHED;
772 void CONSOLE_OT_copy(wmOperatorType *ot)
775 ot->name= "Copy to Clipboard";
776 ot->description= "Copy selected text to clipboard";
777 ot->idname= "CONSOLE_OT_copy";
780 ot->poll= ED_operator_console_active;
786 static int paste_exec(bContext *C, wmOperator *UNUSED(op))
788 SpaceConsole *sc= CTX_wm_space_console(C);
789 ARegion *ar= CTX_wm_region(C);
790 ConsoleLine *ci= console_history_verify(C);
792 char *buf_str= WM_clipboard_text_get(0);
793 char *buf_step, *buf_next;
796 return OPERATOR_CANCELLED;
801 while((buf_next=buf_step) && buf_next[0] != '\0') {
802 buf_step= strchr(buf_next, '\n');
808 if(buf_next != buf_str) {
809 WM_operator_name_call(C, "CONSOLE_OT_execute", WM_OP_EXEC_DEFAULT, NULL);
810 ci= console_history_verify(C);
813 console_select_offset(sc, console_line_insert(ci, buf_next));
818 console_textview_update_rect(sc, ar);
819 ED_area_tag_redraw(CTX_wm_area(C));
821 return OPERATOR_FINISHED;
824 void CONSOLE_OT_paste(wmOperatorType *ot)
827 ot->name= "Paste from Clipboard";
828 ot->description= "Paste text from clipboard";
829 ot->idname= "CONSOLE_OT_paste";
832 ot->poll= ED_operator_console_active;
833 ot->exec= paste_exec;
838 typedef struct SetConsoleCursor {
843 // TODO, cursor placement without selection
844 static void set_cursor_to_pos(SpaceConsole *sc, ARegion *ar, SetConsoleCursor *scu, int mval[2], int UNUSED(sel))
847 pos= console_char_pick(sc, ar, mval);
849 if(scu->sel_init == INT_MAX) {
851 sc->sel_start = sc->sel_end = pos;
855 if (pos < scu->sel_init) {
857 sc->sel_end = scu->sel_init;
859 else if (pos > sc->sel_start) {
860 sc->sel_start = scu->sel_init;
864 sc->sel_start = sc->sel_end = pos;
868 static void console_modal_select_apply(bContext *C, wmOperator *op, wmEvent *event)
870 SpaceConsole *sc= CTX_wm_space_console(C);
871 ARegion *ar= CTX_wm_region(C);
872 SetConsoleCursor *scu= op->customdata;
876 mval[0]= event->mval[0];
877 mval[1]= event->mval[1];
879 sel_prev[0]= sc->sel_start;
880 sel_prev[1]= sc->sel_end;
882 set_cursor_to_pos(sc, ar, scu, mval, TRUE);
884 /* only redraw if the selection changed */
885 if(sel_prev[0] != sc->sel_start || sel_prev[1] != sc->sel_end) {
886 ED_area_tag_redraw(CTX_wm_area(C));
890 static void set_cursor_exit(bContext *UNUSED(C), wmOperator *op)
892 // SpaceConsole *sc= CTX_wm_space_console(C);
893 SetConsoleCursor *scu= op->customdata;
896 if(txt_has_sel(text)) {
897 buffer = txt_sel_to_buf(text);
898 WM_clipboard_text_set(buffer, 1);
905 static int console_modal_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
907 SpaceConsole *sc= CTX_wm_space_console(C);
908 // ARegion *ar= CTX_wm_region(C);
909 SetConsoleCursor *scu;
911 op->customdata= MEM_callocN(sizeof(SetConsoleCursor), "SetConsoleCursor");
914 scu->sel_old[0]= sc->sel_start;
915 scu->sel_old[1]= sc->sel_end;
917 scu->sel_init = INT_MAX;
919 WM_event_add_modal_handler(C, op);
921 console_modal_select_apply(C, op, event);
923 return OPERATOR_RUNNING_MODAL;
926 static int console_modal_select(bContext *C, wmOperator *op, wmEvent *event)
928 switch(event->type) {
932 set_cursor_exit(C, op);
933 return OPERATOR_FINISHED;
935 console_modal_select_apply(C, op, event);
939 return OPERATOR_RUNNING_MODAL;
942 static int console_modal_select_cancel(bContext *C, wmOperator *op)
944 set_cursor_exit(C, op);
945 return OPERATOR_FINISHED;
948 void CONSOLE_OT_select_set(wmOperatorType *ot)
951 ot->name= "Set Selection";
952 ot->idname= "CONSOLE_OT_select_set";
953 ot->description= "Set the console selection";
956 ot->invoke= console_modal_select_invoke;
957 ot->modal= console_modal_select;
958 ot->cancel= console_modal_select_cancel;
959 ot->poll= ED_operator_console_active;