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/editors | |
parent | 1fd397d2d6ce5f9036c606963060eaf5f49d72c4 (diff) |
make text move up/down into a single operator with a direction property
Diffstat (limited to 'source/blender/editors')
-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 |
3 files changed, 22 insertions, 41 deletions
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 *********************/ |