diff options
Diffstat (limited to 'source/blender/editors/space_text/text_ops.c')
-rw-r--r-- | source/blender/editors/space_text/text_ops.c | 176 |
1 files changed, 88 insertions, 88 deletions
diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index 01b404e321a..38f0393858d 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -124,7 +124,7 @@ static int text_region_edit_poll(bContext *C) if (!st || !text) return 0; - + if (!ar || ar->regiontype != RGN_TYPE_WINDOW) return 0; @@ -198,11 +198,11 @@ void TEXT_OT_new(wmOperatorType *ot) ot->name = "Create Text Block"; ot->idname = "TEXT_OT_new"; ot->description = "Create a new text data-block"; - + /* api callbacks */ ot->exec = text_new_exec; ot->poll = text_new_poll; - + /* flags */ ot->flag = OPTYPE_UNDO; } @@ -278,10 +278,10 @@ static int text_open_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(e if (RNA_struct_property_is_set(op->ptr, "filepath")) return text_open_exec(C, op); - + text_open_init(C, op); RNA_string_set(op->ptr, "filepath", path); - WM_event_add_fileselect(C, op); + WM_event_add_fileselect(C, op); return OPERATOR_RUNNING_MODAL; } @@ -301,7 +301,7 @@ void TEXT_OT_open(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_UNDO; - + /* properties */ WM_operator_properties_filesel( ot, FILE_TYPE_FOLDER | FILE_TYPE_TEXT | FILE_TYPE_PYSCRIPT, FILE_SPECIAL, FILE_OPENFILE, @@ -352,7 +352,7 @@ void TEXT_OT_reload(wmOperatorType *ot) ot->name = "Reload"; ot->idname = "TEXT_OT_reload"; ot->description = "Reload active text data-block from its file"; - + /* api callbacks */ ot->exec = text_reload_exec; ot->invoke = WM_operator_confirm; @@ -401,12 +401,12 @@ void TEXT_OT_unlink(wmOperatorType *ot) ot->name = "Unlink"; ot->idname = "TEXT_OT_unlink"; ot->description = "Unlink active text data-block"; - + /* api callbacks */ ot->exec = text_unlink_exec; ot->invoke = WM_operator_confirm; ot->poll = text_unlink_poll; - + /* flags */ ot->flag = OPTYPE_UNDO; } @@ -440,7 +440,7 @@ void TEXT_OT_make_internal(wmOperatorType *ot) /* api callbacks */ ot->exec = text_make_internal_exec; ot->poll = text_edit_poll; - + /* flags */ ot->flag = OPTYPE_UNDO; } @@ -453,7 +453,7 @@ static int text_save_poll(bContext *C) if (!text_edit_poll(C)) return 0; - + return (text->name != NULL && !(text->flags & TXT_ISMEM)); } @@ -463,10 +463,10 @@ static void txt_write_file(Main *bmain, Text *text, ReportList *reports) TextLine *tmp; BLI_stat_t st; char filepath[FILE_MAX]; - + BLI_strncpy(filepath, text->name, FILE_MAX); BLI_path_abs(filepath, bmain->name); - + fp = BLI_fopen(filepath, "w"); if (fp == NULL) { BKE_reportf(reports, RPT_ERROR, "Unable to save '%s': %s", @@ -480,7 +480,7 @@ static void txt_write_file(Main *bmain, Text *text, ReportList *reports) fputc('\n', fp); } } - + fclose(fp); if (BLI_stat(filepath, &st) == 0) { @@ -494,7 +494,7 @@ static void txt_write_file(Main *bmain, Text *text, ReportList *reports) BKE_reportf(reports, RPT_WARNING, "Unable to stat '%s': %s", filepath, errno ? strerror(errno) : TIP_("unknown error stating file")); } - + text->flags &= ~TXT_ISDIRTY; } @@ -563,9 +563,9 @@ static int text_save_as_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSE str = text->id.name + 2; else str = bmain->name; - + RNA_string_set(op->ptr, "filepath", str); - WM_event_add_fileselect(C, op); + WM_event_add_fileselect(C, op); return OPERATOR_RUNNING_MODAL; } @@ -576,7 +576,7 @@ void TEXT_OT_save_as(wmOperatorType *ot) ot->name = "Save As"; ot->idname = "TEXT_OT_save_as"; ot->description = "Save active text file with options"; - + /* api callbacks */ ot->exec = text_save_as_exec; ot->invoke = text_save_as_invoke; @@ -653,7 +653,7 @@ void TEXT_OT_run_script(wmOperatorType *ot) ot->name = "Run Script"; ot->idname = "TEXT_OT_run_script"; ot->description = "Run active script"; - + /* api callbacks */ ot->poll = text_run_script_poll; ot->exec = text_run_script_exec; @@ -672,7 +672,7 @@ static int text_refresh_pyconstraints_exec(bContext *UNUSED(C), wmOperator *UNUS Object *ob; bConstraint *con; short update; - + /* check all pyconstraints */ for (ob = CTX_data_main(C)->object.first; ob; ob = ob->id.next) { update = 0; @@ -684,7 +684,7 @@ static int text_refresh_pyconstraints_exec(bContext *UNUSED(C), wmOperator *UNUS bPythonConstraint *data = con->data; if (data->text == text) BPY_pyconstraint_update(ob, con); update = 1; - + } } } @@ -696,7 +696,7 @@ static int text_refresh_pyconstraints_exec(bContext *UNUSED(C), wmOperator *UNUS update = 1; } } - + if (update) { DEG_id_tag_update(&ob->id, OB_RECALC_DATA); } @@ -713,7 +713,7 @@ void TEXT_OT_refresh_pyconstraints(wmOperatorType *ot) ot->name = "Refresh PyConstraints"; ot->idname = "TEXT_OT_refresh_pyconstraints"; ot->description = "Refresh all pyconstraints"; - + /* api callbacks */ ot->exec = text_refresh_pyconstraints_exec; ot->poll = text_edit_poll; @@ -757,7 +757,7 @@ void TEXT_OT_paste(wmOperatorType *ot) ot->name = "Paste"; ot->idname = "TEXT_OT_paste"; ot->description = "Paste text from clipboard"; - + /* api callbacks */ ot->exec = text_paste_exec; ot->poll = text_edit_poll; @@ -871,7 +871,7 @@ void TEXT_OT_cut(wmOperatorType *ot) ot->name = "Cut"; ot->idname = "TEXT_OT_cut"; ot->description = "Cut selected text to clipboard"; - + /* api callbacks */ ot->exec = text_cut_exec; ot->poll = text_edit_poll; @@ -912,7 +912,7 @@ void TEXT_OT_indent(wmOperatorType *ot) ot->name = "Indent"; ot->idname = "TEXT_OT_indent"; ot->description = "Indent selected text"; - + /* api callbacks */ ot->exec = text_indent_exec; ot->poll = text_edit_poll; @@ -948,7 +948,7 @@ void TEXT_OT_unindent(wmOperatorType *ot) ot->name = "Unindent"; ot->idname = "TEXT_OT_unindent"; ot->description = "Unindent selected text"; - + /* api callbacks */ ot->exec = text_unindent_exec; ot->poll = text_edit_poll; @@ -1077,7 +1077,7 @@ void TEXT_OT_uncomment(wmOperatorType *ot) ot->name = "Uncomment"; ot->idname = "TEXT_OT_uncomment"; ot->description = "Convert selected comment to text"; - + /* api callbacks */ ot->exec = text_uncomment_exec; ot->poll = text_edit_poll; @@ -1117,7 +1117,7 @@ static int text_convert_whitespace_exec(bContext *C, wmOperator *op) MEM_freeN(tmp->line); if (tmp->format) MEM_freeN(tmp->format); - + /* Put new_line in the tmp->line spot still need to try and set the curc correctly. */ tmp->line = new_line; tmp->len = strlen(new_line); @@ -1126,7 +1126,7 @@ static int text_convert_whitespace_exec(bContext *C, wmOperator *op) max_len = tmp->len; } } - + if (type == TO_TABS) { char *tmp_line = MEM_mallocN(sizeof(*tmp_line) * (max_len + 1), __func__); @@ -1212,7 +1212,7 @@ void TEXT_OT_convert_whitespace(wmOperatorType *ot) ot->name = "Convert Whitespace"; ot->idname = "TEXT_OT_convert_whitespace"; ot->description = "Convert whitespaces by type"; - + /* api callbacks */ ot->exec = text_convert_whitespace_exec; ot->poll = text_edit_poll; @@ -1244,7 +1244,7 @@ void TEXT_OT_select_all(wmOperatorType *ot) ot->name = "Select All"; ot->idname = "TEXT_OT_select_all"; ot->description = "Select all text"; - + /* api callbacks */ ot->exec = text_select_all_exec; ot->poll = text_edit_poll; @@ -1270,7 +1270,7 @@ void TEXT_OT_select_line(wmOperatorType *ot) ot->name = "Select Line"; ot->idname = "TEXT_OT_select_line"; ot->description = "Select text by line"; - + /* api callbacks */ ot->exec = text_select_line_exec; ot->poll = text_edit_poll; @@ -1315,14 +1315,14 @@ static int move_lines_exec(bContext *C, wmOperator *op) TextUndoBuf *utxt = ED_text_undo_push_init(C); txt_move_lines(text, utxt, direction); - + text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); /* run the script while editing, evil but useful */ if (CTX_wm_space_text(C)->live_edit) text_run_script(C, NULL); - + return OPERATOR_FINISHED; } @@ -1338,7 +1338,7 @@ void TEXT_OT_move_lines(wmOperatorType *ot) ot->name = "Move Lines"; ot->idname = "TEXT_OT_move_lines"; ot->description = "Move the currently selected line(s) up/down"; - + /* api callbacks */ ot->exec = move_lines_exec; ot->poll = text_edit_poll; @@ -1757,7 +1757,7 @@ static void cursor_skip(SpaceText *st, ARegion *ar, Text *text, int lines, const { TextLine **linep; int *charp; - + if (sel) { linep = &text->sell; charp = &text->selc; } else { linep = &text->curl; charp = &text->curc; } @@ -1802,7 +1802,7 @@ static int text_move_cursor(bContext *C, int type, bool select) if (st && st->wordwrap && ar) txt_wrap_move_bol(st, ar, select); else txt_move_bol(text, select); break; - + case LINE_END: if (!select) { txt_sel_clear(text); @@ -1814,7 +1814,7 @@ static int text_move_cursor(bContext *C, int type, bool select) case FILE_TOP: txt_move_bof(text, select); break; - + case FILE_BOTTOM: txt_move_eof(text, select); break; @@ -1857,7 +1857,7 @@ static int text_move_cursor(bContext *C, int type, bool select) if (st && st->wordwrap && ar) txt_wrap_move_up(st, ar, select); else txt_move_up(text, select); break; - + case NEXT_LINE: if (st && st->wordwrap && ar) txt_wrap_move_down(st, ar, select); else txt_move_down(text, select); @@ -1893,7 +1893,7 @@ void TEXT_OT_move(wmOperatorType *ot) ot->name = "Move Cursor"; ot->idname = "TEXT_OT_move"; ot->description = "Move cursor to position type"; - + /* api callbacks */ ot->exec = text_move_exec; ot->poll = text_edit_poll; @@ -1917,7 +1917,7 @@ void TEXT_OT_move_select(wmOperatorType *ot) ot->name = "Move Select"; ot->idname = "TEXT_OT_move_select"; ot->description = "Move the cursor while selecting"; - + /* api callbacks */ ot->exec = text_move_select_exec; ot->poll = text_space_edit_poll; @@ -1961,7 +1961,7 @@ void TEXT_OT_jump(wmOperatorType *ot) ot->name = "Jump"; ot->idname = "TEXT_OT_jump"; ot->description = "Jump cursor to line"; - + /* api callbacks */ ot->invoke = text_jump_invoke; ot->exec = text_jump_exec; @@ -2052,7 +2052,7 @@ static int text_delete_exec(bContext *C, wmOperator *op) /* run the script while editing, evil but useful */ if (st->live_edit) text_run_script(C, NULL); - + return OPERATOR_FINISHED; } @@ -2062,7 +2062,7 @@ void TEXT_OT_delete(wmOperatorType *ot) ot->name = "Delete"; ot->idname = "TEXT_OT_delete"; ot->description = "Delete text by cursor position"; - + /* api callbacks */ ot->exec = text_delete_exec; ot->poll = text_edit_poll; @@ -2093,7 +2093,7 @@ void TEXT_OT_overwrite_toggle(wmOperatorType *ot) ot->name = "Toggle Overwrite"; ot->idname = "TEXT_OT_overwrite_toggle"; ot->description = "Toggle overwrite while typing"; - + /* api callbacks */ ot->exec = text_toggle_overwrite_exec; ot->poll = text_space_edit_poll; @@ -2264,20 +2264,20 @@ static int text_scroll_invoke(bContext *C, wmOperator *op, const wmEvent *event) { SpaceText *st = CTX_wm_space_text(C); TextScroll *tsc; - + if (RNA_struct_property_is_set(op->ptr, "lines")) return text_scroll_exec(C, op); - + tsc = MEM_callocN(sizeof(TextScroll), "TextScroll"); tsc->first = 1; tsc->zone = SCROLLHANDLE_BAR; op->customdata = tsc; - + st->flags |= ST_SCROLL_SELECT; - + if (event->type == MOUSEPAN) { text_update_character_width(st); - + tsc->old[0] = event->x; tsc->old[1] = event->y; /* Sensitivity of scroll set to 4pix per line/char */ @@ -2291,7 +2291,7 @@ static int text_scroll_invoke(bContext *C, wmOperator *op, const wmEvent *event) } WM_event_add_modal_handler(C, op); - + return OPERATOR_RUNNING_MODAL; } @@ -2300,11 +2300,11 @@ void TEXT_OT_scroll(wmOperatorType *ot) /* identifiers */ ot->name = "Scroll"; /* don't really see the difference between this and - * scroll_bar. Both do basically the same thing (aside + * scroll_bar. Both do basically the same thing (aside * from keymaps).*/ ot->idname = "TEXT_OT_scroll"; ot->description = ""; - + /* api callbacks */ ot->exec = text_scroll_exec; ot->invoke = text_scroll_invoke; @@ -2330,10 +2330,10 @@ static int text_region_scroll_poll(bContext *C) if (!st || !text) return 0; - + if (!ar || ar->regiontype != RGN_TYPE_WINDOW) return 0; - + return 1; } @@ -2347,7 +2347,7 @@ static int text_scroll_bar_invoke(bContext *C, wmOperator *op, const wmEvent *ev if (RNA_struct_property_is_set(op->ptr, "lines")) return text_scroll_exec(C, op); - + /* verify we are in the right zone */ if (mval[0] > st->txtbar.xmin && mval[0] < st->txtbar.xmax) { if (mval[1] >= st->txtbar.ymin && mval[1] <= st->txtbar.ymax) { @@ -2392,11 +2392,11 @@ void TEXT_OT_scroll_bar(wmOperatorType *ot) /* identifiers */ ot->name = "Scrollbar"; /* don't really see the difference between this and - * scroll. Both do basically the same thing (aside + * scroll. Both do basically the same thing (aside * from keymaps).*/ ot->idname = "TEXT_OT_scroll_bar"; ot->description = ""; - + /* api callbacks */ ot->invoke = text_scroll_bar_invoke; ot->modal = text_scroll_modal; @@ -2431,7 +2431,7 @@ static int flatten_width(SpaceText *st, const char *str) total += BLI_str_utf8_char_width_safe(str + i); } } - + return total; } @@ -2444,14 +2444,14 @@ static int flatten_column_to_offset(SpaceText *st, const char *str, int index) col = st->tabnumber - i % st->tabnumber; else col = BLI_str_utf8_char_width_safe(str + j); - + if (i + col > index) break; - + i += col; j += BLI_str_utf8_size_safe(str + j); } - + return j; } @@ -2482,7 +2482,7 @@ static void text_cursor_set_to_pos_wrapped(SpaceText *st, ARegion *ar, int x, in int max = wrap_width(st, ar); /* column */ int charp = -1; /* mem */ bool found = false; /* flags */ - + /* Point to line matching given y position, if any. */ TextLine *linep = get_line_pos_wrapped(st, ar, &y); @@ -2495,7 +2495,7 @@ static void text_cursor_set_to_pos_wrapped(SpaceText *st, ARegion *ar, int x, in for (j = 0 ; !found && ((ch = linep->line[j]) != '\0'); j += BLI_str_utf8_size_safe(linep->line + j)) { int chars; int columns = BLI_str_utf8_char_width_safe(linep->line + j); /* = 1 for tab */ - + /* Mimic replacement of tabs */ if (ch == '\t') { chars = st->tabnumber - i % st->tabnumber; @@ -2504,7 +2504,7 @@ static void text_cursor_set_to_pos_wrapped(SpaceText *st, ARegion *ar, int x, in else { chars = 1; } - + while (chars--) { /* Gone too far, go back to last wrap point */ if (y < 0) { @@ -2526,22 +2526,22 @@ static void text_cursor_set_to_pos_wrapped(SpaceText *st, ARegion *ar, int x, in } if (i + columns - start > max) { end = MIN2(end, i); - + if (found) { /* exact cursor position was found, check if it's still on needed line (hasn't been wrapped) */ if (charp > endj && !chop && ch != '\0') charp = endj; break; } - + if (chop) endj = j; start = end; end += max; - + if (j < linep->len) y--; - + chop = true; if (y == 0 && i + columns - start > x) { charp = curs; @@ -2553,7 +2553,7 @@ static void text_cursor_set_to_pos_wrapped(SpaceText *st, ARegion *ar, int x, in if (found) { break; } - + if (y == 0 && i + columns - start > x) { charp = curs; found = true; @@ -2568,7 +2568,7 @@ static void text_cursor_set_to_pos_wrapped(SpaceText *st, ARegion *ar, int x, in } BLI_assert(y == 0); - + if (!found) { /* On correct line but didn't meet cursor, must be at end */ charp = linep->len; @@ -2606,7 +2606,7 @@ static void text_cursor_set_to_pos(SpaceText *st, ARegion *ar, int x, int y, con if (x < 0) x = 0; x = text_pixel_x_to_column(st, x) + st->left; - + if (st->wordwrap) { text_cursor_set_to_pos_wrapped(st, ar, x, y, sel); } @@ -2614,12 +2614,12 @@ static void text_cursor_set_to_pos(SpaceText *st, ARegion *ar, int x, int y, con TextLine **linep; int *charp; int w; - + if (sel) { linep = &text->sell; charp = &text->selc; } else { linep = &text->curl; charp = &text->curc; } - + y -= txt_get_span(text->lines.first, *linep) - st->top; - + if (y > 0) { while (y-- != 0) { if ((*linep)->next) *linep = (*linep)->next; @@ -2631,7 +2631,7 @@ static void text_cursor_set_to_pos(SpaceText *st, ARegion *ar, int x, int y, con } } - + w = flatten_width(st, (*linep)->line); if (x < w) *charp = flatten_column_to_offset(st, (*linep)->line, x); else *charp = (*linep)->len; @@ -2679,7 +2679,7 @@ static void text_cursor_set_apply(bContext *C, wmOperator *op, const wmEvent *ev } else if (!st->wordwrap && (event->mval[0] < 0 || event->mval[0] > ar->winx)) { text_cursor_timer_ensure(C, ssel); - + if (event->type == TIMER) { text_cursor_set_to_pos(st, ar, CLAMPIS(event->mval[0], 0, ar->winx), event->mval[1], 1); text_scroll_to_cursor(st, ar, false); @@ -2876,7 +2876,7 @@ void TEXT_OT_line_number(wmOperatorType *ot) ot->name = "Line Number"; ot->idname = "TEXT_OT_line_number"; ot->description = "The current line number"; - + /* api callbacks */ ot->invoke = text_line_number_invoke; ot->poll = text_region_edit_poll; @@ -2913,7 +2913,7 @@ static int text_insert_exec(bContext *C, wmOperator *op) } MEM_freeN(str); - + if (!done) return OPERATOR_CANCELLED; @@ -2941,7 +2941,7 @@ static int text_insert_invoke(bContext *C, wmOperator *op, const wmEvent *event) else { char str[BLI_UTF8_MAX + 1]; size_t len; - + if (event->utf8_buf[0]) { len = BLI_str_utf8_size_safe(event->utf8_buf); memcpy(str, event->utf8_buf, len); @@ -2956,7 +2956,7 @@ static int text_insert_invoke(bContext *C, wmOperator *op, const wmEvent *event) } ret = text_insert_exec(C, op); - + /* run the script while editing, evil but useful */ if (ret == OPERATOR_FINISHED && CTX_wm_space_text(C)->live_edit) text_run_script(C, NULL); @@ -2972,7 +2972,7 @@ void TEXT_OT_insert(wmOperatorType *ot) ot->name = "Insert"; ot->idname = "TEXT_OT_insert"; ot->description = "Insert text at cursor position"; - + /* api callbacks */ ot->exec = text_insert_exec; ot->invoke = text_insert_invoke; @@ -3064,7 +3064,7 @@ void TEXT_OT_find(wmOperatorType *ot) ot->name = "Find Next"; ot->idname = "TEXT_OT_find"; ot->description = "Find specified text"; - + /* api callbacks */ ot->exec = text_find_exec; ot->poll = text_space_edit_poll; @@ -3116,7 +3116,7 @@ void TEXT_OT_find_set_selected(wmOperatorType *ot) ot->name = "Find Set Selected"; ot->idname = "TEXT_OT_find_set_selected"; ot->description = "Find specified text and set as selected"; - + /* api callbacks */ ot->exec = text_find_set_selected_exec; ot->poll = text_space_edit_poll; @@ -3143,7 +3143,7 @@ void TEXT_OT_replace_set_selected(wmOperatorType *ot) ot->name = "Replace Set Selected"; ot->idname = "TEXT_OT_replace_set_selected"; ot->description = "Replace text with specified text and set as selected"; - + /* api callbacks */ ot->exec = text_replace_set_selected_exec; ot->poll = text_space_edit_poll; @@ -3259,11 +3259,11 @@ void TEXT_OT_to_3d_object(wmOperatorType *ot) ot->name = "To 3D Object"; ot->idname = "TEXT_OT_to_3d_object"; ot->description = "Create 3D text object from active text data-block"; - + /* api callbacks */ ot->exec = text_to_3d_object_exec; ot->poll = text_edit_poll; - + /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; |