Ejemplo n.º 1
0
    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;
    }
Ejemplo n.º 2
0
 private static bool ContainsGrammar(GrammarItemList items, GrammarItem item)
 {
     foreach (var listItem in items)
     if (listItem.TypeName == item.TypeName && listItem.Location == item.Location)
       return true;
       return false;
 }
Ejemplo n.º 3
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;
 }
Ejemplo n.º 4
0
 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;
 }
Ejemplo n.º 5
0
 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);
 }
Ejemplo n.º 6
0
 private static bool ContainsGrammar(GrammarItemList items, GrammarItem item)
 {
     return items.Any(listItem => listItem.TypeName == item.TypeName && listItem.Location == item.Location);
 }