[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [53472] trunk/blender/source/blender/ editors/space_text: syntax highlight autocomplete listing.

Campbell Barton ideasman42 at gmail.com
Mon Dec 31 17:40:18 CET 2012


Revision: 53472
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53472
Author:   campbellbarton
Date:     2012-12-31 16:40:14 +0000 (Mon, 31 Dec 2012)
Log Message:
-----------
syntax highlight autocomplete listing.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/space_text/text_autocomplete.c
    trunk/blender/source/blender/editors/space_text/text_draw.c
    trunk/blender/source/blender/editors/space_text/text_format.h
    trunk/blender/source/blender/editors/space_text/text_format_osl.c
    trunk/blender/source/blender/editors/space_text/text_format_py.c

Modified: trunk/blender/source/blender/editors/space_text/text_autocomplete.c
===================================================================
--- trunk/blender/source/blender/editors/space_text/text_autocomplete.c	2012-12-31 16:24:49 UTC (rev 53471)
+++ trunk/blender/source/blender/editors/space_text/text_autocomplete.c	2012-12-31 16:40:14 UTC (rev 53472)
@@ -50,6 +50,7 @@
 #include "ED_screen.h"
 #include "UI_interface.h"
 
+#include "text_format.h"
 #include "text_intern.h"  /* own include */
 
 
@@ -199,9 +200,13 @@
 		{
 			GHashIterator *iter = BLI_ghashIterator_new(gh);
 
+			/* get the formatter for highlighting */
+			TextFormatType *tft;
+			tft = ED_text_format_get(text);
+
 			for (; !BLI_ghashIterator_isDone(iter); BLI_ghashIterator_step(iter)) {
 				const char *s = BLI_ghashIterator_getValue(iter);
-				texttool_suggest_add(s, 'k');
+				texttool_suggest_add(s, tft->format_identifier(s));
 			}
 			BLI_ghashIterator_free(iter);
 

Modified: trunk/blender/source/blender/editors/space_text/text_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_text/text_draw.c	2012-12-31 16:24:49 UTC (rev 53471)
+++ trunk/blender/source/blender/editors/space_text/text_draw.c	2012-12-31 16:40:14 UTC (rev 53472)
@@ -957,7 +957,7 @@
 	SuggItem *item, *first, *last, *sel;
 	TextLine *tmp;
 	char str[SUGG_LIST_WIDTH + 1];
-	int w, boxw = 0, boxh, i, l, x, y, b, *top;
+	int w, boxw = 0, boxh, i, l, x, y, *top;
 	const int lheight = st->lheight_dpi + TXT_LINE_SPACING;
 	const int margin_x = 2;
 	
@@ -1014,18 +1014,8 @@
 			UI_ThemeColor(TH_SHADE2);
 			glRecti(x + margin_x, y - 3, x + margin_x + w, y + lheight - 3);
 		}
-		b = 1; /* b=1 color block, text is default. b=0 no block, color text */
-		switch (item->type) {
-			case 'k': UI_ThemeColor(TH_SYNTAX_B); b = 0; break;
-			case 'm': UI_ThemeColor(TH_TEXT); break;
-			case 'f': UI_ThemeColor(TH_SYNTAX_L); break;
-			case 'v': UI_ThemeColor(TH_SYNTAX_N); break;
-			case '?': UI_ThemeColor(TH_TEXT); b = 0; break;
-		}
-		if (b) {
-			glRecti(x + 8, y + 2, x + 11, y + 5);
-			UI_ThemeColor(TH_TEXT);
-		}
+
+		format_draw_color(item->type);
 		text_draw(st, str, 0, 0, 1, x + margin_x, y - 1, NULL);
 
 		if (item == last) break;

Modified: trunk/blender/source/blender/editors/space_text/text_format.h
===================================================================
--- trunk/blender/source/blender/editors/space_text/text_format.h	2012-12-31 16:24:49 UTC (rev 53471)
+++ trunk/blender/source/blender/editors/space_text/text_format.h	2012-12-31 16:40:14 UTC (rev 53472)
@@ -66,6 +66,8 @@
 typedef struct TextFormatType {
 	struct TextFormatType *next, *prev;
 
+	char (*format_identifier)(const char *string);
+
 	/* Formats the specified line. If do_next is set, the process will move on to
 	 * the succeeding line if it is affected (eg. multiline strings). Format strings
 	 * may contain any of the following characters:

Modified: trunk/blender/source/blender/editors/space_text/text_format_osl.c
===================================================================
--- trunk/blender/source/blender/editors/space_text/text_format_osl.c	2012-12-31 16:24:49 UTC (rev 53471)
+++ trunk/blender/source/blender/editors/space_text/text_format_osl.c	2012-12-31 16:40:14 UTC (rev 53472)
@@ -170,6 +170,17 @@
 	return -1;
 }
 
+static char txtfmt_osl_format_identifier(const char *str)
+{
+	char fmt;
+	if      ((txtfmt_osl_find_specialvar(str))   != -1) fmt = FMT_TYPE_SPECIAL;
+	else if ((txtfmt_osl_find_builtinfunc(str))  != -1) fmt = FMT_TYPE_KEYWORD;
+	else if ((txtfmt_osl_find_reserved(str))     != -1) fmt = FMT_TYPE_RESERVED;
+	else if ((txtfmt_osl_find_preprocessor(str)) != -1) fmt = FMT_TYPE_DIRECTIVE;
+	else                                                fmt = FMT_TYPE_DEFAULT;
+	return fmt;
+}
+
 static void txtfmt_osl_format_line(SpaceText *st, TextLine *line, const int do_next)
 {
 	FlattenString fs;
@@ -280,6 +291,7 @@
 			/* Not ws, a digit, punct, or continuing text. Must be new, check for special words */
 			else {
 				/* Special vars(v) or built-in keywords(b) */
+				/* keep in sync with 'txtfmt_osl_format_identifier()' */
 				if      ((i = txtfmt_osl_find_specialvar(str))   != -1) prev = FMT_TYPE_SPECIAL;
 				else if ((i = txtfmt_osl_find_builtinfunc(str))  != -1) prev = FMT_TYPE_KEYWORD;
 				else if ((i = txtfmt_osl_find_reserved(str))     != -1) prev = FMT_TYPE_RESERVED;
@@ -315,7 +327,8 @@
 	static TextFormatType tft = {0};
 	static const char *ext[] = {"osl", NULL};
 
-	tft.format_line = txtfmt_osl_format_line;
+	tft.format_identifier = txtfmt_osl_format_identifier;
+	tft.format_line       = txtfmt_osl_format_line;
 	tft.ext = ext;
 
 	ED_text_format_register(&tft);

Modified: trunk/blender/source/blender/editors/space_text/text_format_py.c
===================================================================
--- trunk/blender/source/blender/editors/space_text/text_format_py.c	2012-12-31 16:24:49 UTC (rev 53471)
+++ trunk/blender/source/blender/editors/space_text/text_format_py.c	2012-12-31 16:40:14 UTC (rev 53472)
@@ -154,6 +154,16 @@
 	return i;
 }
 
+static char txtfmt_py_format_identifier(const char *str)
+{
+	char fmt;
+	if      ((txtfmt_py_find_specialvar(str))   != -1) fmt = FMT_TYPE_SPECIAL;
+	else if ((txtfmt_py_find_builtinfunc(str))  != -1) fmt = FMT_TYPE_KEYWORD;
+	else if ((txtfmt_py_find_decorator(str))    != -1) fmt = FMT_TYPE_RESERVED;
+	else                                               fmt = FMT_TYPE_DEFAULT;
+	return fmt;
+}
+
 static void txtfmt_py_format_line(SpaceText *st, TextLine *line, const int do_next)
 {
 	FlattenString fs;
@@ -269,6 +279,7 @@
 			/* Not ws, a digit, punct, or continuing text. Must be new, check for special words */
 			else {
 				/* Special vars(v) or built-in keywords(b) */
+				/* keep in sync with 'txtfmt_py_format_identifier()' */
 				if      ((i = txtfmt_py_find_specialvar(str))   != -1) prev = FMT_TYPE_SPECIAL;
 				else if ((i = txtfmt_py_find_builtinfunc(str))  != -1) prev = FMT_TYPE_KEYWORD;
 				else if ((i = txtfmt_py_find_decorator(str))    != -1) prev = FMT_TYPE_DIRECTIVE;
@@ -303,7 +314,8 @@
 	static TextFormatType tft = {0};
 	static const char *ext[] = {"py", NULL};
 
-	tft.format_line = txtfmt_py_format_line;
+	tft.format_identifier = txtfmt_py_format_identifier;
+	tft.format_line       = txtfmt_py_format_line;
 	tft.ext = ext;
 
 	ED_text_format_register(&tft);




More information about the Bf-blender-cvs mailing list