public static Variable ShowEditor(AutoSplitEnv env) { using (var form = new VariableEditorPicker(env)) { return(form.ShowDialog() != DialogResult.Cancel ? form.EditedVariable : null); } }
void btnAdd_Click(object sender, EventArgs e) { var env = _env.Clone(); env.Events = EditedAutoSplit.Variables.GetRestrictedEvents() ?? _env.Events; var newVariable = VariableEditorPicker.ShowEditor(env); if (newVariable != null) { var list = (BindingList <Variable>)lstVariables.DataSource; var attributes = newVariable.GetType().GetCustomAttributes(typeof(VariableDescriptorAttribute), true); var varDescriptor = attributes.Length > 0 ? (VariableDescriptorAttribute)attributes[0] : null; if (varDescriptor == null || varDescriptor.AllowMultiple || !list.Any(v => v.GetType() == newVariable.GetType())) { if (EditedAutoSplit.Variables.AreCompatible(newVariable)) { var selectedIndex = lstVariables.SelectedIndex; list.Add(newVariable); if (selectedIndex == -1) { lstVariables.SelectedIndex = -1; } RefreshEvents(); } else { MessageBox.Show($"The new condition could not be added because one or more existing conditions are incompatible with it.", "Condition could not be added", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show($"There can't be multiple {newVariable.GetType().Name} conditions in an autosplit.", "Condition could not be added", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }