From d191dec1d5a938c0d7d2950f5140a4811627602e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 31 Dec 2012 16:40:14 +0000 Subject: syntax highlight autocomplete listing. --- source/blender/editors/space_text/text_autocomplete.c | 7 ++++++- source/blender/editors/space_text/text_draw.c | 16 +++------------- source/blender/editors/space_text/text_format.h | 2 ++ source/blender/editors/space_text/text_format_osl.c | 15 ++++++++++++++- source/blender/editors/space_text/text_format_py.c | 14 +++++++++++++- 5 files changed, 38 insertions(+), 16 deletions(-) (limited to 'source/blender/editors/space_text') diff --git a/source/blender/editors/space_text/text_autocomplete.c b/source/blender/editors/space_text/text_autocomplete.c index 46e2f99d3fa..31f6d92988c 100644 --- a/source/blender/editors/space_text/text_autocomplete.c +++ b/source/blender/editors/space_text/text_autocomplete.c @@ -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 @@ static GHash *text_autocomplete_build(Text *text) { 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); diff --git a/source/blender/editors/space_text/text_draw.c b/source/blender/editors/space_text/text_draw.c index a26b4f56e02..c264368e714 100644 --- a/source/blender/editors/space_text/text_draw.c +++ b/source/blender/editors/space_text/text_draw.c @@ -957,7 +957,7 @@ static void draw_suggestion_list(SpaceText *st, ARegion *ar) 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 @@ static void draw_suggestion_list(SpaceText *st, ARegion *ar) 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; diff --git a/source/blender/editors/space_text/text_format.h b/source/blender/editors/space_text/text_format.h index 99cd20149cf..e593e41d42c 100644 --- a/source/blender/editors/space_text/text_format.h +++ b/source/blender/editors/space_text/text_format.h @@ -66,6 +66,8 @@ int text_check_format_len(TextLine *line, unsigned int len); 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: diff --git a/source/blender/editors/space_text/text_format_osl.c b/source/blender/editors/space_text/text_format_osl.c index f313e9a5f2a..3120e88163e 100644 --- a/source/blender/editors/space_text/text_format_osl.c +++ b/source/blender/editors/space_text/text_format_osl.c @@ -170,6 +170,17 @@ static int txtfmt_osl_find_preprocessor(const char *string) 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 @@ static void txtfmt_osl_format_line(SpaceText *st, TextLine *line, const int do_n /* 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 @@ void ED_text_format_register_osl(void) 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); diff --git a/source/blender/editors/space_text/text_format_py.c b/source/blender/editors/space_text/text_format_py.c index d68d6ae0e78..cbccc6a770f 100644 --- a/source/blender/editors/space_text/text_format_py.c +++ b/source/blender/editors/space_text/text_format_py.c @@ -154,6 +154,16 @@ static int txtfmt_py_find_bool(const char *string) 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 @@ static void txtfmt_py_format_line(SpaceText *st, TextLine *line, const int do_ne /* 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 @@ void ED_text_format_register_py(void) 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); -- cgit v1.2.3