diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-05-04 20:17:09 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-05-04 20:17:09 +0400 |
commit | b6edcc4b33e782b4a91a61d1c46136c52a4172c9 (patch) | |
tree | 9a70fa74cc51ca3ba6b91463848c82b559cb09bc /source/blender/blenkernel | |
parent | 1fd397d2d6ce5f9036c606963060eaf5f49d72c4 (diff) |
make text move up/down into a single operator with a direction property
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_text.h | 8 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/text.c | 38 |
2 files changed, 29 insertions, 17 deletions
diff --git a/source/blender/blenkernel/BKE_text.h b/source/blender/blenkernel/BKE_text.h index 393663456d5..115c00d9e73 100644 --- a/source/blender/blenkernel/BKE_text.h +++ b/source/blender/blenkernel/BKE_text.h @@ -96,8 +96,7 @@ void txt_unindent (struct Text *text); void txt_comment (struct Text *text); void txt_indent (struct Text *text); void txt_uncomment (struct Text *text); -void txt_move_lines_up (struct Text *text); -void txt_move_lines_down (struct Text *text); +void txt_move_lines (struct Text *text, const int direction); void txt_duplicate_line (struct Text *text); int setcurr_tab_spaces (struct Text *text, int space); @@ -116,6 +115,11 @@ int text_check_digit(const char ch); int text_check_identifier(const char ch); int text_check_whitespace(const char ch); +enum { + TXT_MOVE_LINE_UP = -1, + TXT_MOVE_LINE_DOWN = 1 +}; + /* Undo opcodes */ diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index db0ff6eeca6..d67c5fb3698 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -2201,10 +2201,10 @@ void txt_do_undo(Text *text) txt_delete_line(text, text->curl->next); break; case UNDO_MOVE_LINES_UP: - txt_move_lines_down(text); + txt_move_lines(text, TXT_MOVE_LINE_DOWN); break; case UNDO_MOVE_LINES_DOWN: - txt_move_lines_up(text); + txt_move_lines(text, TXT_MOVE_LINE_UP); break; default: //XXX error("Undo buffer error - resetting"); @@ -2407,10 +2407,10 @@ void txt_do_redo(Text *text) txt_duplicate_line(text); break; case UNDO_MOVE_LINES_UP: - txt_move_lines_up(text); + txt_move_lines(text, TXT_MOVE_LINE_UP); break; case UNDO_MOVE_LINES_DOWN: - txt_move_lines_down(text); + txt_move_lines(text, TXT_MOVE_LINE_DOWN); break; default: //XXX error("Undo buffer error - resetting"); @@ -3069,26 +3069,34 @@ void txt_move_lines_up(struct Text *text) } } -void txt_move_lines_down(struct Text *text) +void txt_move_lines(struct Text *text, const int direction) { - TextLine *next_line; - + TextLine *line_other; + + BLI_assert(ELEM(direction, TXT_MOVE_LINE_UP, TXT_MOVE_LINE_DOWN)); + if (!text || !text->curl || !text->sell) return; txt_order_cursors(text); + + line_other = (direction == TXT_MOVE_LINE_DOWN) ? text->sell->next : text->curl->prev; - next_line= text->sell->next; - - if (!next_line) return; + if (!line_other) return; - BLI_remlink(&text->lines, next_line); - BLI_insertlinkbefore(&text->lines, text->curl, next_line); - + BLI_remlink(&text->lines, line_other); + + if (direction == TXT_MOVE_LINE_DOWN) { + BLI_insertlinkbefore(&text->lines, text->curl, line_other); + } + else { + BLI_insertlinkafter(&text->lines, text->sell, line_other); + } + txt_make_dirty(text); txt_clean_text(text); - if (!undoing) { - txt_undo_add_op(text, UNDO_MOVE_LINES_DOWN); + if (!undoing) { + txt_undo_add_op(text, (direction == TXT_MOVE_LINE_DOWN) ? UNDO_MOVE_LINES_DOWN : UNDO_MOVE_LINES_UP); } } |