Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_text/text_ops.c
| Show First 20 Lines • Show All 834 Lines • ▼ Show 20 Lines | static int text_paste_exec(bContext *C, wmOperator *op) | ||||
| buf = WM_clipboard_text_get(selection, &buf_len); | buf = WM_clipboard_text_get(selection, &buf_len); | ||||
| if (!buf) { | if (!buf) { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| text_drawcache_tag_update(CTX_wm_space_text(C), 0); | text_drawcache_tag_update(CTX_wm_space_text(C), 0); | ||||
| TextUndoBuf *utxt = ED_text_undo_push_init(C); | ED_text_undo_push_init(C); | ||||
| /* Convert clipboard content indentation to spaces if specified */ | /* Convert clipboard content indentation to spaces if specified */ | ||||
| if (text->flags & TXT_TABSTOSPACES) { | if (text->flags & TXT_TABSTOSPACES) { | ||||
| char *new_buf = buf_tabs_to_spaces(buf, TXT_TABSIZE); | char *new_buf = buf_tabs_to_spaces(buf, TXT_TABSIZE); | ||||
| MEM_freeN(buf); | MEM_freeN(buf); | ||||
| buf = new_buf; | buf = new_buf; | ||||
| } | } | ||||
| txt_insert_buf(text, utxt, buf); | txt_insert_buf(text, buf); | ||||
| text_update_edited(text); | text_update_edited(text); | ||||
| MEM_freeN(buf); | MEM_freeN(buf); | ||||
| text_update_cursor_moved(C); | text_update_cursor_moved(C); | ||||
| WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); | WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); | ||||
| /* run the script while editing, evil but useful */ | /* run the script while editing, evil but useful */ | ||||
| Show All 27 Lines | |||||
| } | } | ||||
| /**************** duplicate operator *******************/ | /**************** duplicate operator *******************/ | ||||
| static int text_duplicate_line_exec(bContext *C, wmOperator *UNUSED(op)) | static int text_duplicate_line_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| { | { | ||||
| Text *text = CTX_data_edit_text(C); | Text *text = CTX_data_edit_text(C); | ||||
| TextUndoBuf *utxt = ED_text_undo_push_init(C); | ED_text_undo_push_init(C); | ||||
| txt_duplicate_line(text, utxt); | txt_duplicate_line(text); | ||||
| WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); | WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); | ||||
| /* run the script while editing, evil but useful */ | /* run the script while editing, evil but useful */ | ||||
| if (CTX_wm_space_text(C)->live_edit) { | if (CTX_wm_space_text(C)->live_edit) { | ||||
| text_run_script(C, NULL); | text_run_script(C, NULL); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | |||||
| static int text_cut_exec(bContext *C, wmOperator *UNUSED(op)) | static int text_cut_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| { | { | ||||
| Text *text = CTX_data_edit_text(C); | Text *text = CTX_data_edit_text(C); | ||||
| text_drawcache_tag_update(CTX_wm_space_text(C), 0); | text_drawcache_tag_update(CTX_wm_space_text(C), 0); | ||||
| txt_copy_clipboard(text); | txt_copy_clipboard(text); | ||||
| TextUndoBuf *utxt = ED_text_undo_push_init(C); | ED_text_undo_push_init(C); | ||||
| txt_delete_selected(text, utxt); | txt_delete_selected(text); | ||||
| text_update_cursor_moved(C); | text_update_cursor_moved(C); | ||||
| WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); | WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); | ||||
| /* run the script while editing, evil but useful */ | /* run the script while editing, evil but useful */ | ||||
| if (CTX_wm_space_text(C)->live_edit) { | if (CTX_wm_space_text(C)->live_edit) { | ||||
| text_run_script(C, NULL); | text_run_script(C, NULL); | ||||
| } | } | ||||
| Show All 19 Lines | |||||
| /******************* indent operator *********************/ | /******************* indent operator *********************/ | ||||
| static int text_indent_exec(bContext *C, wmOperator *UNUSED(op)) | static int text_indent_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| { | { | ||||
| Text *text = CTX_data_edit_text(C); | Text *text = CTX_data_edit_text(C); | ||||
| text_drawcache_tag_update(CTX_wm_space_text(C), 0); | text_drawcache_tag_update(CTX_wm_space_text(C), 0); | ||||
| TextUndoBuf *utxt = ED_text_undo_push_init(C); | ED_text_undo_push_init(C); | ||||
| if (txt_has_sel(text)) { | if (txt_has_sel(text)) { | ||||
| txt_order_cursors(text, false); | txt_order_cursors(text, false); | ||||
| txt_indent(text, utxt); | txt_indent(text); | ||||
| } | } | ||||
| else { | else { | ||||
| txt_add_char(text, utxt, '\t'); | txt_add_char(text, '\t'); | ||||
| } | } | ||||
| text_update_edited(text); | text_update_edited(text); | ||||
| text_update_cursor_moved(C); | text_update_cursor_moved(C); | ||||
| WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); | WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| Show All 17 Lines | |||||
| /******************* unindent operator *********************/ | /******************* unindent operator *********************/ | ||||
| static int text_unindent_exec(bContext *C, wmOperator *UNUSED(op)) | static int text_unindent_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| { | { | ||||
| Text *text = CTX_data_edit_text(C); | Text *text = CTX_data_edit_text(C); | ||||
| text_drawcache_tag_update(CTX_wm_space_text(C), 0); | text_drawcache_tag_update(CTX_wm_space_text(C), 0); | ||||
| TextUndoBuf *utxt = ED_text_undo_push_init(C); | ED_text_undo_push_init(C); | ||||
| txt_order_cursors(text, false); | txt_order_cursors(text, false); | ||||
| txt_unindent(text, utxt); | txt_unindent(text); | ||||
| text_update_edited(text); | text_update_edited(text); | ||||
| text_update_cursor_moved(C); | text_update_cursor_moved(C); | ||||
| WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); | WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| Show All 21 Lines | static int text_line_break_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| Text *text = CTX_data_edit_text(C); | Text *text = CTX_data_edit_text(C); | ||||
| int a, curts; | int a, curts; | ||||
| int space = (text->flags & TXT_TABSTOSPACES) ? st->tabnumber : 1; | int space = (text->flags & TXT_TABSTOSPACES) ? st->tabnumber : 1; | ||||
| text_drawcache_tag_update(st, 0); | text_drawcache_tag_update(st, 0); | ||||
| // double check tabs/spaces before splitting the line | // double check tabs/spaces before splitting the line | ||||
| curts = txt_setcurr_tab_spaces(text, space); | curts = txt_setcurr_tab_spaces(text, space); | ||||
| TextUndoBuf *utxt = ED_text_undo_push_init(C); | ED_text_undo_push_init(C); | ||||
| txt_split_curline(text, utxt); | txt_split_curline(text); | ||||
| for (a = 0; a < curts; a++) { | for (a = 0; a < curts; a++) { | ||||
| if (text->flags & TXT_TABSTOSPACES) { | if (text->flags & TXT_TABSTOSPACES) { | ||||
| txt_add_char(text, utxt, ' '); | txt_add_char(text, ' '); | ||||
| } | } | ||||
| else { | else { | ||||
| txt_add_char(text, utxt, '\t'); | txt_add_char(text, '\t'); | ||||
| } | } | ||||
| } | } | ||||
| if (text->curl) { | if (text->curl) { | ||||
| if (text->curl->prev) { | if (text->curl->prev) { | ||||
| text_update_line_edited(text->curl->prev); | text_update_line_edited(text->curl->prev); | ||||
| } | } | ||||
| text_update_line_edited(text->curl); | text_update_line_edited(text->curl); | ||||
| Show All 24 Lines | |||||
| static int text_comment_exec(bContext *C, wmOperator *UNUSED(op)) | static int text_comment_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| { | { | ||||
| Text *text = CTX_data_edit_text(C); | Text *text = CTX_data_edit_text(C); | ||||
| if (txt_has_sel(text)) { | if (txt_has_sel(text)) { | ||||
| text_drawcache_tag_update(CTX_wm_space_text(C), 0); | text_drawcache_tag_update(CTX_wm_space_text(C), 0); | ||||
| TextUndoBuf *utxt = ED_text_undo_push_init(C); | ED_text_undo_push_init(C); | ||||
| txt_order_cursors(text, false); | txt_order_cursors(text, false); | ||||
| txt_comment(text, utxt); | txt_comment(text); | ||||
| text_update_edited(text); | text_update_edited(text); | ||||
| text_update_cursor_moved(C); | text_update_cursor_moved(C); | ||||
| WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); | WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| Show All 18 Lines | |||||
| static int text_uncomment_exec(bContext *C, wmOperator *UNUSED(op)) | static int text_uncomment_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| { | { | ||||
| Text *text = CTX_data_edit_text(C); | Text *text = CTX_data_edit_text(C); | ||||
| if (txt_has_sel(text)) { | if (txt_has_sel(text)) { | ||||
| text_drawcache_tag_update(CTX_wm_space_text(C), 0); | text_drawcache_tag_update(CTX_wm_space_text(C), 0); | ||||
| TextUndoBuf *utxt = ED_text_undo_push_init(C); | ED_text_undo_push_init(C); | ||||
| txt_order_cursors(text, false); | txt_order_cursors(text, false); | ||||
| txt_uncomment(text, utxt); | txt_uncomment(text); | ||||
| text_update_edited(text); | text_update_edited(text); | ||||
| text_update_cursor_moved(C); | text_update_cursor_moved(C); | ||||
| WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); | WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 249 Lines • ▼ Show 20 Lines | |||||
| /********************* move lines operators ***********************/ | /********************* move lines operators ***********************/ | ||||
| static int move_lines_exec(bContext *C, wmOperator *op) | static int move_lines_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Text *text = CTX_data_edit_text(C); | Text *text = CTX_data_edit_text(C); | ||||
| const int direction = RNA_enum_get(op->ptr, "direction"); | const int direction = RNA_enum_get(op->ptr, "direction"); | ||||
| TextUndoBuf *utxt = ED_text_undo_push_init(C); | ED_text_undo_push_init(C); | ||||
| txt_move_lines(text, utxt, direction); | txt_move_lines(text, direction); | ||||
| text_update_cursor_moved(C); | text_update_cursor_moved(C); | ||||
| WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); | WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); | ||||
| /* run the script while editing, evil but useful */ | /* run the script while editing, evil but useful */ | ||||
| if (CTX_wm_space_text(C)->live_edit) { | if (CTX_wm_space_text(C)->live_edit) { | ||||
| text_run_script(C, NULL); | text_run_script(C, NULL); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 765 Lines • ▼ Show 20 Lines | if (txt_has_sel(text)) { | ||||
| if (type == DEL_PREV_WORD) { | if (type == DEL_PREV_WORD) { | ||||
| type = DEL_PREV_CHAR; | type = DEL_PREV_CHAR; | ||||
| } | } | ||||
| else if (type == DEL_NEXT_WORD) { | else if (type == DEL_NEXT_WORD) { | ||||
| type = DEL_NEXT_CHAR; | type = DEL_NEXT_CHAR; | ||||
| } | } | ||||
| } | } | ||||
| TextUndoBuf *utxt = ED_text_undo_push_init(C); | ED_text_undo_push_init(C); | ||||
| if (type == DEL_PREV_WORD) { | if (type == DEL_PREV_WORD) { | ||||
| if (txt_cursor_is_line_start(text)) { | if (txt_cursor_is_line_start(text)) { | ||||
| txt_backspace_char(text, utxt); | txt_backspace_char(text); | ||||
| } | } | ||||
| txt_backspace_word(text, utxt); | txt_backspace_word(text); | ||||
| } | } | ||||
| else if (type == DEL_PREV_CHAR) { | else if (type == DEL_PREV_CHAR) { | ||||
| if (text->flags & TXT_TABSTOSPACES) { | if (text->flags & TXT_TABSTOSPACES) { | ||||
| if (!txt_has_sel(text) && !txt_cursor_is_line_start(text)) { | if (!txt_has_sel(text) && !txt_cursor_is_line_start(text)) { | ||||
| int tabsize = 0; | int tabsize = 0; | ||||
| tabsize = txt_calc_tab_left(text->curl, text->curc); | tabsize = txt_calc_tab_left(text->curl, text->curc); | ||||
| if (tabsize) { | if (tabsize) { | ||||
| text->sell = text->curl; | text->sell = text->curl; | ||||
| text->selc = text->curc - tabsize; | text->selc = text->curc - tabsize; | ||||
| txt_order_cursors(text, false); | txt_order_cursors(text, false); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| txt_backspace_char(text, utxt); | txt_backspace_char(text); | ||||
| } | } | ||||
| else if (type == DEL_NEXT_WORD) { | else if (type == DEL_NEXT_WORD) { | ||||
| if (txt_cursor_is_line_end(text)) { | if (txt_cursor_is_line_end(text)) { | ||||
| txt_delete_char(text, utxt); | txt_delete_char(text); | ||||
| } | } | ||||
| txt_delete_word(text, utxt); | txt_delete_word(text); | ||||
| } | } | ||||
| else if (type == DEL_NEXT_CHAR) { | else if (type == DEL_NEXT_CHAR) { | ||||
| if (text->flags & TXT_TABSTOSPACES) { | if (text->flags & TXT_TABSTOSPACES) { | ||||
| if (!txt_has_sel(text) && !txt_cursor_is_line_end(text)) { | if (!txt_has_sel(text) && !txt_cursor_is_line_end(text)) { | ||||
| int tabsize = 0; | int tabsize = 0; | ||||
| tabsize = txt_calc_tab_right(text->curl, text->curc); | tabsize = txt_calc_tab_right(text->curl, text->curc); | ||||
| if (tabsize) { | if (tabsize) { | ||||
| text->sell = text->curl; | text->sell = text->curl; | ||||
| text->selc = text->curc + tabsize; | text->selc = text->curc + tabsize; | ||||
| txt_order_cursors(text, true); | txt_order_cursors(text, true); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| txt_delete_char(text, utxt); | txt_delete_char(text); | ||||
| } | } | ||||
| text_update_line_edited(text->curl); | text_update_line_edited(text->curl); | ||||
| text_update_cursor_moved(C); | text_update_cursor_moved(C); | ||||
| WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); | WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); | ||||
| /* run the script while editing, evil but useful */ | /* run the script while editing, evil but useful */ | ||||
| ▲ Show 20 Lines • Show All 899 Lines • ▼ Show 20 Lines | static int text_insert_exec(bContext *C, wmOperator *op) | ||||
| bool done = false; | bool done = false; | ||||
| size_t i = 0; | size_t i = 0; | ||||
| unsigned int code; | unsigned int code; | ||||
| text_drawcache_tag_update(st, 0); | text_drawcache_tag_update(st, 0); | ||||
| str = RNA_string_get_alloc(op->ptr, "text", NULL, 0); | str = RNA_string_get_alloc(op->ptr, "text", NULL, 0); | ||||
| TextUndoBuf *utxt = ED_text_undo_push_init(C); | ED_text_undo_push_init(C); | ||||
| if (st && st->overwrite) { | if (st && st->overwrite) { | ||||
| while (str[i]) { | while (str[i]) { | ||||
| code = BLI_str_utf8_as_unicode_step(str, &i); | code = BLI_str_utf8_as_unicode_step(str, &i); | ||||
| done |= txt_replace_char(text, utxt, code); | done |= txt_replace_char(text, code); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| while (str[i]) { | while (str[i]) { | ||||
| code = BLI_str_utf8_as_unicode_step(str, &i); | code = BLI_str_utf8_as_unicode_step(str, &i); | ||||
| done |= txt_add_char(text, utxt, code); | done |= txt_add_char(text, code); | ||||
| } | } | ||||
| } | } | ||||
| MEM_freeN(str); | MEM_freeN(str); | ||||
| if (!done) { | if (!done) { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | if (flags & ST_MATCH_CASE) { | ||||
| found = STREQ(st->findstr, tmp); | found = STREQ(st->findstr, tmp); | ||||
| } | } | ||||
| else { | else { | ||||
| found = BLI_strcasecmp(st->findstr, tmp) == 0; | found = BLI_strcasecmp(st->findstr, tmp) == 0; | ||||
| } | } | ||||
| if (found) { | if (found) { | ||||
| if (mode == TEXT_REPLACE) { | if (mode == TEXT_REPLACE) { | ||||
| TextUndoBuf *utxt = ED_text_undo_push_init(C); | ED_text_undo_push_init(C); | ||||
| txt_insert_buf(text, utxt, st->replacestr); | txt_insert_buf(text, st->replacestr); | ||||
| if (text->curl && text->curl->format) { | if (text->curl && text->curl->format) { | ||||
| MEM_freeN(text->curl->format); | MEM_freeN(text->curl->format); | ||||
| text->curl->format = NULL; | text->curl->format = NULL; | ||||
| } | } | ||||
| text_update_cursor_moved(C); | text_update_cursor_moved(C); | ||||
| WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); | WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); | ||||
| text_drawcache_tag_update(CTX_wm_space_text(C), 1); | text_drawcache_tag_update(CTX_wm_space_text(C), 1); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 273 Lines • Show Last 20 Lines | |||||