From 08db61d4e360084fcfdac02a408c066c426ffa43 Mon Sep 17 00:00:00 2001 From: cxl Date: Sat, 16 Nov 2013 12:12:16 +0000 Subject: [PATCH] ide: json highlighting improved #558 git-svn-id: svn://ultimatepp.org/upp/trunk@6565 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/CodeEditor/CodeEditor.cpp | 1 - uppsrc/CodeEditor/CodeEditor.h | 2 +- uppsrc/CodeEditor/Highlight.cpp | 30 +++++++++++++++++------------- uppsrc/ide/Common/ComDlg.cpp | 2 +- uppsrc/ide/idefile.cpp | 5 ++++- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/uppsrc/CodeEditor/CodeEditor.cpp b/uppsrc/CodeEditor/CodeEditor.cpp index 1caa07b7c..44f228225 100644 --- a/uppsrc/CodeEditor/CodeEditor.cpp +++ b/uppsrc/CodeEditor/CodeEditor.cpp @@ -1208,4 +1208,3 @@ CodeEditor::CodeEditor() { CodeEditor::~CodeEditor() {} END_UPP_NAMESPACE - diff --git a/uppsrc/CodeEditor/CodeEditor.h b/uppsrc/CodeEditor/CodeEditor.h index 7e406fd37..86b8a7626 100644 --- a/uppsrc/CodeEditor/CodeEditor.h +++ b/uppsrc/CodeEditor/CodeEditor.h @@ -185,7 +185,7 @@ public: enum { HIGHLIGHT_NONE = -1, HIGHLIGHT_CPP = 0, HIGHLIGHT_USC, HIGHLIGHT_JAVA, HIGHLIGHT_T, HIGHLIGHT_CALC, HIGHLIGHT_LAY, HIGHLIGHT_SCH, HIGHLIGHT_SQL, HIGHLIGHT_CS, - HIGHLIGHT_JAVASCRIPT, HIGHLIGHT_CSS, + HIGHLIGHT_JAVASCRIPT, HIGHLIGHT_CSS, HIGHLIGHT_JSON, HIGHLIGHT_COUNT }; diff --git a/uppsrc/CodeEditor/Highlight.cpp b/uppsrc/CodeEditor/Highlight.cpp index a24f69422..63e2eceee 100644 --- a/uppsrc/CodeEditor/Highlight.cpp +++ b/uppsrc/CodeEditor/Highlight.cpp @@ -497,22 +497,26 @@ void CodeEditor::InitKeywords() "SELECT", "TABLE", NULL }; - static const char *javan[] = { + static const char *empty[] = { NULL }; static const char *javascriptn[] = { "alert", "eval", "toString", "valueOf", "length", NULL }; - static const char **kw[HIGHLIGHT_COUNT] = { - cpp, usc, java, tfile, usc, lay, sch, sql, cs, javascript, css, - }; - static const char **nm[HIGHLIGHT_COUNT] = { - upp, usclib, javan, tlng, usclib, javan, javan, javan, javan, javascriptn, cssn - }; - for(int i = 0; i < HIGHLIGHT_COUNT; i++) - LoadSyntax(kw[i], nm[i]); + LoadSyntax(cpp, upp); // Order here is important, must be the same as enum + LoadSyntax(usc, usclib); + LoadSyntax(java, empty); + LoadSyntax(tfile, tlng); + LoadSyntax(usc, usclib); + LoadSyntax(lay, empty); + LoadSyntax(sch, empty); + LoadSyntax(sql, empty); + LoadSyntax(cs, empty); + LoadSyntax(javascript, javascriptn); + LoadSyntax(css, cssn); + LoadSyntax(empty, empty); kw_macros = InitUpp(upp_macros); kw_logs = InitUpp(upp_logs); @@ -581,7 +585,7 @@ void CodeEditor::HighlightLine(int line, Vector& hl, int po p++; hls.Put(hl_style[INK_NORMAL]); } - if(*p == '#' && highlight != HIGHLIGHT_JAVASCRIPT && highlight != HIGHLIGHT_CSS) { + if(*p == '#' && findarg(highlight, HIGHLIGHT_JAVASCRIPT, HIGHLIGHT_CSS, HIGHLIGHT_JSON) < 0) { static const char *pd[] = { "define", "error", "if", "elif", "else", "endif", "ifdef", "ifndef", "include", "line", "undef", "pragma", @@ -610,13 +614,13 @@ void CodeEditor::HighlightLine(int line, Vector& hl, int po bool is_comment = false; while(p < e) { int pair = MAKELONG(p[0], p[1]); - if(ss.linecomment && ss.linecont || pair == MAKELONG('/', '/') && highlight != HIGHLIGHT_CSS) { + if(ss.linecomment && ss.linecont || pair == MAKELONG('/', '/') && highlight != HIGHLIGHT_CSS && highlight != HIGHLIGHT_JSON) { hls.Put(text.GetLength() + 1 - hls.pos, hl_style[INK_COMMENT]); is_comment = true; break; } else - if(ss.comment) + if(ss.comment && highlight != HIGHLIGHT_JSON) if(pair == MAKELONG('*', '/')) { hls.Put(2, hl_style[INK_COMMENT]); p += 2; @@ -630,7 +634,7 @@ void CodeEditor::HighlightLine(int line, Vector& hl, int po if((*p == '\"' || *p == '\'') || ss.linecont && ss.string) p = HlString(hls, p); else - if(pair == MAKELONG('/', '*')) { + if(pair == MAKELONG('/', '*') && highlight != HIGHLIGHT_JSON) { hls.Put(2, hl_style[INK_COMMENT]); p += 2; ss.comment = true; diff --git a/uppsrc/ide/Common/ComDlg.cpp b/uppsrc/ide/Common/ComDlg.cpp index 47c96b7b9..fe367f682 100644 --- a/uppsrc/ide/Common/ComDlg.cpp +++ b/uppsrc/ide/Common/ComDlg.cpp @@ -111,7 +111,7 @@ void SourceFs(FileSel& fs) { fs.Type("Language files (*.lng)", "*.lng"); fs.Type("Web development files (*.html *.js *.css *.witz)", "*.html *.js *.css *.witz"); fs.Type("Other special files (*.sch *.usc *.rc *.brc *.upt)", "*.sch *.usc *.rc *.brc *.upt"); - String mask = "*.cpp *.h *.hpp *.c *.C *.cc *.cxx *.icpp *.lay *.iml *.lng *.sch *.usc *.rc *.brc *.upt *.html *.js *.css *.witz"; + String mask = "*.cpp *.h *.hpp *.c *.C *.cc *.cxx *.icpp *.lay *.iml *.lng *.sch *.usc *.rc *.brc *.upt *.html *.js *.css *.witz *.json *.xml"; fs.Type("All source files (" + mask + ")", mask); IdeFs(fs); } diff --git a/uppsrc/ide/idefile.cpp b/uppsrc/ide/idefile.cpp index 395138978..c36dffb86 100644 --- a/uppsrc/ide/idefile.cpp +++ b/uppsrc/ide/idefile.cpp @@ -12,7 +12,7 @@ void Ide::SetupEditor(int f, String hl, String fn) } if(IsNull(hl) && *ext == '.') hl = ext.Mid(1); - if(findarg(hl, "c", "cpp", "cc", "cxx", "h", "hpp", "hh", "hxx", "m", "mm", "icpp", "conf", "json") >= 0) + if(findarg(hl, "c", "cpp", "cc", "cxx", "h", "hpp", "hh", "hxx", "m", "mm", "icpp", "conf") >= 0) editor.Highlight(CodeEditor::HIGHLIGHT_CPP); else if(hl == "cs") @@ -30,6 +30,9 @@ void Ide::SetupEditor(int f, String hl, String fn) if(hl == "css") editor.Highlight(CodeEditor::HIGHLIGHT_CSS); else + if(hl == "json") + editor.Highlight(CodeEditor::HIGHLIGHT_JSON); + else if(hl == "t" || hl == "jt") editor.Highlight(CodeEditor::HIGHLIGHT_T); else