private void onSaveRule(rule saveThis) { // Find the Rule in the listView ListViewItem ruleItem = findRuleItem(saveThis); if (ruleItem == null) { DialogResult result; frmQuestion frm = new frmQuestion("New Rule"); if ((result = frm.ShowDialog(this)) != DialogResult.OK) { MessageBox.Show("Unable to save rule"); return; } while (findRuleItem(frm.result) != null && result == DialogResult.OK) result = frm.ShowDialog(this); if (result == DialogResult.Cancel) return; saveThis.changeName(_myOptions.rulesPath,frm.result); addNewRule(saveThis); } else { // mark the listView item as not being open in the editor any more ruleItem.SubItems[2].Text = false.ToString(); // Stash our rule object in the listViewItem. ruleItem.Tag = saveThis; } }
private void renameRuleToolStripMenuItem_Click(object sender, EventArgs e) { if (lstRules.SelectedItems.Count <= 0) { return; } if (lstRules.SelectedItems[0].SubItems[2].Text == true.ToString()) { MessageBox.Show(this , "Cannot rename rule which is open in the editor"); return; } rule toRename = (rule) lstRules.SelectedItems[0].Tag; string oldname = toRename.name; while(true) { frmQuestion newname = new frmQuestion("New rule name" , oldname); if (newname.ShowDialog(this) == DialogResult.Cancel) return; // nothing to do if the same name if (newname.result == toRename.name) return; if (findRuleItem(newname.result) != null) { MessageBox.Show(this , "Sorry a rule is already called " + newname.result); oldname = newname.result; } else { toRename.changeName(_myOptions.rulesPath,newname.result ); break; } } lstRules.SelectedItems[0].SubItems[1].Text = toRename.name; }
private void newRuleToolStripMenuItem_Click(object sender, EventArgs e) { while (true) { // Find a rule name which doesn't exist, and use this as the default string defaultName = "Unnamed Rule"; int n = 0; while ((findRuleItem(defaultName) != null)) { defaultName = String.Format("Unnamed Rule {0}", n.ToString()); n++; } // Ask the user what name they want frmQuestion newname = new frmQuestion("New rule name", defaultName); if (newname.ShowDialog(this) == DialogResult.Cancel) return; addNewRule(new rule(newname.result)); return; } }