diff --git a/SynNotes/Form.cs b/SynNotes/Form.cs index 2e10aa0..3fd2487 100644 --- a/SynNotes/Form.cs +++ b/SynNotes/Form.cs @@ -35,6 +35,7 @@ public partial class Form1 : Form { TagItem tagDeleted; // pointer to DELETED tag TagItem tagAll; // pointer to ALL tag Dictionary> lexers = new Dictionary>(StringComparer.InvariantCultureIgnoreCase); + Dictionary> keywords = new Dictionary>(StringComparer.InvariantCultureIgnoreCase); public static Timer saveTimer; // autosave public static System.Timers.Timer syncTimer; // auto-sync int treeTopLine, treeSelLine; // used to restore tree position after restore of window @@ -1214,6 +1215,7 @@ private void lexClick(object sender, EventArgs e) { private void initScintilla() { //read theme file var file = ini.GetValue("Scintilla", "Theme", "Visual Studio.xml"); + readKeywords(); readTheme(file); //smart highlight scEdit.Indicators[0].Style = IndicatorStyle.RoundBox; @@ -1240,7 +1242,47 @@ private void initScintilla() { else scEdit.Caret.HighlightCurrentLine = false; } - //fills lexers dic with styles + //fills in keywords dic + private void readKeywords() { + var fn="themes\\langs.model.xml"; + if(!File.Exists(fn)) return; + + string _readTo = ""; + var s = new XmlReaderSettings(); + s.IgnoreComments = true; + s.IgnoreWhitespace = true; + try { + var reader = XmlReader.Create(fn, s); + reader.ReadStartElement(); + while (!reader.EOF) { + //read lang + if (reader.Name.Equals("Language", StringComparison.OrdinalIgnoreCase) && !reader.IsEmptyElement && reader.HasAttributes) { + _readTo = ""; + while (reader.MoveToNextAttribute()) { + if (reader.Name.Equals("name", StringComparison.OrdinalIgnoreCase)) { + if (Glob.Lexers.Contains(reader.Value, StringComparer.OrdinalIgnoreCase)) _readTo = reader.Value.ToLower(); + break; + } + } + if (!String.IsNullOrEmpty(_readTo)) while (!(reader.NodeType == XmlNodeType.EndElement && reader.Name.Equals("Language", StringComparison.OrdinalIgnoreCase))) { + if (reader.NodeType == XmlNodeType.Element && reader.Name.Equals("Keywords", StringComparison.OrdinalIgnoreCase) ) { + if (!keywords.ContainsKey(_readTo)) keywords.Add(_readTo, new List()); + keywords[_readTo].Add(reader.ReadElementContentAsString()); + } + else reader.Read(); + } + } + reader.Read(); + } + reader.Close(); + } + catch (Exception e) { + MessageBox.Show("Error reading keywords file: '" + fn + "'\n" + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + + //fills in lexers dic with styles private void readTheme(string file) { string _readTo = ""; var s = new XmlReaderSettings(); diff --git a/SynNotes/Note.cs b/SynNotes/Note.cs index 606afb7..4d41ef9 100644 --- a/SynNotes/Note.cs +++ b/SynNotes/Note.cs @@ -85,6 +85,7 @@ public void ShowSelected() { /// set scintilla lexer and styles /// public void SetLanguage(string lang) { + f.scEdit.Styles.ResetDefault(); foreach (var s in f.lexers["globals"]) { if (s.id != 0) { f.scEdit.Styles[s.id].ForeColor = s.fgcolor; @@ -96,10 +97,11 @@ public void SetLanguage(string lang) { f.scEdit.Styles[s.id].Underline = s.underline; } } - f.scEdit.Styles.ClearAll(); + f.scEdit.Styles.ClearAll(); // i.e. Apply to all f.scEdit.Lexing.LexerName = lang; - if (Glob.Lexers.Contains(lang) && f.lexers.ContainsKey(lang)) { - foreach (var s in f.lexers[lang]) { + if (Glob.Lexers.Contains(lang)) { + //styles + if(f.lexers.ContainsKey(lang)) foreach (var s in f.lexers[lang]) { if (s.id != 0) { f.scEdit.Styles[s.id].ForeColor = s.fgcolor; f.scEdit.Styles[s.id].BackColor = s.bgcolor; @@ -110,6 +112,10 @@ public void SetLanguage(string lang) { f.scEdit.Styles[s.id].Underline = s.underline; } } + //keywords + if (f.keywords.ContainsKey(lang)) for (int i =0; i