void LanguageComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { listBox.ItemsSource = null; XshdSyntaxDefinition xshd = (XshdSyntaxDefinition)languageComboBox.SelectedItem; if (xshd != null) { IHighlightingItem defaultText; ObservableCollection <IHighlightingItem> list = new ObservableCollection <IHighlightingItem>(); CreateDefaultEntries(languageComboBox.SelectedIndex == 0 ? null : xshd.Name, out defaultText, list); listBox.ItemsSource = list; if (languageComboBox.SelectedIndex > 0) { // Create entries for all customizable colors in the syntax highlighting definition // (but don't do this for the "All languages" pseudo-entry) IHighlightingDefinition def = HighlightingManager.Instance.GetDefinition(xshd.Name); if (def == null) { throw new InvalidOperationException("Expected that all XSHDs are registered in default highlighting manager; but highlighting definition was not found"); } else { var visitor = new ColorVisitor(allSyntaxDefinitions); xshd.AcceptElements(visitor); foreach (XshdColor namedColor in visitor.foundColors) { if (namedColor.ExampleText != null) { IHighlightingItem item = new NamedColorHighlightingItem(defaultText, namedColor) { ParentDefinition = def }; item = new CustomizedHighlightingItem(customizationList, item, xshd.Name); list.Add(item); item.PropertyChanged += item_PropertyChanged; } } } } if (listBox.Items.Count > 0) { listBox.SelectedIndex = 0; } } }
bool FindSDColor(string sdKey, out IHighlightingItem item) { string language = null; int dot = sdKey.IndexOf('.'); if (dot > 0) { language = sdKey.Substring(0, dot); sdKey = sdKey.Substring(dot + 1); } if ((language == null && languageComboBox.SelectedIndex == 0) || (language == ((XshdSyntaxDefinition)languageComboBox.SelectedItem).Name)) { item = listBox.Items.OfType <IHighlightingItem>().FirstOrDefault(i => i.Name == sdKey); } else if (language == null) { item = defaultEntries.FirstOrDefault(i => i.Name == sdKey); } else { var def = allSyntaxDefinitions.FirstOrDefault(d => d.Name == language); var highlighting = HighlightingManager.Instance.GetDefinition(language); item = null; if (def != null && highlighting != null) { var visitor = new ColorVisitor(allSyntaxDefinitions); def.AcceptElements(visitor); var color = visitor.foundColors.FirstOrDefault(i => i.Name == sdKey); if (color != null) { item = new NamedColorHighlightingItem(defaultText, color) { ParentDefinition = highlighting }; item = new CustomizedHighlightingItem(customizationList, item, language); } } } return(item != null); }
bool FindSDColor(string sdKey, out IHighlightingItem item) { string language = null; int dot = sdKey.IndexOf('.'); if (dot > 0) { language = sdKey.Substring(0, dot); sdKey = sdKey.Substring(dot + 1); } if ((language == null && languageComboBox.SelectedIndex == 0) || (language == ((XshdSyntaxDefinition)languageComboBox.SelectedItem).Name)) { item = listBox.Items.OfType<IHighlightingItem>().FirstOrDefault(i => i.Name == sdKey); } else if (language == null) { item = defaultEntries.FirstOrDefault(i => i.Name == sdKey); } else { var def = allSyntaxDefinitions.FirstOrDefault(d => d.Name == language); var highlighting = HighlightingManager.Instance.GetDefinition(language); item = null; if (def != null && highlighting != null) { var visitor = new ColorVisitor(allSyntaxDefinitions); def.AcceptElements(visitor); var color = visitor.foundColors.FirstOrDefault(i => i.Name == sdKey); if (color != null) { item = new NamedColorHighlightingItem(defaultText, color) { ParentDefinition = highlighting }; item = new CustomizedHighlightingItem(customizationList, item, language); } } } return item != null; }
void LanguageComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { listBox.ItemsSource = null; XshdSyntaxDefinition xshd = (XshdSyntaxDefinition)languageComboBox.SelectedItem; if (xshd != null) { IHighlightingItem defaultText; ObservableCollection<IHighlightingItem> list = new ObservableCollection<IHighlightingItem>(); CreateDefaultEntries(languageComboBox.SelectedIndex == 0 ? null : xshd.Name, out defaultText, list); listBox.ItemsSource = list; if (languageComboBox.SelectedIndex > 0) { // Create entries for all customizable colors in the syntax highlighting definition // (but don't do this for the "All languages" pseudo-entry) IHighlightingDefinition def = HighlightingManager.Instance.GetDefinition(xshd.Name); if (def == null) { throw new InvalidOperationException("Expected that all XSHDs are registered in default highlighting manager; but highlighting definition was not found"); } else { var visitor = new ColorVisitor(allSyntaxDefinitions); xshd.AcceptElements(visitor); foreach (XshdColor namedColor in visitor.foundColors) { if (namedColor.ExampleText != null) { IHighlightingItem item = new NamedColorHighlightingItem(defaultText, namedColor) { ParentDefinition = def }; item = new CustomizedHighlightingItem(customizationList, item, xshd.Name); list.Add(item); item.PropertyChanged += item_PropertyChanged; } } } } if (listBox.Items.Count > 0) listBox.SelectedIndex = 0; } }