private void AddRule_Button_Click( object sender, EventArgs e ) { using( var dlg = new InputForm() ) { dlg.OKButtonLabel = "Add new rule"; dlg.CheckRuleCallback = this.CheckRuleString; dlg.RuleString = string.Empty; if( dlg.ShowDialog(this.ParentForm) == DialogResult.OK ) { bool grammaticals_changed = false, terminals_changed = false; var new_rule = this.ParseRule(dlg.RuleString); this.UpdateSymbolsAfterRuleAdded(new_rule, ref grammaticals_changed, ref terminals_changed); this.rules.Add(new_rule); // Update gui this.Rules_ListBox.Items.Add(dlg.RuleString); //TODO: new_rule instead? if( grammaticals_changed ) this.UpdateGrammaticals(); if( terminals_changed ) this.UpdateTerminals(); } } }
private void EditRule_Button_Click( object sender, EventArgs e ) { if( this.Rules_ListBox.SelectedIndices.Count != 1 ) { MessageBox.Show( this.ParentForm, "Select one rule!", "Edit rule", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } int index = this.Rules_ListBox.SelectedIndices[0]; var old_rule = this.rules[index]; using( var dlg = new InputForm() ) { dlg.OKButtonLabel = "Save rule"; dlg.CheckRuleCallback = this.CheckRuleString; dlg.RuleString = old_rule.ToString(); if( dlg.ShowDialog(this.ParentForm) == DialogResult.OK ) { bool grammaticals_changed = false, terminals_changed = false; var new_rule = this.ParseRule(dlg.RuleString); this.rules[index] = new_rule; this.UpdateSymbolsAfterRuleRemoved(old_rule, ref grammaticals_changed, ref terminals_changed); this.UpdateSymbolsAfterRuleAdded(new_rule, ref grammaticals_changed, ref terminals_changed); // Update Gui accordingly this.Rules_ListBox.Items[index] = dlg.RuleString; //TODO: new_rule ? if( grammaticals_changed ) this.UpdateGrammaticals(); if( terminals_changed ) this.UpdateTerminals(); } } }