[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [46286] trunk/blender/source/blender: make text move up/down into a single operator with a direction property

Campbell Barton ideasman42 at gmail.com
Fri May 4 18:17:14 CEST 2012


Revision: 46286
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=46286
Author:   campbellbarton
Date:     2012-05-04 16:17:09 +0000 (Fri, 04 May 2012)
Log Message:
-----------
make text move up/down into a single operator with a direction property

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_text.h
    trunk/blender/source/blender/blenkernel/intern/text.c
    trunk/blender/source/blender/editors/space_text/space_text.c
    trunk/blender/source/blender/editors/space_text/text_intern.h
    trunk/blender/source/blender/editors/space_text/text_ops.c

Modified: trunk/blender/source/blender/blenkernel/BKE_text.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_text.h	2012-05-04 15:42:49 UTC (rev 46285)
+++ trunk/blender/source/blender/blenkernel/BKE_text.h	2012-05-04 16:17:09 UTC (rev 46286)
@@ -96,8 +96,7 @@
 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,7 +115,12 @@
 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 */
 
 /* Simple main cursor movement */

Modified: trunk/blender/source/blender/blenkernel/intern/text.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/text.c	2012-05-04 15:42:49 UTC (rev 46285)
+++ trunk/blender/source/blender/blenkernel/intern/text.c	2012-05-04 16:17:09 UTC (rev 46286)
@@ -2201,10 +2201,10 @@
 			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 @@
 			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_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);
 	}
 }
 

Modified: trunk/blender/source/blender/editors/space_text/space_text.c
===================================================================
--- trunk/blender/source/blender/editors/space_text/space_text.c	2012-05-04 15:42:49 UTC (rev 46285)
+++ trunk/blender/source/blender/editors/space_text/space_text.c	2012-05-04 16:17:09 UTC (rev 46286)
@@ -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 @@
 	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,10 +323,10 @@
 	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);
+
+	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_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);

Modified: trunk/blender/source/blender/editors/space_text/text_intern.h
===================================================================
--- trunk/blender/source/blender/editors/space_text/text_intern.h	2012-05-04 15:42:49 UTC (rev 46285)
+++ trunk/blender/source/blender/editors/space_text/text_intern.h	2012-05-04 16:17:09 UTC (rev 46286)
@@ -137,8 +137,7 @@
 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);

Modified: trunk/blender/source/blender/editors/space_text/text_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_text/text_ops.c	2012-05-04 15:42:49 UTC (rev 46285)
+++ trunk/blender/source/blender/editors/space_text/text_ops.c	2012-05-04 16:17:09 UTC (rev 46286)
@@ -1333,11 +1333,12 @@
 
 /********************* 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,46 +1350,27 @@
 	return OPERATOR_FINISHED;
 }
 
-void TEXT_OT_move_lines_up(wmOperatorType *ot)
+void TEXT_OT_move_lines(wmOperatorType *ot)
 {
+	static EnumPropertyItem direction_items[]= {
+		{TXT_MOVE_LINE_UP, "UP", 0, "Up", ""},
+		{TXT_MOVE_LINE_DOWN, "DOWN", 0, "Down", ""},
+		{0, NULL, 0, NULL, NULL}
+	};
+
 	/* identifiers */
-	ot->name = "Move Lines Up";
-	ot->idname = "TEXT_OT_move_lines_up";
-	ot->description = "Moves the currently selected line(s) up.";
+	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_up_exec;
+	ot->exec = move_lines_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;
+	/* properties */
+	RNA_def_enum(ot->srna, "direction", direction_items, 1, "Direction", "");
 }
 
-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))




More information about the Bf-blender-cvs mailing list