Quantcast
Channel: SharpDevelop Community
Viewing all articles
Browse latest Browse all 1764

How do I add Keywords at runtime to main ruleset?

$
0
0

Hi,

I add a new Keywords object to the main rule set at run time. But except those keywords, other rules are colored properly.

Can anyone explain why words loaded at runtime don't get highlighted?


using (Stream stream = typeof(Window1).Assembly.GetManifestResourceStream("testAvalonEdit.MyLang.xshd")) {
if (stream == null) throw new InvalidOperationException("Could not find embedded resource");
using (XmlReader reader = new XmlTextReader(stream)) {
xshd = HighlightingLoader.LoadXshd(reader);
customHighlighting = HighlightingLoader.Load(xshd, HighlightingManager.Instance);
updateStandardParametersList();
}
}
HighlightingManager.Instance.RegisterHighlighting("MyLang Highlighting", new string[ { ".s" }, customHighlighting);

Where, the highlighted method is:

void updateStandardParametersList() {
//find existing color. It exists for sure.
XshdColor existingColor = xshd.Elements.OfType<XshdColor>().Where(xc => string.Equals(xc.Name, "StandardParametersColor", StringComparison.CurrentCultureIgnoreCase)).First();


XshdKeywords newKeyWords = new XshdKeywords();
newKeyWords.ColorReference = new XshdReference<XshdColor>(existingColor);

//I add new words to the Keywords object
for(int i = 1; i < 25; i++)
newKeyWords.Words.Add("A000" + i.ToString("00"));
for(int i = 1; i < 25; i++)
newKeyWords.Words.Add("B000" + i.ToString("00"));
for(int i = 1; i < 5; i++)
newKeyWords.Words.Add("C0000" + i);

XshdRuleSet mainRuleSet = xshd.Elements.OfType<XshdRuleSet>().Where(o => string.IsNullOrEmpty(o.Name)).First();
mainRuleSet.Elements.Add(newKeyWords);
}

Thanks!


Viewing all articles
Browse latest Browse all 1764

Trending Articles