diff options
-rw-r--r-- | source/blender/blenkernel/BKE_text.h | 8 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/text.c | 38 | ||||
-rw-r--r-- | source/blender/editors/space_text/space_text.c | 10 | ||||
-rw-r--r-- | source/blender/editors/space_text/text_intern.h | 3 | ||||
-rw-r--r-- | source/blender/editors/space_text/text_ops.c | 50 |
5 files changed, 51 insertions, 58 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); } } diff --git a/source/blender/editors/space_text/space_text.c b/source/blender/editors/space_text/space_text.c index ddff1fe603f..85eda858d24 100644 --- a/source/blender/editors/space_text/space_text.c +++ b/source/blender/editors/space_text/space_text.c @@ -44,6 +44,7 @@ #include "BKE_context.h" #include "BKE_screen.h" +#include "BKE_text.h" #include "ED_space_api.h" #include "ED_screen.h" @@ -203,8 +204,7 @@ static void text_operatortypes(void) WM_operatortype_append(TEXT_OT_select_all); WM_operatortype_append(TEXT_OT_select_word); - WM_operatortype_append(TEXT_OT_move_lines_up); - WM_operatortype_append(TEXT_OT_move_lines_down); + WM_operatortype_append(TEXT_OT_move_lines); WM_operatortype_append(TEXT_OT_jump); WM_operatortype_append(TEXT_OT_move); @@ -323,9 +323,9 @@ static void text_keymap(struct wmKeyConfig *keyconf) WM_keymap_add_item(keymap, "TEXT_OT_select_all", AKEY, KM_PRESS, KM_CTRL, 0); WM_keymap_add_item(keymap, "TEXT_OT_select_line", AKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0); WM_keymap_add_item(keymap, "TEXT_OT_select_word", LEFTMOUSE, KM_DBL_CLICK, 0, 0); - - WM_keymap_add_item(keymap, "TEXT_OT_move_lines_up", UPARROWKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0); - WM_keymap_add_item(keymap, "TEXT_OT_move_lines_down", DOWNARROWKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0); + + RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_lines", UPARROWKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0)->ptr, "direction", TXT_MOVE_LINE_UP); + RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_lines", DOWNARROWKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0)->ptr, "direction", TXT_MOVE_LINE_DOWN); WM_keymap_add_item(keymap, "TEXT_OT_indent", TABKEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "TEXT_OT_unindent", TABKEY, KM_PRESS, KM_SHIFT, 0); diff --git a/source/blender/editors/space_text/text_intern.h b/source/blender/editors/space_text/text_intern.h index be6287a939c..4f973e7076b 100644 --- a/source/blender/editors/space_text/text_intern.h +++ b/source/blender/editors/space_text/text_intern.h @@ -137,8 +137,7 @@ void TEXT_OT_select_line(struct wmOperatorType *ot); void TEXT_OT_select_all(struct wmOperatorType *ot); void TEXT_OT_select_word(struct wmOperatorType *ot); -void TEXT_OT_move_lines_up(struct wmOperatorType *ot); -void TEXT_OT_move_lines_down(struct wmOperatorType *ot); +void TEXT_OT_move_lines(struct wmOperatorType *ot); void TEXT_OT_jump(struct wmOperatorType *ot); void TEXT_OT_move(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index cb8daa0f03e..a07493ef8fc 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -1333,11 +1333,12 @@ void TEXT_OT_select_word(wmOperatorType *ot) /********************* move lines operators ***********************/ -static int move_lines_up_exec(bContext *C, wmOperator *UNUSED(op)) +static int move_lines_exec(bContext *C, wmOperator *op) { Text *text = CTX_data_edit_text(C); + const int direction = RNA_enum_get(op->ptr, "direction"); - txt_move_lines_up(text); + txt_move_lines(text, direction); text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text); @@ -1349,44 +1350,25 @@ static int move_lines_up_exec(bContext *C, wmOperator *UNUSED(op)) return OPERATOR_FINISHED; } -void TEXT_OT_move_lines_up(wmOperatorType *ot) +void TEXT_OT_move_lines(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Move Lines Up"; - ot->idname = "TEXT_OT_move_lines_up"; - ot->description = "Moves the currently selected line(s) up."; - - /* api callbacks */ - ot->exec = move_lines_up_exec; - ot->poll = text_edit_poll; -} - -static int move_lines_down_exec(bContext *C, wmOperator *UNUSED(op)) -{ - Text *text = CTX_data_edit_text(C); - - txt_move_lines_down(text); - - text_update_cursor_moved(C); - WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text); + static EnumPropertyItem direction_items[]= { + {TXT_MOVE_LINE_UP, "UP", 0, "Up", ""}, + {TXT_MOVE_LINE_DOWN, "DOWN", 0, "Down", ""}, + {0, NULL, 0, NULL, NULL} + }; - /* run the script while editing, evil but useful */ - if (CTX_wm_space_text(C)->live_edit) - text_run_script(C, NULL); - - return OPERATOR_FINISHED; -} - -void TEXT_OT_move_lines_down(wmOperatorType *ot) -{ /* identifiers */ - ot->name = "Move Lines Down"; - ot->idname = "TEXT_OT_move_lines_down"; - ot->description = "Moves the currently selected line(s) down."; + ot->name = "Move Lines"; + ot->idname = "TEXT_OT_move_lines"; + ot->description = "Moves the currently selected line(s) up/down"; /* api callbacks */ - ot->exec = move_lines_down_exec; + ot->exec = move_lines_exec; ot->poll = text_edit_poll; + + /* properties */ + RNA_def_enum(ot->srna, "direction", direction_items, 1, "Direction", ""); } /******************* previous marker operator *********************/ |