Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Leung <aligorith@gmail.com>2012-05-04 18:27:13 +0400
committerJoshua Leung <aligorith@gmail.com>2012-05-04 18:27:13 +0400
commit2bc29ff4260e28dd89409255997858ca447ad51f (patch)
tree3ffc5961c796571371f1edaaaaa709fc953e1e62 /source/blender/editors/space_text
parente62f13ac311eec269abb6a9429b29279dc642cec (diff)
Patch [#30654] Wiki Quick Hack: Text editor move lines up/down
Submitted by: Justin Dailey (dail) Patch allows the current line (or selected lines) to be moved up and down with Ctrl+Shift+Up and Ctrl+Shift+Down. Has undo/redo support and operators in python menu.
Diffstat (limited to 'source/blender/editors/space_text')
-rw-r--r--source/blender/editors/space_text/space_text.c7
-rw-r--r--source/blender/editors/space_text/text_intern.h3
-rw-r--r--source/blender/editors/space_text/text_ops.c58
3 files changed, 67 insertions, 1 deletions
diff --git a/source/blender/editors/space_text/space_text.c b/source/blender/editors/space_text/space_text.c
index 032cc4ecbf2..ddff1fe603f 100644
--- a/source/blender/editors/space_text/space_text.c
+++ b/source/blender/editors/space_text/space_text.c
@@ -202,6 +202,9 @@ static void text_operatortypes(void)
WM_operatortype_append(TEXT_OT_select_line);
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_jump);
WM_operatortype_append(TEXT_OT_move);
@@ -321,7 +324,9 @@ static void text_keymap(struct wmKeyConfig *keyconf)
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);
+
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);
WM_keymap_add_item(keymap, "TEXT_OT_uncomment", DKEY, KM_PRESS, KM_CTRL | KM_SHIFT, 0);
diff --git a/source/blender/editors/space_text/text_intern.h b/source/blender/editors/space_text/text_intern.h
index 07d2dffb95b..be6287a939c 100644
--- a/source/blender/editors/space_text/text_intern.h
+++ b/source/blender/editors/space_text/text_intern.h
@@ -137,6 +137,9 @@ 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_jump(struct wmOperatorType *ot);
void TEXT_OT_move(struct wmOperatorType *ot);
void TEXT_OT_move_select(struct wmOperatorType *ot);
diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c
index f60217ba8ac..cb8daa0f03e 100644
--- a/source/blender/editors/space_text/text_ops.c
+++ b/source/blender/editors/space_text/text_ops.c
@@ -1331,6 +1331,64 @@ void TEXT_OT_select_word(wmOperatorType *ot)
ot->poll = text_edit_poll;
}
+/********************* move lines operators ***********************/
+
+static int move_lines_up_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ Text *text = CTX_data_edit_text(C);
+
+ txt_move_lines_up(text);
+
+ 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;
+}
+
+void TEXT_OT_move_lines_up(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);
+
+ /* 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.";
+
+ /* api callbacks */
+ ot->exec = move_lines_down_exec;
+ ot->poll = text_edit_poll;
+}
+
/******************* previous marker operator *********************/
static int text_previous_marker_exec(bContext *C, wmOperator *UNUSED(op))