private void miAdd_Click(object sender, EventArgs e) { if (dlgSelectAssembly.ShowDialog() != DialogResult.OK) { return; } string location = dlgSelectAssembly.FileName; if (string.IsNullOrEmpty(location)) { return; } var oldGrammars = new GrammarItemList(); foreach (var item in cboGrammars.Items) { oldGrammars.Add((GrammarItem)item); } var grammars = fmSelectGrammars.SelectGrammars(location, oldGrammars); if (grammars == null) { return; } foreach (GrammarItem item in grammars) { cboGrammars.Items.Add(item); } btnRefresh.Enabled = false; // auto-select the first grammar if no grammar currently selected if (cboGrammars.SelectedIndex < 0 && grammars.Count > 0) { cboGrammars.SelectedIndex = 0; } }
private static GrammarItemList LoadGrammars(string assemblyPath) { Assembly asm = null; try { asm = Assembly.LoadFrom(assemblyPath); } catch (Exception ex) { MessageBox.Show("Failed to load assembly: " + ex.Message); return(null); } var types = asm.GetTypes(); var grammars = new GrammarItemList(); foreach (Type t in types) { if (!t.IsSubclassOf(typeof(Grammar))) { continue; } grammars.Add(new GrammarItem(t, assemblyPath)); } if (grammars.Count == 0) { MessageBox.Show("No classes derived from Irony.Grammar were found in the assembly."); return(null); } return(grammars); }
private void miAdd_Click(object sender, EventArgs e) { if (dlgSelectAssembly.ShowDialog() != DialogResult.OK) { return; } string location = dlgSelectAssembly.FileName; if (string.IsNullOrEmpty(location)) { return; } var oldGrammars = new GrammarItemList(); foreach (var item in cboGrammars.Items) { oldGrammars.Add((GrammarItem)item); } var grammars = fmSelectGrammars.SelectGrammars(location, oldGrammars); if (grammars == null) { return; } foreach (GrammarItem item in grammars) { cboGrammars.Items.Add(item); } }
public static GrammarItemList FromCombo(ComboBox combo) { GrammarItemList list = new GrammarItemList(); foreach (GrammarItem item in combo.Items) { list.Add(item); } return(list); }
public static GrammarItemList FromXml(string xml) { GrammarItemList list = new GrammarItemList(); XmlDocument xdoc = new XmlDocument(); xdoc.LoadXml(xml); XmlNodeList xlist = xdoc.SelectNodes("//Grammar"); foreach (XmlElement xitem in xlist) { GrammarItem item = new GrammarItem(xitem); list.Add(item); } return(list); }
public static GrammarItemList SelectGrammars(string assemblyPath, GrammarItemList loadedGrammars) { var fromGrammars = LoadGrammars(assemblyPath); if (fromGrammars == null) { return(null); } //fill the listbox and show the form fmSelectGrammars form = new fmSelectGrammars(); var listbox = form.lstGrammars; listbox.Sorted = false; foreach (GrammarItem item in fromGrammars) { listbox.Items.Add(item); if (!ContainsGrammar(loadedGrammars, item)) { listbox.SetItemChecked(listbox.Items.Count - 1, true); } } listbox.Sorted = true; if (form.ShowDialog() != DialogResult.OK) { return(null); } GrammarItemList result = new GrammarItemList(); for (int i = 0; i < listbox.Items.Count; i++) { if (listbox.GetItemChecked(i)) { var item = listbox.Items[i] as GrammarItem; item._loading = false; result.Add(item); } } return(result); }