Page Menu
Home
Search
Configure Global Search
Log In
Files
F20156
text_move_lines.diff
Public
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Authored By
Justin Dailey (dail)
Nov 13 2013, 4:23 PM
Size
7 KB
Subscribers
None
text_move_lines.diff
View Options
Index: release/scripts/startup/bl_ui/space_text.py
===================================================================
--- release/scripts/startup/bl_ui/space_text.py (revision 45114)
+++ release/scripts/startup/bl_ui/space_text.py (working copy)
@@ -276,6 +276,11 @@
layout.separator()
+ layout.operator("text.move_lines_up")
+ layout.operator("text.move_lines_down")
+
+ layout.separator()
+
layout.menu("TEXT_MT_edit_select")
layout.menu("TEXT_MT_edit_markers")
Index: source/blender/blenkernel/BKE_text.h
===================================================================
--- source/blender/blenkernel/BKE_text.h (revision 45114)
+++ source/blender/blenkernel/BKE_text.h (working copy)
@@ -96,6 +96,8 @@
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);
int setcurr_tab_spaces (struct Text *text, int space);
void txt_add_marker (struct Text *text, struct TextLine *line, int start, int end, const unsigned char color[4], int group, int flags);
@@ -169,6 +171,9 @@
#define UNDO_COMMENT 034
#define UNDO_UNCOMMENT 035
+#define UNDO_MOVE_LINES_UP 036
+#define UNDO_MOVE_LINES_DOWN 037
+
/* Marker flags */
#define TMARK_TEMP 0x01 /* Remove on non-editing events, don't save */
#define TMARK_EDITALL 0x02 /* Edit all markers of the same group as one */
Index: source/blender/blenkernel/intern/text.c
===================================================================
--- source/blender/blenkernel/intern/text.c (revision 45114)
+++ source/blender/blenkernel/intern/text.c (working copy)
@@ -1644,6 +1644,10 @@
ops= "Comment ";
} else if (op==UNDO_UNCOMMENT) {
ops= "Uncomment ";
+ } else if (op==UNDO_MOVE_LINES_UP) {
+ ops= "Move lines up ";
+ } else if (op==UNDO_MOVE_LINES_DOWN) {
+ ops= "Move lines down ";
} else {
ops= "Unknown";
}
@@ -2155,6 +2159,12 @@
text->undo_pos--;
break;
+ case UNDO_MOVE_LINES_UP:
+ txt_move_lines_down(text);
+ break;
+ case UNDO_MOVE_LINES_DOWN:
+ txt_move_lines_up(text);
+ break;
default:
//XXX error("Undo buffer error - resetting");
text->undo_pos= -1;
@@ -2348,6 +2358,12 @@
txt_uncomment(text);
}
break;
+ case UNDO_MOVE_LINES_UP:
+ txt_move_lines_up(text);
+ break;
+ case UNDO_MOVE_LINES_DOWN:
+ txt_move_lines_down(text);
+ break;
default:
//XXX error("Undo buffer error - resetting");
text->undo_pos= -1;
@@ -2968,6 +2984,54 @@
}
}
+void txt_move_lines_up(struct Text *text)
+{
+ TextLine *prev_line;
+
+ if (!text || !text->curl || !text->sell) return;
+
+ txt_order_cursors(text);
+
+ if (!text->curl) return;
+
+ prev_line= text->curl->prev;
+
+ if(!prev_line) return;
+
+ BLI_remlink(&text->lines, prev_line);
+ BLI_insertlink(&text->lines, text->sell, prev_line);
+
+ if(!undoing)
+ {
+ txt_undo_add_op(text, UNDO_MOVE_LINES_UP);
+ }
+}
+
+void txt_move_lines_down(struct Text *text)
+{
+ TextLine *next_line;
+
+ if (!text || !text->curl || !text->sell) return;
+
+ txt_order_cursors(text);
+
+ next_line= text->sell->next;
+
+ if(!next_line) return;
+
+ BLI_remlink(&text->lines, next_line);
+
+ if(!text->curl->prev)
+ BLI_addhead(&text->lines, next_line);
+ else
+ BLI_insertlink(&text->lines, text->curl->prev, next_line);
+
+ if(!undoing)
+ {
+ txt_undo_add_op(text, UNDO_MOVE_LINES_DOWN);
+ }
+}
+
int setcurr_tab_spaces (Text *text, int space)
{
int i = 0;
Index: source/blender/editors/space_text/space_text.c
===================================================================
--- source/blender/editors/space_text/space_text.c (revision 45114)
+++ source/blender/editors/space_text/space_text.c (working copy)
@@ -201,6 +201,9 @@
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);
@@ -318,7 +321,9 @@
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);
Index: source/blender/editors/space_text/text_intern.h
===================================================================
--- source/blender/editors/space_text/text_intern.h (revision 45114)
+++ source/blender/editors/space_text/text_intern.h (working copy)
@@ -136,6 +136,9 @@
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);
Index: source/blender/editors/space_text/text_ops.c
===================================================================
--- source/blender/editors/space_text/text_ops.c (revision 45114)
+++ source/blender/editors/space_text/text_ops.c (working copy)
@@ -1300,6 +1300,64 @@
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))
File Metadata
Details
Mime Type
text/x-diff
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
21/ed/f73da24c70eef89b22e20ff9df0f
Event Timeline
Log In to Comment