[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31231] trunk/blender: small edits to text editor from writing a python editor extension.

Campbell Barton ideasman42 at gmail.com
Wed Aug 11 07:21:44 CEST 2010


Revision: 31231
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31231
Author:   campbellbarton
Date:     2010-08-11 07:21:43 +0200 (Wed, 11 Aug 2010)

Log Message:
-----------
small edits to text editor from writing a python editor extension.
- rename TextLine.line -> body, ConsoleLine.line -> body
- minor speedups when setting the body text, also re-allocate console lines if they are < half the length.
- added option to highlight current line in the text editor.

Modified Paths:
--------------
    trunk/blender/release/scripts/modules/bpy_types.py
    trunk/blender/release/scripts/op/console_python.py
    trunk/blender/release/scripts/op/console_shell.py
    trunk/blender/release/scripts/ui/space_text.py
    trunk/blender/source/blender/editors/space_image/image_ops.c
    trunk/blender/source/blender/editors/space_text/text_draw.c
    trunk/blender/source/blender/makesdna/DNA_space_types.h
    trunk/blender/source/blender/makesrna/intern/rna_space.c
    trunk/blender/source/blender/makesrna/intern/rna_text.c

Modified: trunk/blender/release/scripts/modules/bpy_types.py
===================================================================
--- trunk/blender/release/scripts/modules/bpy_types.py	2010-08-11 05:11:43 UTC (rev 31230)
+++ trunk/blender/release/scripts/modules/bpy_types.py	2010-08-11 05:21:43 UTC (rev 31231)
@@ -525,7 +525,7 @@
 
     def as_string(self):
         """Return the text as a string."""
-        return "\n".join(line.line for line in self.lines)
+        return "\n".join(line.body for line in self.lines)
 
     def from_string(self, string):
         """Replace text with this string."""

Modified: trunk/blender/release/scripts/op/console_python.py
===================================================================
--- trunk/blender/release/scripts/op/console_python.py	2010-08-11 05:11:43 UTC (rev 31230)
+++ trunk/blender/release/scripts/op/console_python.py	2010-08-11 05:21:43 UTC (rev 31231)
@@ -131,7 +131,7 @@
     is_multiline = False
 
     try:
-        line = line_object.line
+        line = line_object.body
 
         # run the console, "\n" executes a multiline statement
         line_exec = line if line.strip() else "\n"
@@ -212,13 +212,13 @@
 
     try:
         current_line = sc.history[-1]
-        line = current_line.line
+        line = current_line.body
 
         # This function isnt aware of the text editor or being an operator
         # just does the autocomp then copy its results back
-        current_line.line, current_line.current_character, scrollback = \
+        current_line.body, current_line.current_character, scrollback = \
             intellisense.expand(
-                line=current_line.line,
+                line=current_line.body,
                 cursor=current_line.current_character,
                 namespace=console.locals,
                 private=bpy.app.debug)
@@ -233,7 +233,7 @@
 
     # Separate automplete output by command prompts
     if scrollback != '':
-        bpy.ops.console.scrollback_append(text=sc.prompt + current_line.line, type='INPUT')
+        bpy.ops.console.scrollback_append(text=sc.prompt + current_line.body, type='INPUT')
 
     # Now we need to copy back the line from blender back into the
     # text editor. This will change when we dont use the text editor

Modified: trunk/blender/release/scripts/op/console_shell.py
===================================================================
--- trunk/blender/release/scripts/op/console_shell.py	2010-08-11 05:11:43 UTC (rev 31230)
+++ trunk/blender/release/scripts/op/console_shell.py	2010-08-11 05:21:43 UTC (rev 31231)
@@ -47,7 +47,7 @@
     sc = context.space_data
 
     try:
-        line = sc.history[-1].line
+        line = sc.history[-1].body
     except:
         return {'CANCELLED'}
 

Modified: trunk/blender/release/scripts/ui/space_text.py
===================================================================
--- trunk/blender/release/scripts/ui/space_text.py	2010-08-11 05:11:43 UTC (rev 31230)
+++ trunk/blender/release/scripts/ui/space_text.py	2010-08-11 05:21:43 UTC (rev 31231)
@@ -48,9 +48,9 @@
         layout.template_ID(st, "text", new="text.new", unlink="text.unlink")
 
         row = layout.row(align=True)
-        row.prop(st, "line_numbers", text="")
-        row.prop(st, "word_wrap", text="")
-        row.prop(st, "syntax_highlight", text="")
+        row.prop(st, "show_line_numbers", text="")
+        row.prop(st, "show_word_wrap", text="")
+        row.prop(st, "show_syntax_highlight", text="")
 
         if text:
             row = layout.row()
@@ -81,9 +81,10 @@
         st = context.space_data
 
         flow = layout.column_flow()
-        flow.prop(st, "line_numbers")
-        flow.prop(st, "word_wrap")
-        flow.prop(st, "syntax_highlight")
+        flow.prop(st, "show_line_numbers")
+        flow.prop(st, "show_word_wrap")
+        flow.prop(st, "show_syntax_highlight")
+        flow.prop(st, "show_line_highlight")
         flow.prop(st, "live_edit")
 
         flow = layout.column_flow()

Modified: trunk/blender/source/blender/editors/space_image/image_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_image/image_ops.c	2010-08-11 05:11:43 UTC (rev 31230)
+++ trunk/blender/source/blender/editors/space_image/image_ops.c	2010-08-11 05:21:43 UTC (rev 31231)
@@ -747,7 +747,6 @@
 	}
 
 	if (ima==NULL) {
-		 SpaceButs *sbuts= CTX_wm_space_buts(C);
 		 Tex *tex= CTX_data_pointer_get_type(C, "texture", &RNA_Texture).data;
 		 if(tex && tex->type==TEX_IMAGE)
 			 ima= tex->ima;

Modified: trunk/blender/source/blender/editors/space_text/text_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_text/text_draw.c	2010-08-11 05:11:43 UTC (rev 31230)
+++ trunk/blender/source/blender/editors/space_text/text_draw.c	2010-08-11 05:21:43 UTC (rev 31231)
@@ -1107,6 +1107,17 @@
 		x += vselc*st->cwidth;
 		y= ar->winy-2 - vsell*st->lheight;
 		
+		if(st->line_hlight) {
+			int x1= st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET;
+			int x2= x1 + ar->winx;
+			glColor4ub(255, 255, 255, 32);
+			
+			glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+			glEnable(GL_BLEND);
+			glRecti(x1, y, x2, y-st->lheight+1);
+			glDisable(GL_BLEND);
+		}
+		
 		if(st->overwrite) {
 			char ch= text->sell->line[text->selc];
 			if(!ch) ch= ' ';
@@ -1288,7 +1299,7 @@
 	}
 	y= ar->winy-st->lheight;
 	winx= ar->winx - TXT_SCROLL_WIDTH;
-
+	
 	/* draw cursor */
 	draw_cursor(st, ar);
 

Modified: trunk/blender/source/blender/makesdna/DNA_space_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_space_types.h	2010-08-11 05:11:43 UTC (rev 31230)
+++ trunk/blender/source/blender/makesdna/DNA_space_types.h	2010-08-11 05:21:43 UTC (rev 31231)
@@ -303,7 +303,8 @@
 	int showlinenrs;
 	int tabnumber;
 
-	int showsyntax;
+	short showsyntax;
+	short line_hlight;
 	short overwrite;
 	short live_edit; /* run python while editing, evil */
 	float pix_per_line;

Modified: trunk/blender/source/blender/makesrna/intern/rna_space.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_space.c	2010-08-11 05:11:43 UTC (rev 31230)
+++ trunk/blender/source/blender/makesrna/intern/rna_space.c	2010-08-11 05:21:43 UTC (rev 31231)
@@ -567,31 +567,30 @@
 }
 
 /* Space Console */
-static void rna_ConsoleLine_line_get(PointerRNA *ptr, char *value)
+static void rna_ConsoleLine_body_get(PointerRNA *ptr, char *value)
 {
 	ConsoleLine *ci= (ConsoleLine*)ptr->data;
 	strcpy(value, ci->line);
 }
 
-static int rna_ConsoleLine_line_length(PointerRNA *ptr)
+static int rna_ConsoleLine_body_length(PointerRNA *ptr)
 {
 	ConsoleLine *ci= (ConsoleLine*)ptr->data;
 	return ci->len;
 }
 
-static void rna_ConsoleLine_line_set(PointerRNA *ptr, const char *value)
+static void rna_ConsoleLine_body_set(PointerRNA *ptr, const char *value)
 {
 	ConsoleLine *ci= (ConsoleLine*)ptr->data;
 	int len= strlen(value);
 	
-	if(len < ci->len_alloc) { /* allocated size is enough? */
-		strcpy(ci->line, value);
-	}
-	else { /* allocate a new strnig */
+	if((len >= ci->len_alloc) || (len * 2 < ci->len_alloc) ) { /* allocate a new strnig */
 		MEM_freeN(ci->line);
-		ci->line= BLI_strdup(value);
-		ci->len_alloc= len;
+		ci->line= MEM_mallocN((len + 1) * sizeof(char), "rna_consoleline");
+		ci->len_alloc= len + 1;
 	}
+
+	memcpy(ci->line, value, len + 1);
 	ci->len= len;
 
 	if(ci->cursor > len) /* clamp the cursor */
@@ -1536,31 +1535,28 @@
 	RNA_def_property_update(prop, NC_SPACE|ND_SPACE_TEXT, NULL);
 
 	/* display */
-	prop= RNA_def_property(srna, "syntax_highlight", PROP_BOOLEAN, PROP_NONE);
-	RNA_def_property_boolean_sdna(prop, NULL, "showsyntax", 0);
-	RNA_def_property_ui_text(prop, "Syntax Highlight", "Syntax highlight for scripting");
-	RNA_def_property_ui_icon(prop, ICON_SYNTAX_OFF, 1);
-	RNA_def_property_update(prop, NC_SPACE|ND_SPACE_TEXT, NULL);
-
-	prop= RNA_def_property(srna, "word_wrap", PROP_BOOLEAN, PROP_NONE);
+	prop= RNA_def_property(srna, "show_word_wrap", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "wordwrap", 0);
 	RNA_def_property_boolean_funcs(prop, NULL, "rna_SpaceTextEditor_word_wrap_set");
 	RNA_def_property_ui_text(prop, "Word Wrap", "Wrap words if there is not enough horizontal space");
 	RNA_def_property_ui_icon(prop, ICON_WORDWRAP_OFF, 1);
 	RNA_def_property_update(prop, NC_SPACE|ND_SPACE_TEXT, NULL);
 
-	prop= RNA_def_property(srna, "line_numbers", PROP_BOOLEAN, PROP_NONE);
+	prop= RNA_def_property(srna, "show_line_numbers", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "showlinenrs", 0);
 	RNA_def_property_ui_text(prop, "Line Numbers", "Show line numbers next to the text");
 	RNA_def_property_ui_icon(prop, ICON_LINENUMBERS_OFF, 1);
 	RNA_def_property_update(prop, NC_SPACE|ND_SPACE_TEXT, NULL);
 
-	prop= RNA_def_property(srna, "overwrite", PROP_BOOLEAN, PROP_NONE);
-	RNA_def_property_ui_text(prop, "Overwrite", "Overwrite characters when typing rather than inserting them");
+	prop= RNA_def_property(srna, "show_syntax_highlight", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "showsyntax", 0);
+	RNA_def_property_ui_text(prop, "Syntax Highlight", "Syntax highlight for scripting");
+	RNA_def_property_ui_icon(prop, ICON_SYNTAX_OFF, 1);
 	RNA_def_property_update(prop, NC_SPACE|ND_SPACE_TEXT, NULL);
 	
-	prop= RNA_def_property(srna, "live_edit", PROP_BOOLEAN, PROP_NONE);
-	RNA_def_property_ui_text(prop, "Live Edit", "Run python while editing");
+	prop= RNA_def_property(srna, "show_line_highlight", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "line_hlight", 0);
+	RNA_def_property_ui_text(prop, "Highlight Line", "Highlight the current line");
 	RNA_def_property_update(prop, NC_SPACE|ND_SPACE_TEXT, NULL);
 
 	prop= RNA_def_property(srna, "tab_width", PROP_INT, PROP_NONE);
@@ -1575,6 +1571,15 @@
 	RNA_def_property_ui_text(prop, "Font Size", "Font size to use for displaying the text");
 	RNA_def_property_update(prop, NC_SPACE|ND_SPACE_TEXT, NULL);
 
+	/* functionality options */
+	prop= RNA_def_property(srna, "overwrite", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_ui_text(prop, "Overwrite", "Overwrite characters when typing rather than inserting them");
+	RNA_def_property_update(prop, NC_SPACE|ND_SPACE_TEXT, NULL);
+	

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list