[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47391] trunk/blender: patch [#31644] Py Console: Indent and unindent independent of cursor (aligned) [Tab / Shift + Tab / Ctrl + Tab]

Campbell Barton ideasman42 at gmail.com
Mon Jun 4 09:24:23 CEST 2012


Revision: 47391
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47391
Author:   campbellbarton
Date:     2012-06-04 07:24:19 +0000 (Mon, 04 Jun 2012)
Log Message:
-----------
patch [#31644] Py Console: Indent and unindent independent of cursor (aligned) [Tab / Shift + Tab / Ctrl + Tab]
from Sebastian Nell (codemanx)

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_ui/space_console.py
    trunk/blender/source/blender/editors/space_console/console_intern.h
    trunk/blender/source/blender/editors/space_console/console_ops.c
    trunk/blender/source/blender/editors/space_console/space_console.c

Modified: trunk/blender/release/scripts/startup/bl_ui/space_console.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/space_console.py	2012-06-04 01:17:37 UTC (rev 47390)
+++ trunk/blender/release/scripts/startup/bl_ui/space_console.py	2012-06-04 07:24:19 UTC (rev 47391)
@@ -41,8 +41,16 @@
     def draw(self, context):
         layout = self.layout
 
+        layout.operator("console.indent")
+        layout.operator("console.unindent")
+
+        layout.separator()
+
         layout.operator("console.clear")
         layout.operator("console.clear_line")
+
+        layout.separator()
+
         layout.operator("console.copy")
         layout.operator("console.paste")
         layout.menu("CONSOLE_MT_language")

Modified: trunk/blender/source/blender/editors/space_console/console_intern.h
===================================================================
--- trunk/blender/source/blender/editors/space_console/console_intern.h	2012-06-04 01:17:37 UTC (rev 47390)
+++ trunk/blender/source/blender/editors/space_console/console_intern.h	2012-06-04 07:24:19 UTC (rev 47391)
@@ -54,6 +54,9 @@
 void CONSOLE_OT_delete(struct wmOperatorType *ot);
 void CONSOLE_OT_insert(struct wmOperatorType *ot);
 
+void CONSOLE_OT_indent(struct wmOperatorType *ot);
+void CONSOLE_OT_unindent(struct wmOperatorType *ot);
+
 void CONSOLE_OT_history_append(struct wmOperatorType *ot);
 void CONSOLE_OT_scrollback_append(struct wmOperatorType *ot);
 

Modified: trunk/blender/source/blender/editors/space_console/console_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_console/console_ops.c	2012-06-04 01:17:37 UTC (rev 47390)
+++ trunk/blender/source/blender/editors/space_console/console_ops.c	2012-06-04 07:24:19 UTC (rev 47391)
@@ -364,9 +364,8 @@
 	char *str = RNA_string_get_alloc(op->ptr, "text", NULL, 0);
 	int len;
 
-	// XXX, alligned tab key hack
 	if (str[0] == '\t' && str[1] == '\0') {
-		len = TAB_LENGTH - (ci->cursor % TAB_LENGTH);
+		len = TAB_LENGTH;
 		MEM_freeN(str);
 		str = MEM_mallocN(len + 1, "insert_exec");
 		memset(str, ' ', len);
@@ -430,7 +429,96 @@
 	RNA_def_property_flag(prop, PROP_SKIP_SAVE);
 }
 
+static int console_indent_exec(bContext *C, wmOperator *op)
+{
+	SpaceConsole *sc = CTX_wm_space_console(C);
+	ARegion *ar = CTX_wm_region(C);
+	ConsoleLine *ci = console_history_verify(C);
+	int spaces;
+	int len;
 
+	for (spaces = 0; spaces < ci->len; spaces++) {
+		if (ci->line[spaces] != ' ')
+			break;
+	}
+
+	len = TAB_LENGTH - spaces % TAB_LENGTH;
+
+	console_line_verify_length(ci, ci->len + len);
+
+	memmove(ci->line + len, ci->line, ci->len);
+	memset(ci->line, ' ', len);
+	ci->len += len;
+	console_line_cursor_set(ci, ci->cursor + len);
+
+	console_textview_update_rect(sc, ar);
+	ED_area_tag_redraw(CTX_wm_area(C));
+
+	console_scroll_bottom(ar);
+
+	return OPERATOR_FINISHED;
+}
+
+void CONSOLE_OT_indent(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Indent";
+	ot->description = "Add 4 spaces at line beginning";
+	ot->idname = "CONSOLE_OT_indent";
+
+	/* api callbacks */
+	ot->exec = console_indent_exec;
+	ot->poll = ED_operator_console_active;
+}
+
+static int console_unindent_exec(bContext *C, wmOperator *op)
+{
+	SpaceConsole *sc = CTX_wm_space_console(C);
+	ARegion *ar = CTX_wm_region(C);
+	ConsoleLine *ci = console_history_verify(C);
+	int spaces;
+	int len;
+
+	for (spaces = 0; spaces < ci->len; spaces++) {
+		if (ci->line[spaces] != ' ')
+			break;
+	}
+
+	if (spaces == 0)
+		return OPERATOR_CANCELLED;
+
+	len = spaces % TAB_LENGTH;
+	if (len == 0)
+		len = TAB_LENGTH;
+
+	console_line_verify_length(ci, ci->len - len);
+
+	memmove(ci->line, ci->line + len, (ci->len - len) + 1);
+	ci->len -= len;
+	console_line_cursor_set(ci, ci->cursor - len);
+
+	//console_select_offset(sc, -4);
+
+	console_textview_update_rect(sc, ar);
+	ED_area_tag_redraw(CTX_wm_area(C));
+
+	console_scroll_bottom(ar);
+
+	return OPERATOR_FINISHED;
+}
+
+void CONSOLE_OT_unindent(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Unindent";
+	ot->description = "Delete 4 spaces from line beginning";
+	ot->idname = "CONSOLE_OT_unindent";
+
+	/* api callbacks */
+	ot->exec = console_unindent_exec;
+	ot->poll = ED_operator_console_active;
+}
+
 static EnumPropertyItem console_delete_type_items[] = {
 	{DEL_NEXT_CHAR, "NEXT_CHARACTER", 0, "Next Character", ""},
 	{DEL_PREV_CHAR, "PREVIOUS_CHARACTER", 0, "Previous Character", ""},
@@ -757,7 +845,8 @@
 		{CONSOLE_LINE_INPUT,    "INPUT", 0, "Input", ""},
 		{CONSOLE_LINE_INFO,     "INFO", 0, "Information", ""},
 		{CONSOLE_LINE_ERROR,    "ERROR", 0, "Error", ""},
-		{0, NULL, 0, NULL, NULL}};
+		{0, NULL, 0, NULL, NULL}
+	};
 
 	/* identifiers */
 	ot->name = "Scrollback Append";

Modified: trunk/blender/source/blender/editors/space_console/space_console.c
===================================================================
--- trunk/blender/source/blender/editors/space_console/space_console.c	2012-06-04 01:17:37 UTC (rev 47390)
+++ trunk/blender/source/blender/editors/space_console/space_console.c	2012-06-04 07:24:19 UTC (rev 47391)
@@ -246,6 +246,9 @@
 	WM_operatortype_append(CONSOLE_OT_move);
 	WM_operatortype_append(CONSOLE_OT_delete);
 	WM_operatortype_append(CONSOLE_OT_insert);
+
+	WM_operatortype_append(CONSOLE_OT_indent);
+	WM_operatortype_append(CONSOLE_OT_unindent);
 	
 	/* for use by python only */
 	WM_operatortype_append(CONSOLE_OT_history_append); 
@@ -332,7 +335,11 @@
 	
 	WM_keymap_add_item(keymap, "CONSOLE_OT_select_set", LEFTMOUSE, KM_PRESS, 0, 0);
 
-	RNA_string_set(WM_keymap_add_item(keymap, "CONSOLE_OT_insert", TABKEY, KM_PRESS, 0, 0)->ptr, "text", "\t"); /* fake tabs */
+	RNA_string_set(WM_keymap_add_item(keymap, "CONSOLE_OT_insert", TABKEY, KM_PRESS, KM_CTRL, 0)->ptr, "text", "\t"); /* fake tabs */
+
+	WM_keymap_add_item(keymap, "CONSOLE_OT_indent", TABKEY, KM_PRESS, 0, 0);
+	WM_keymap_add_item(keymap, "CONSOLE_OT_unindent", TABKEY, KM_PRESS, KM_SHIFT, 0);
+
 	WM_keymap_add_item(keymap, "CONSOLE_OT_insert", KM_TEXTINPUT, KM_ANY, KM_ANY, 0); // last!
 }
 




More information about the Bf-blender-cvs mailing list