14 using System.Collections.Generic;
18 using System.Windows.Forms;
19 using System.Reflection;
21 using System.Threading;
25 namespace Irony.GrammarExplorer {
33 internal bool _loading;
34 public GrammarItem(
string caption,
string location,
string typeName) {
39 public GrammarItem(Type grammarClass,
string assemblyLocation) {
41 Location = assemblyLocation;
42 TypeName = grammarClass.FullName;
44 Caption = grammarClass.Name;
45 LongCaption = Caption;
46 var langAttr = LanguageAttribute.GetValue(grammarClass);
47 if (langAttr != null) {
48 Caption = langAttr.LanguageName;
49 if (!
string.IsNullOrEmpty(langAttr.Version))
50 Caption +=
", version " + langAttr.Version;
51 LongCaption = Caption;
52 if (!
string.IsNullOrEmpty(langAttr.Description))
53 LongCaption +=
": " + langAttr.Description;
57 Caption = element.GetAttribute(
"Caption");
58 Location = element.GetAttribute(
"Location");
59 TypeName = element.GetAttribute(
"TypeName");
61 public void Save(XmlElement toElement) {
62 toElement.SetAttribute(
"Caption", Caption);
63 toElement.SetAttribute(
"Location", Location);
64 toElement.SetAttribute(
"TypeName", TypeName);
67 return _loading ? LongCaption : Caption;
75 XmlDocument xdoc =
new XmlDocument();
77 XmlNodeList xlist = xdoc.SelectNodes(
"//Grammar");
78 foreach (XmlElement xitem
in xlist) {
92 XmlDocument xdoc =
new XmlDocument();
93 XmlElement xlist = xdoc.CreateElement(
"Grammars");
94 xdoc.AppendChild(xlist);
96 XmlElement xitem = xdoc.CreateElement(
"Grammar");
97 xlist.AppendChild(xitem);
100 return xdoc.OuterXml;
106 combo.Items.Add(item);
static GrammarItemList FromXml(string xml)
override string ToString()
void Save(XmlElement toElement)
readonly string LongCaption
static GrammarItemList FromCombo(ComboBox combo)
void ShowIn(ComboBox combo)
GrammarItem(Type grammarClass, string assemblyLocation)
GrammarItem(string caption, string location, string typeName)
GrammarItem(XmlElement element)