public MainWindow() { InitializeComponent(); DataContext = this; cmbFontStyle.ItemsSource = new FontStyle[] { FontStyles.Italic, FontStyles.Normal, FontStyles.Oblique }; cmbFontWeight.ItemsSource = new FontWeight[] { FontWeights.Black, FontWeights.Bold, FontWeights.DemiBold, FontWeights.ExtraBlack, FontWeights.ExtraBold, FontWeights.ExtraLight, FontWeights.Heavy, FontWeights.Light, FontWeights.Medium, FontWeights.Normal, FontWeights.Regular, FontWeights.SemiBold, FontWeights.Thin, FontWeights.UltraBlack, FontWeights.UltraBold, FontWeights.UltraLight }; try { using (XmlTextReader reader = new XmlTextReader(App.XSHDFile)) { xshd = HighlightingLoader.LoadXshd(reader); //XshdColor x; } colors = xshd.Elements.OfType<XshdColor>().ToList(); /*using (XmlTextWriter writer = new XmlTextWriter("output.xshd", System.Text.Encoding.UTF8)) { writer.Formatting = Formatting.Indented; new SaveXshdVisitor(writer).WriteDefinition(xshd); }*/ } catch (Exception) { MessageBox.Show("Error: Couldn't load syntax definition file." + Environment.NewLine + "Usage: XSHDEditor myfile.xshd", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); } }
/// <summary> /// Creates a highlighting definition from the XSHD file. /// </summary> public static Tuple <IHighlightingDefinition, XshdSyntaxDefinition> Load(XmlReader reader, IHighlightingDefinitionReferenceResolver resolver) { XshdSyntaxDefinition def = LoadXshd(reader); IHighlightingDefinition highlightDef = Load(def, resolver); return(new Tuple <IHighlightingDefinition, XshdSyntaxDefinition>(highlightDef, def)); }
public XmlHighlightingDefinition(XshdSyntaxDefinition xshd, IHighlightingDefinitionReferenceResolver resolver) { this.Name = xshd.Name; // Create HighlightingRuleSet instances var rnev = new RegisterNamedElementsVisitor(this); xshd.AcceptElements(rnev); // Assign MainRuleSet so that references can be resolved foreach (XshdElement element in xshd.Elements) { XshdRuleSet xrs = element as XshdRuleSet; if (xrs != null && xrs.Name == null) { if (MainRuleSet != null) { throw Error(element, "Duplicate main RuleSet. There must be only one nameless RuleSet!"); } else { MainRuleSet = rnev.ruleSets[xrs]; } } } if (MainRuleSet == null) { throw new HighlightingDefinitionInvalidException("Could not find main RuleSet."); } // Translate elements within the rulesets (resolving references and processing imports) xshd.AcceptElements(new TranslateElementVisitor(this, rnev.ruleSets, resolver)); foreach (var p in xshd.Elements.OfType <XshdProperty>()) { propDict.Add(p.Name, p.Value); } }
public XmlHighlightingDefinition(XshdSyntaxDefinition xshd, IHighlightingDefinitionReferenceResolver resolver) { this.Name = xshd.Name; xshd.AcceptElements(new RegisterNamedElementsVisitor(this)); TranslateElementVisitor translateVisitor = new TranslateElementVisitor(this, resolver); foreach (XshdElement element in xshd.Elements) { HighlightingRuleSet rs = element.AcceptVisitor(translateVisitor) as HighlightingRuleSet; XshdRuleSet xrs = element as XshdRuleSet; if (rs != null && xrs != null && xrs.Name == null) { if (MainRuleSet != null) { throw Error(element, "Duplicate main RuleSet. There must be only one nameless RuleSet!"); } else { MainRuleSet = rs; } } } if (MainRuleSet == null) { throw new HighlightingDefinitionInvalidException("Could not find main RuleSet."); } }
/// <summary> /// Creates a highlighting definition from the XSHD file. /// </summary> public static IHighlightingDefinition Load(XshdSyntaxDefinition syntaxDefinition, IHighlightingDefinitionReferenceResolver resolver) { if (syntaxDefinition == null) { throw new ArgumentNullException("syntaxDefinition"); } return(new XmlHighlightingDefinition(syntaxDefinition, resolver)); }
private XshdSyntaxDefinition ParseDefinition(XmlElement syntaxDefinition) { XshdSyntaxDefinition def = new XshdSyntaxDefinition(); def.Name = syntaxDefinition.GetAttributeOrNull("name"); if (syntaxDefinition.HasAttribute("extensions")) { def.Extensions.AddRange(syntaxDefinition.GetAttribute("extensions").Split(';', '|')); } XshdRuleSet mainRuleSetElement = null; foreach (XmlElement element in syntaxDefinition.GetElementsByTagName("RuleSet")) { XshdRuleSet ruleSet = ImportRuleSet(element); def.Elements.Add(ruleSet); if (ruleSet.Name == null) { mainRuleSetElement = ruleSet; } if (syntaxDefinition["Digits"] != null) { // create digit highlighting rule const string optionalExponent = @"([eE][+-]?[0-9]+)?"; const string floatingPoint = @"\.[0-9]+"; ruleSet.Elements.Add( new XshdRule { ColorReference = GetColorReference(syntaxDefinition["Digits"]), RegexType = XshdRegexType.IgnorePatternWhitespace, Regex = @"\b0[xX][0-9a-fA-F]+" + @"|" + @"(\b\d+(" + floatingPoint + ")?" + @"|" + floatingPoint + ")" + optionalExponent }); } } if (syntaxDefinition.HasAttribute("extends") && mainRuleSetElement != null) { // convert 'extends="HTML"' to '<Import ruleSet="HTML/" />' in main rule set. mainRuleSetElement.Elements.Add( new XshdImport { RuleSetReference = new XshdReference <XshdRuleSet>( syntaxDefinition.GetAttribute("extends"), string.Empty ) }); } return(def); }
static XshdSyntaxDefinition ParseDefinition(XmlReader reader) { Debug.Assert(reader.LocalName == "SyntaxDefinition"); XshdSyntaxDefinition def = new XshdSyntaxDefinition(); def.Name = reader.GetAttribute("name"); string extensions = reader.GetAttribute("extensions"); if (extensions != null) def.Extensions.AddRange(extensions.Split(';')); ParseElements(def.Elements, reader); Debug.Assert(reader.NodeType == XmlNodeType.EndElement); Debug.Assert(reader.LocalName == "SyntaxDefinition"); return def; }
/// <summary> /// Writes the specified syntax definition. /// </summary> public void WriteDefinition(XshdSyntaxDefinition definition) { if (definition == null) throw new ArgumentNullException("definition"); writer.WriteStartElement("SyntaxDefinition", Namespace); if (definition.Name != null) writer.WriteAttributeString("name", definition.Name); if (definition.Extensions != null) writer.WriteAttributeString("extensions", string.Join(";", definition.Extensions.ToArray())); definition.AcceptElements(this); writer.WriteEndElement(); }
static XshdSyntaxDefinition ParseDefinition(XmlReader reader) { Debug.Assert(reader.LocalName == "SyntaxDefinition"); XshdSyntaxDefinition def = new XshdSyntaxDefinition(); def.Name = reader.GetAttribute("name"); string extensions = reader.GetAttribute("extensions"); if (extensions != null) { def.Extensions.AddRange(extensions.Split(';')); } ParseElements(def.Elements, reader); Debug.Assert(reader.NodeType == XmlNodeType.EndElement); Debug.Assert(reader.LocalName == "SyntaxDefinition"); return(def); }
public XmlHighlightingDefinition(XshdSyntaxDefinition xshd, IHighlightingDefinitionReferenceResolver resolver) { this.Name = xshd.Name; xshd.AcceptElements(new RegisterNamedElementsVisitor(this)); TranslateElementVisitor translateVisitor = new TranslateElementVisitor(this, resolver); foreach (XshdElement element in xshd.Elements) { HighlightingRuleSet rs = element.AcceptVisitor(translateVisitor) as HighlightingRuleSet; XshdRuleSet xrs = element as XshdRuleSet; if (rs != null && xrs != null && xrs.Name == null) { if (MainRuleSet != null) throw Error(element, "Duplicate main RuleSet. There must be only one nameless RuleSet!"); else MainRuleSet = rs; } } if (MainRuleSet == null) throw new HighlightingDefinitionInvalidException("Could not find main RuleSet."); }
XshdSyntaxDefinition ParseDefinition(XmlElement syntaxDefinition) { XshdSyntaxDefinition def = new XshdSyntaxDefinition(); def.Name = syntaxDefinition.GetAttributeOrNull("name"); if (syntaxDefinition.HasAttribute("extensions")) { def.Extensions.AddRange(syntaxDefinition.GetAttribute("extensions").Split(';', '|')); } XshdRuleSet mainRuleSetElement = null; foreach (XmlElement element in syntaxDefinition.GetElementsByTagName("RuleSet")) { XshdRuleSet ruleSet = ImportRuleSet(element); def.Elements.Add(ruleSet); if (ruleSet.Name == null) mainRuleSetElement = ruleSet; if (syntaxDefinition["Digits"] != null) { // create digit highlighting rule const string optionalExponent = @"([eE][+-]?[0-9]+)?"; const string floatingPoint = @"\.[0-9]+"; ruleSet.Elements.Add( new XshdRule { ColorReference = GetColorReference(syntaxDefinition["Digits"]), RegexType = XshdRegexType.IgnorePatternWhitespace, Regex = @"\b0[xX][0-9a-fA-F]+" + @"|\b" + @"(\d+(" + floatingPoint + ")?" + @"|" + floatingPoint + ")" + optionalExponent }); } } if (syntaxDefinition.HasAttribute("extends") && mainRuleSetElement != null) { // convert 'extends="HTML"' to '<Import ruleSet="HTML/" />' in main rule set. mainRuleSetElement.Elements.Add( new XshdImport { RuleSetReference = new XshdReference<XshdRuleSet>( syntaxDefinition.GetAttribute("extends"), string.Empty ) }); } return def; }
/// <summary> /// Writes the specified syntax definition. /// </summary> public void WriteDefinition(XshdSyntaxDefinition definition) { if (definition == null) { throw new ArgumentNullException("definition"); } writer.WriteStartElement("SyntaxDefinition", Namespace); if (definition.Name != null) { writer.WriteAttributeString("name", definition.Name); } if (definition.Extensions != null) { writer.WriteAttributeString("extensions", string.Join(";", definition.Extensions.ToArray())); } definition.AcceptElements(this); writer.WriteEndElement(); }
public XmlHighlightingDefinition(XshdSyntaxDefinition xshd, IHighlightingDefinitionReferenceResolver resolver) { this.Name = xshd.Name; // Create HighlightingRuleSet instances var rnev = new RegisterNamedElementsVisitor(this); xshd.AcceptElements(rnev); // Assign MainRuleSet so that references can be resolved foreach (XshdElement element in xshd.Elements) { XshdRuleSet xrs = element as XshdRuleSet; if (xrs != null && xrs.Name == null) { if (MainRuleSet != null) throw Error(element, "Duplicate main RuleSet. There must be only one nameless RuleSet!"); else MainRuleSet = rnev.ruleSets[xrs]; } } if (MainRuleSet == null) throw new HighlightingDefinitionInvalidException("Could not find main RuleSet."); // Translate elements within the rulesets (resolving references and processing imports) xshd.AcceptElements(new TranslateElementVisitor(this, rnev.ruleSets, resolver)); }
private IHighlightingDefinition LoadHighlightingDefinition() { HighlightingManager highlightingManager = HighlightingManager.Instance; if (!string.IsNullOrEmpty(CustomSyntaxHighlightingFileName)) { using (var reader = new XmlTextReader(CustomSyntaxHighlightingFileName)) _syntaxDefinition = HighlightingLoader.LoadXshd(reader); } if (_syntaxDefinition != null) { IHighlightingDefinition highlightingDefinition = HighlightingLoader.Load(_syntaxDefinition, highlightingManager); highlightingManager.RegisterHighlighting(_syntaxDefinition.Name, _syntaxDefinition.Extensions.ToArray(), highlightingDefinition); } return highlightingManager.GetDefinition(_name); }
public static void Init() { if (Table == null) { var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("QueryDesk.Resources.Table_748.png"); PngBitmapDecoder decoder = new PngBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); Table = decoder.Frames[0]; } if (Field == null) { var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("QueryDesk.Resources.Template_514.png"); PngBitmapDecoder decoder = new PngBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); Field = decoder.Frames[0]; } if (SQLHighlighter == null) { var reader = XmlReader.Create(Assembly.GetExecutingAssembly().GetManifestResourceStream("QueryDesk.Resources.SQL.xshd")); SQLHighlighter = HighlightingLoader.LoadXshd(reader); SQLSyntaxHiglighting = HighlightingLoader.Load(SQLHighlighter, HighlightingManager.Instance); } }
/// <summary> /// Creates a highlighting definition from the XSHD file. /// </summary> public static IHighlightingDefinition Load(XshdSyntaxDefinition syntaxDefinition, IHighlightingDefinitionReferenceResolver resolver) { if (syntaxDefinition == null) throw new ArgumentNullException("syntaxDefinition"); return new XmlHighlightingDefinition(syntaxDefinition, resolver); }
public DefaultLanguageDefinition(XshdSyntaxDefinition syntaxDefinition) : this(syntaxDefinition.Name, syntaxDefinition.Extensions) { _syntaxDefinition = syntaxDefinition; }
private void setColoring(ICSharpCode.AvalonEdit.TextEditor textEditor) { string dir =System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); using (StreamReader s = new StreamReader(dir + @"\Resources\AutonEditColors.xshd")) { using (XmlTextReader reader = new XmlTextReader(s)) { xshd = HighlightingLoader.LoadXshd(reader); OptionsWindow _ow = new OptionsWindow(); for(int ii=0;ii<6;ii++) { updateStandardWordList(ii); } for(int i=6;i<_ow.words.Count;i++) { updateWordList(i); } textEditor.SyntaxHighlighting = ICSharpCode.AvalonEdit.Highlighting.Xshd.HighlightingLoader.Load(xshd, HighlightingManager.Instance); } } }