diff options
Diffstat (limited to 'source/blender/editors/space_text')
-rw-r--r-- | source/blender/editors/space_text/space_text.c | 5 | ||||
-rw-r--r-- | source/blender/editors/space_text/text_draw.c | 119 | ||||
-rw-r--r-- | source/blender/editors/space_text/text_intern.h | 8 | ||||
-rw-r--r-- | source/blender/editors/space_text/text_ops.c | 223 | ||||
-rw-r--r-- | source/blender/editors/space_text/text_python.c | 174 |
5 files changed, 37 insertions, 492 deletions
diff --git a/source/blender/editors/space_text/space_text.c b/source/blender/editors/space_text/space_text.c index 3f70b2cb66e..d74e32620af 100644 --- a/source/blender/editors/space_text/space_text.c +++ b/source/blender/editors/space_text/space_text.c @@ -196,10 +196,6 @@ static void text_operatortypes(void) WM_operatortype_append(TEXT_OT_unindent); WM_operatortype_append(TEXT_OT_indent); - WM_operatortype_append(TEXT_OT_markers_clear); - WM_operatortype_append(TEXT_OT_next_marker); - WM_operatortype_append(TEXT_OT_previous_marker); - WM_operatortype_append(TEXT_OT_select_line); WM_operatortype_append(TEXT_OT_select_all); WM_operatortype_append(TEXT_OT_select_word); @@ -227,7 +223,6 @@ static void text_operatortypes(void) WM_operatortype_append(TEXT_OT_find_set_selected); WM_operatortype_append(TEXT_OT_replace); WM_operatortype_append(TEXT_OT_replace_set_selected); - WM_operatortype_append(TEXT_OT_mark_all); WM_operatortype_append(TEXT_OT_to_3d_object); diff --git a/source/blender/editors/space_text/text_draw.c b/source/blender/editors/space_text/text_draw.c index 423452e207b..46ab2d9e688 100644 --- a/source/blender/editors/space_text/text_draw.c +++ b/source/blender/editors/space_text/text_draw.c @@ -1070,40 +1070,6 @@ int text_get_total_lines(SpaceText *st, ARegion *ar) return drawcache->total_lines; } -/* Move pointer to first visible line (top) */ -static TextLine *first_visible_line(SpaceText *st, ARegion *ar, int *wrap_top) -{ - Text *text = st->text; - TextLine *pline = text->lines.first; - int i = st->top, lineno = 0; - - text_update_drawcache(st, ar); - - if (wrap_top) *wrap_top = 0; - - if (st->wordwrap) { - while (i > 0 && pline) { - int lines = text_get_visible_lines_no(st, lineno); - - if (i - lines < 0) { - if (wrap_top) *wrap_top = i; - break; - } - else { - pline = pline->next; - i -= lines; - lineno++; - } - } - } - else { - for (i = st->top; pline->next && i > 0; i--) - pline = pline->next; - } - - return pline; -} - /************************ draw scrollbar *****************************/ static void calc_text_rcts(SpaceText *st, ARegion *ar, rcti *scroll, rcti *back) @@ -1241,90 +1207,6 @@ static void draw_textscroll(SpaceText *st, rcti *scroll, rcti *back) glDisable(GL_BLEND); } -/************************** draw markers **************************/ - -static void draw_markers(SpaceText *st, ARegion *ar) -{ - Text *text = st->text; - TextMarker *marker, *next; - TextLine *top, *line; - int offl, offc, i, x1, x2, y1, y2, x, y; - int topi, topy; - - /* Move pointer to first visible line (top) */ - top = first_visible_line(st, ar, NULL); - topi = BLI_findindex(&text->lines, top); - - topy = txt_get_span(text->lines.first, top); - - for (marker = text->markers.first; marker; marker = next) { - next = marker->next; - - /* invisible line (before top) */ - if (marker->lineno < topi) continue; - - line = BLI_findlink(&text->lines, marker->lineno); - - /* Remove broken markers */ - if (marker->end > line->len || marker->start > marker->end) { - BLI_freelinkN(&text->markers, marker); - continue; - } - - wrap_offset(st, ar, line, marker->start, &offl, &offc); - y1 = txt_get_span(top, line) - st->top + offl + topy; - x1 = text_get_char_pos(st, line->line, marker->start) - st->left + offc; - - wrap_offset(st, ar, line, marker->end, &offl, &offc); - y2 = txt_get_span(top, line) - st->top + offl + topy; - x2 = text_get_char_pos(st, line->line, marker->end) - st->left + offc; - - /* invisible part of line (before top, after last visible line) */ - if (y2 < 0 || y1 > st->top + st->viewlines) continue; - - glColor3ubv(marker->color); - x = st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET; - y = ar->winy - 3; - - if (y1 == y2) { - y -= y1 * st->lheight; - glBegin(GL_LINE_LOOP); - glVertex2i(x + x2 * st->cwidth + 1, y); - glVertex2i(x + x1 * st->cwidth - 2, y); - glVertex2i(x + x1 * st->cwidth - 2, y - st->lheight); - glVertex2i(x + x2 * st->cwidth + 1, y - st->lheight); - glEnd(); - } - else { - y -= y1 * st->lheight; - glBegin(GL_LINE_STRIP); - glVertex2i(ar->winx, y); - glVertex2i(x + x1 * st->cwidth - 2, y); - glVertex2i(x + x1 * st->cwidth - 2, y - st->lheight); - glVertex2i(ar->winx, y - st->lheight); - glEnd(); - y -= st->lheight; - - for (i = y1 + 1; i < y2; i++) { - glBegin(GL_LINES); - glVertex2i(x, y); - glVertex2i(ar->winx, y); - glVertex2i(x, y - st->lheight); - glVertex2i(ar->winx, y - st->lheight); - glEnd(); - y -= st->lheight; - } - - glBegin(GL_LINE_STRIP); - glVertex2i(x, y); - glVertex2i(x + x2 * st->cwidth + 1, y); - glVertex2i(x + x2 * st->cwidth + 1, y - st->lheight); - glVertex2i(x, y - st->lheight); - glEnd(); - } - } -} - /*********************** draw documentation *******************************/ static void draw_documentation(SpaceText *st, ARegion *ar) @@ -1860,7 +1742,6 @@ void draw_text_main(SpaceText *st, ARegion *ar) /* draw other stuff */ draw_brackets(st, ar); - draw_markers(st, ar); glTranslatef(GLA_PIXEL_OFS, GLA_PIXEL_OFS, 0.0f); /* XXX scroll requires exact pixel space */ draw_textscroll(st, &scroll, &back); draw_documentation(st, ar); diff --git a/source/blender/editors/space_text/text_intern.h b/source/blender/editors/space_text/text_intern.h index d687f4cdd8a..ea61644cee9 100644 --- a/source/blender/editors/space_text/text_intern.h +++ b/source/blender/editors/space_text/text_intern.h @@ -69,9 +69,6 @@ void text_update_cursor_moved(struct bContext *C); #define TOOL_SUGG_LIST 0x01 #define TOOL_DOCUMENT 0x02 -#define TMARK_GRP_CUSTOM 0x00010000 /* Lower 2 bytes used for Python groups */ -#define TMARK_GRP_FINDALL 0x00020000 - typedef struct FlattenString { char fixedbuf[256]; int fixedaccum[256]; @@ -130,10 +127,6 @@ void TEXT_OT_indent(struct wmOperatorType *ot); void TEXT_OT_line_break(struct wmOperatorType *ot); void TEXT_OT_insert(struct wmOperatorType *ot); -void TEXT_OT_markers_clear(struct wmOperatorType *ot); -void TEXT_OT_next_marker(struct wmOperatorType *ot); -void TEXT_OT_previous_marker(struct wmOperatorType *ot); - void TEXT_OT_select_line(struct wmOperatorType *ot); void TEXT_OT_select_all(struct wmOperatorType *ot); void TEXT_OT_select_word(struct wmOperatorType *ot); @@ -158,7 +151,6 @@ void TEXT_OT_find(struct wmOperatorType *ot); void TEXT_OT_find_set_selected(struct wmOperatorType *ot); void TEXT_OT_replace(struct wmOperatorType *ot); void TEXT_OT_replace_set_selected(struct wmOperatorType *ot); -void TEXT_OT_mark_all(struct wmOperatorType *ot); void TEXT_OT_to_3d_object(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index ae5de4c6a25..cd6d8719544 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -1377,104 +1377,6 @@ void TEXT_OT_move_lines(wmOperatorType *ot) RNA_def_enum(ot->srna, "direction", direction_items, 1, "Direction", ""); } -/******************* previous marker operator *********************/ - -static int text_previous_marker_exec(bContext *C, wmOperator *UNUSED(op)) -{ - Text *text = CTX_data_edit_text(C); - TextMarker *mrk; - int lineno; - - lineno = txt_get_span(text->lines.first, text->curl); - mrk = text->markers.last; - while (mrk && (mrk->lineno > lineno || (mrk->lineno == lineno && mrk->end > text->curc))) - mrk = mrk->prev; - if (!mrk) mrk = text->markers.last; - if (mrk) { - txt_move_to(text, mrk->lineno, mrk->start, 0); - txt_move_to(text, mrk->lineno, mrk->end, 1); - } - - text_update_cursor_moved(C); - WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); - - return OPERATOR_FINISHED; -} - -void TEXT_OT_previous_marker(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Previous Marker"; - ot->idname = "TEXT_OT_previous_marker"; - ot->description = "Move to previous marker"; - - /* api callbacks */ - ot->exec = text_previous_marker_exec; - ot->poll = text_edit_poll; -} - -/******************* next marker operator *********************/ - -static int text_next_marker_exec(bContext *C, wmOperator *UNUSED(op)) -{ - Text *text = CTX_data_edit_text(C); - TextMarker *mrk; - int lineno; - - lineno = txt_get_span(text->lines.first, text->curl); - mrk = text->markers.first; - while (mrk && (mrk->lineno < lineno || (mrk->lineno == lineno && mrk->start <= text->curc))) - mrk = mrk->next; - if (!mrk) mrk = text->markers.first; - if (mrk) { - txt_move_to(text, mrk->lineno, mrk->start, 0); - txt_move_to(text, mrk->lineno, mrk->end, 1); - } - - text_update_cursor_moved(C); - WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); - - return OPERATOR_FINISHED; -} - -void TEXT_OT_next_marker(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Next Marker"; - ot->idname = "TEXT_OT_next_marker"; - ot->description = "Move to next marker"; - - /* api callbacks */ - ot->exec = text_next_marker_exec; - ot->poll = text_edit_poll; -} - -/******************* clear all markers operator *********************/ - -static int text_clear_all_markers_exec(bContext *C, wmOperator *UNUSED(op)) -{ - Text *text = CTX_data_edit_text(C); - - txt_clear_markers(text, 0, 0); - - text_update_cursor_moved(C); - WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); - - return OPERATOR_FINISHED; -} - -void TEXT_OT_markers_clear(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Clear All Markers"; - ot->idname = "TEXT_OT_markers_clear"; - ot->description = "Clear all markers"; - - /* api callbacks */ - ot->exec = text_clear_all_markers_exec; - ot->poll = text_edit_poll; -} - /************************ move operator ************************/ static EnumPropertyItem move_type_items[] = { @@ -2956,14 +2858,13 @@ void TEXT_OT_insert(wmOperatorType *ot) /* mode */ #define TEXT_FIND 0 #define TEXT_REPLACE 1 -#define TEXT_MARK_ALL 2 static int text_find_and_replace(bContext *C, wmOperator *op, short mode) { Main *bmain = CTX_data_main(C); SpaceText *st = CTX_wm_space_text(C); - Text *start = NULL, *text = st->text; - int flags, first = 1; + Text *text = st->text; + int flags; int found = 0; char *tmp; @@ -2972,79 +2873,48 @@ static int text_find_and_replace(bContext *C, wmOperator *op, short mode) flags = st->flags; if (flags & ST_FIND_ALL) - flags ^= ST_FIND_WRAP; - - do { - int proceed = 0; - - if (first) { - if (text->markers.first) - WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); + flags &= ~ST_FIND_WRAP; - txt_clear_markers(text, TMARK_GRP_FINDALL, 0); - } - - first = 0; - - /* Replace current */ - if (mode != TEXT_FIND && txt_has_sel(text)) { - tmp = txt_sel_to_buf(text); - - if (flags & ST_MATCH_CASE) proceed = strcmp(st->findstr, tmp) == 0; - else proceed = BLI_strcasecmp(st->findstr, tmp) == 0; - - if (proceed) { - if (mode == TEXT_REPLACE) { - txt_insert_buf(text, st->replacestr); - if (text->curl && text->curl->format) { - MEM_freeN(text->curl->format); - text->curl->format = NULL; - } - text_update_cursor_moved(C); - WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); - text_drawcache_tag_update(CTX_wm_space_text(C), 1); - } - else if (mode == TEXT_MARK_ALL) { - unsigned char color[4]; - UI_GetThemeColor4ubv(TH_SHADE2, color); + /* Replace current */ + if (mode != TEXT_FIND && txt_has_sel(text)) { + tmp = txt_sel_to_buf(text); - if (txt_find_marker(text, text->curl, text->selc, TMARK_GRP_FINDALL, 0)) { - if (tmp) MEM_freeN(tmp), tmp = NULL; - break; - } + if (flags & ST_MATCH_CASE) found = strcmp(st->findstr, tmp) == 0; + else found = BLI_strcasecmp(st->findstr, tmp) == 0; - txt_add_marker(text, text->curl, text->curc, text->selc, color, TMARK_GRP_FINDALL, TMARK_EDITALL); - text_update_cursor_moved(C); - WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); + if (found) { + if (mode == TEXT_REPLACE) { + txt_insert_buf(text, st->replacestr); + if (text->curl && text->curl->format) { + MEM_freeN(text->curl->format); + text->curl->format = NULL; } + text_update_cursor_moved(C); + WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); + text_drawcache_tag_update(CTX_wm_space_text(C), 1); } - MEM_freeN(tmp); - tmp = NULL; } + MEM_freeN(tmp); + tmp = NULL; + } - /* Find next */ - if (txt_find_string(text, st->findstr, flags & ST_FIND_WRAP, flags & ST_MATCH_CASE)) { - text_update_cursor_moved(C); - WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, text); - } - else if (flags & ST_FIND_ALL) { - if (text == start) break; - if (!start) start = text; - if (text->id.next) - text = st->text = text->id.next; - else - text = st->text = bmain->text.first; - txt_move_toline(text, 0, 0); - text_update_cursor_moved(C); - WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, text); - first = 1; - } - else { - if (!found && !proceed) BKE_reportf(op->reports, RPT_ERROR, "Text not found: %s", st->findstr); - break; - } - found = 1; - } while (mode == TEXT_MARK_ALL); + /* Find next */ + if (txt_find_string(text, st->findstr, flags & ST_FIND_WRAP, flags & ST_MATCH_CASE)) { + text_update_cursor_moved(C); + WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, text); + } + else if (flags & ST_FIND_ALL) { + if (text->id.next) + text = st->text = text->id.next; + else + text = st->text = bmain->text.first; + txt_move_toline(text, 0, 0); + text_update_cursor_moved(C); + WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, text); + } + else { + if (!found) BKE_reportf(op->reports, RPT_ERROR, "Text not found: %s", st->findstr); + } return OPERATOR_FINISHED; } @@ -3085,25 +2955,6 @@ void TEXT_OT_replace(wmOperatorType *ot) ot->poll = text_space_edit_poll; } -/******************* mark all operator *********************/ - -static int text_mark_all_exec(bContext *C, wmOperator *op) -{ - return text_find_and_replace(C, op, TEXT_MARK_ALL); -} - -void TEXT_OT_mark_all(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Mark All"; - ot->idname = "TEXT_OT_mark_all"; - ot->description = "Mark all specified text"; - - /* api callbacks */ - ot->exec = text_mark_all_exec; - ot->poll = text_space_edit_poll; -} - /******************* find set selected *********************/ static int text_find_set_selected_exec(bContext *C, wmOperator *op) diff --git a/source/blender/editors/space_text/text_python.c b/source/blender/editors/space_text/text_python.c index 966afe22e42..4c9b4b900cc 100644 --- a/source/blender/editors/space_text/text_python.c +++ b/source/blender/editors/space_text/text_python.c @@ -359,177 +359,3 @@ static short UNUSED_FUNCTION(do_texttools) (SpaceText * st, char ascii, unsigned return swallow; } - -static short UNUSED_FUNCTION(do_textmarkers) (SpaceText * st, char ascii, unsigned short evnt, short val) -{ - Text *text; - TextMarker *marker, *mrk, *nxt; - int c, s, draw = 0, swallow = 0; - int qual = 0; // XXX - - text = st->text; - if (!text || text->id.lib || text->curl != text->sell) return 0; - - marker = txt_find_marker(text, text->sell, text->selc, 0, 0); - if (marker && (marker->start > text->curc || marker->end < text->curc)) - marker = NULL; - - if (!marker) { - /* Find the next temporary marker */ - if (evnt == TABKEY) { - int lineno = txt_get_span(text->lines.first, text->curl); - mrk = text->markers.first; - while (mrk) { - if (!marker && (mrk->flags & TMARK_TEMP)) marker = mrk; - if ((mrk->flags & TMARK_TEMP) && (mrk->lineno > lineno || (mrk->lineno == lineno && mrk->end > text->curc))) { - marker = mrk; - break; - } - mrk = mrk->next; - } - if (marker) { - txt_move_to(text, marker->lineno, marker->start, 0); - txt_move_to(text, marker->lineno, marker->end, 1); - // XXX text_update_cursor_moved(C); - // XXX WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text); - evnt = ascii = val = 0; - draw = 1; - swallow = 1; - } - } - else if (evnt == ESCKEY) { - if (txt_clear_markers(text, 0, TMARK_TEMP)) swallow = 1; - else if (txt_clear_markers(text, 0, 0)) swallow = 1; - else return 0; - evnt = ascii = val = 0; - draw = 1; - } - if (!swallow) return 0; - } - - if (ascii) { - if (marker->flags & TMARK_EDITALL) { - c = text->curc - marker->start; - s = text->selc - marker->start; - if (s < 0 || s > marker->end - marker->start) return 0; - - mrk = txt_next_marker(text, marker); - while (mrk) { - nxt = txt_next_marker(text, mrk); /* mrk may become invalid */ - txt_move_to(text, mrk->lineno, mrk->start + c, 0); - if (s != c) txt_move_to(text, mrk->lineno, mrk->start + s, 1); - if (st->overwrite) { - if (txt_replace_char(text, ascii)) - text_update_line_edited(st->text->curl); - } - else { - if (txt_add_char(text, ascii)) { - text_update_line_edited(st->text->curl); - } - } - - if (mrk == marker || mrk == nxt) break; - mrk = nxt; - } - swallow = 1; - draw = 1; - } - } - else if (val) { - switch (evnt) { - case BACKSPACEKEY: - if (marker->flags & TMARK_EDITALL) { - c = text->curc - marker->start; - s = text->selc - marker->start; - if (s < 0 || s > marker->end - marker->start) return 0; - - mrk = txt_next_marker(text, marker); - while (mrk) { - nxt = txt_next_marker(text, mrk); /* mrk may become invalid */ - txt_move_to(text, mrk->lineno, mrk->start + c, 0); - if (s != c) txt_move_to(text, mrk->lineno, mrk->start + s, 1); - txt_backspace_char(text); - text_update_line_edited(st->text->curl); - if (mrk == marker || mrk == nxt) break; - mrk = nxt; - } - swallow = 1; - draw = 1; - } - break; - case DELKEY: - if (marker->flags & TMARK_EDITALL) { - c = text->curc - marker->start; - s = text->selc - marker->start; - if (s < 0 || s > marker->end - marker->start) return 0; - - mrk = txt_next_marker(text, marker); - while (mrk) { - nxt = txt_next_marker(text, mrk); /* mrk may become invalid */ - txt_move_to(text, mrk->lineno, mrk->start + c, 0); - if (s != c) txt_move_to(text, mrk->lineno, mrk->start + s, 1); - txt_delete_char(text); - text_update_line_edited(st->text->curl); - if (mrk == marker || mrk == nxt) break; - mrk = nxt; - } - swallow = 1; - draw = 1; - } - break; - case TABKEY: - if (qual & LR_SHIFTKEY) { - nxt = marker->prev; - if (!nxt) nxt = text->markers.last; - } - else { - nxt = marker->next; - if (!nxt) nxt = text->markers.first; - } - if (marker->flags & TMARK_TEMP) { - if (nxt == marker) nxt = NULL; - BLI_freelinkN(&text->markers, marker); - } - mrk = nxt; - if (mrk) { - txt_move_to(text, mrk->lineno, mrk->start, 0); - txt_move_to(text, mrk->lineno, mrk->end, 1); - // XXX text_update_cursor_moved(C); - // XXX WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text); - } - swallow = 1; - draw = 1; - break; - - /* Events that should clear markers */ - case UKEY: if (!(qual & LR_ALTKEY)) break; - case ZKEY: if (evnt == ZKEY && !(qual & LR_CTRLKEY)) break; - case RETKEY: - case ESCKEY: - if (marker->flags & (TMARK_EDITALL | TMARK_TEMP)) - txt_clear_markers(text, marker->group, 0); - else - BLI_freelinkN(&text->markers, marker); - swallow = 1; - draw = 1; - break; - case RIGHTMOUSE: /* Marker context menu? */ - case LEFTMOUSE: - break; - case FKEY: /* Allow find */ - if (qual & LR_SHIFTKEY) swallow = 1; - break; - - default: - if (qual != 0 && qual != LR_SHIFTKEY) - swallow = 1; /* Swallow all other shortcut events */ - } - } - - if (draw) { - // XXX redraw_alltext(); - } - - return swallow; -} - |