forked from bartvdbraak/blender
syntax highlight autocomplete listing.
This commit is contained in:
parent
dd62a2c375
commit
d191dec1d5
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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:
|
||||
|
@ -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,6 +327,7 @@ void ED_text_format_register_osl(void)
|
||||
static TextFormatType tft = {0};
|
||||
static const char *ext[] = {"osl", NULL};
|
||||
|
||||
tft.format_identifier = txtfmt_osl_format_identifier;
|
||||
tft.format_line = txtfmt_osl_format_line;
|
||||
tft.ext = ext;
|
||||
|
||||
|
@ -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,6 +314,7 @@ void ED_text_format_register_py(void)
|
||||
static TextFormatType tft = {0};
|
||||
static const char *ext[] = {"py", NULL};
|
||||
|
||||
tft.format_identifier = txtfmt_py_format_identifier;
|
||||
tft.format_line = txtfmt_py_format_line;
|
||||
tft.ext = ext;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user