public void OkDialog() { var helper = new MessageBoxHelper(this); string name; if (!helper.ValidateNameTextBox(textName, out name)) return; foreach (SrmSettings settings in Settings.Default.SrmSettingsList) { if (name == settings.Name) { var message = TextUtil.LineSeparate(String.Format(Resources.SaveSettingsDlg_OnClosing_The_name__0__already_exists, name), Resources.SaveSettingsDlg_OnClosing_Do_you_want_to_overwrite_the_existing_settings); var result = MessageBox.Show(this, message, Program.Name, MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result == DialogResult.OK) break; textName.Focus(); return; } } SaveName = name; DialogResult = DialogResult.OK; }
public void OkDialog() { MessageBoxHelper helper = new MessageBoxHelper(this); string serverName; if (!helper.ValidateNameTextBox(textServerURL, out serverName)) return; Uri uriServer = PanoramaUtil.ServerNameToUri(serverName); if (uriServer == null) { helper.ShowTextBoxError(textServerURL, Resources.EditServerDlg_OkDialog_The_text__0__is_not_a_valid_server_name_, serverName); return; } var panoramaClient = PanoramaClient ?? new WebPanoramaClient(uriServer); using (var waitDlg = new LongWaitDlg { Text = Resources.EditServerDlg_OkDialog_Verifying_server_information }) { try { waitDlg.PerformWork(this, 1000, () => PanoramaUtil.VerifyServerInformation( panoramaClient, Username, Password)); } catch (Exception x) { helper.ShowTextBoxError(textServerURL, x.Message); return; } } Uri updatedUri = panoramaClient.ServerUri ?? uriServer; if (_existing.Contains(server => !ReferenceEquals(_server, server) && Equals(updatedUri, server.URI))) { helper.ShowTextBoxError(textServerURL, Resources.EditServerDlg_OkDialog_The_server__0__already_exists_, uriServer.Host); return; } _server = new Server(updatedUri, Username, Password); DialogResult = DialogResult.OK; }
public void OkDialog() { var messageBoxHelper = new MessageBoxHelper(this); string name; if (!messageBoxHelper.ValidateNameTextBox(tbxName, out name)) { return; } if (_annotationDef == null || name != _annotationDef.Name) { foreach (var annotationDef in _existing) { if (annotationDef.Name == name) { messageBoxHelper.ShowTextBoxError(tbxName, Resources.DefineAnnotationDlg_OkDialog_There_is_already_an_annotation_defined_named__0__, name); return; } } } if (checkedListBoxAppliesTo.CheckedItems.Count == 0) { MessageBox.Show(this, Resources.DefineAnnotationDlg_OkDialog_Choose_at_least_one_type_for_this_annotation_to_apply_to, Program.Name); checkedListBoxAppliesTo.Focus(); return; } DialogResult = DialogResult.OK; Close(); }
public void OkDialog() { var helper = new MessageBoxHelper(this); string name; if (!helper.ValidateNameTextBox(_editing ? (Control) textName : comboMod, out name)) return; // Allow updating the original modification if (!_editing || !Equals(name, Modification.Name)) { if(!ModNameAvailable(name)) { helper.ShowTextBoxError(_editing ? (Control)textName : comboMod, Resources.EditStaticModDlg_OkDialog_The_modification__0__already_exists, name); return; } } string aas = comboAA.Text; if (string.IsNullOrEmpty(aas)) aas = null; else { // Use the cleanest possible format. var sb = new StringBuilder(); foreach (string aaPart in aas.Split(SEPARATOR_AA)) { string aa = aaPart.Trim(); if (aa.Length == 0) continue; if (sb.Length > 0) sb.Append(", "); // Not L10N sb.Append(aa); } } string termString = comboTerm.SelectedItem.ToString(); ModTerminus? term = null; if (!string.IsNullOrEmpty(termString)) term = (ModTerminus) Enum.Parse(typeof (ModTerminus), termString); if (cbVariableMod.Checked && aas == null && term == null) { MessageDlg.Show(this, Resources.EditStaticModDlg_OkDialog_Variable_modifications_must_specify_amino_acid_or_terminus); comboAA.Focus(); return; } string formula = null; double? monoMass = null; double? avgMass = null; LabelAtoms labelAtoms = LabelAtoms.None; if (cbChemicalFormula.Checked) formula = Formula; else labelAtoms = LabelAtoms; // Get the losses to know whether any exist below IList<FragmentLoss> losses = null; if (listNeutralLosses.Items.Count > 0) { losses = Losses.ToArray(); } if (!string.IsNullOrEmpty(formula)) { try { SequenceMassCalc.ParseModMass(BioMassCalc.MONOISOTOPIC, formula); } catch (ArgumentException x) { _formulaBox.ShowTextBoxErrorFormula(helper, x.Message); return; } } else if (labelAtoms == LabelAtoms.None) { formula = null; // Allow formula and both masses to be empty, if losses are present if ( NotZero(_formulaBox.MonoMass) || NotZero(_formulaBox.AverageMass)|| losses == null) { // TODO: Maximum and minimum masses should be formalized and applied everywhere double mass; if (!_formulaBox.ValidateMonoText(helper, -1500, 5000, out mass)) return; monoMass = mass; if (!_formulaBox.ValidateAverageText(helper, -1500, 5000, out mass)) return; avgMass = mass; } // Loss-only modifications may not be variable else if (cbVariableMod.Checked) { MessageDlg.Show(this, Resources.EditStaticModDlg_OkDialog_The_variable_checkbox_only_applies_to_precursor_modification_Product_ion_losses_are_inherently_variable); cbVariableMod.Focus(); return; } } else if (aas == null && term.HasValue) { MessageDlg.Show(this, Resources.EditStaticModDlg_OkDialog_Labeled_atoms_on_terminal_modification_are_not_valid); return; } RelativeRT relativeRT = RelativeRT.Matching; if (comboRelativeRT.Visible && comboRelativeRT.SelectedItem != null) { relativeRT = RelativeRTExtension.GetEnum(comboRelativeRT.SelectedItem.ToString()); } // Store state of the chemical formula checkbox for next use. if (cbChemicalFormula.Visible) Settings.Default.ShowHeavyFormula = _formulaBox.FormulaVisible; var newMod = new StaticMod(name, aas, term, cbVariableMod.Checked, formula, labelAtoms, relativeRT, monoMass, avgMass, losses); foreach (StaticMod mod in _existing) { if (newMod.Equivalent(mod) && !(_editing && mod.Equals(_originalModification))) { if (DialogResult.OK == MultiButtonMsgDlg.Show( this, TextUtil.LineSeparate(Resources.EditStaticModDlg_OkDialog_There_is_an_existing_modification_with_the_same_settings, string.Format("'{0}'.", mod.Name), // Not L10N string.Empty, Resources.EditStaticModDlg_OkDialog_Continue), MultiButtonMsgDlg.BUTTON_OK)) { Modification = newMod; DialogResult = DialogResult.OK; } return; } } var uniMod = UniMod.GetModification(name, IsStructural); // If the modification name is not found in Unimod, check if there exists a modification in Unimod that matches // the dialog modification, and prompt the user to to use the Unimod modification instead. if (uniMod == null) { var matchingMod = UniMod.FindMatchingStaticMod(newMod, IsStructural); if (matchingMod != null && (ModNameAvailable(matchingMod.Name) || (_editing && Equals(matchingMod.Name, Modification.Name)))) { var result = MultiButtonMsgDlg.Show( this, TextUtil.LineSeparate(Resources.EditStaticModDlg_OkDialog_There_is_a_Unimod_modification_with_the_same_settings, string.Empty, string.Format(Resources.EditStaticModDlg_OkDialog_Click__Unimod__to_use_the_name___0___, matchingMod.Name), string.Format(Resources.EditStaticModDlg_OkDialog_Click__Custom__to_use_the_name___0___, name)), Resources.EditStaticModDlg_OkDialog_Unimod, Resources.EditStaticModDlg_OkDialog_Custom, true); if (result == DialogResult.Yes) newMod = matchingMod.MatchVariableAndLossInclusion(newMod); // Unimod if (result == DialogResult.Cancel) return; } } else { // If the dialog modification matches the modification of the same name in Unimod, // use the UnimodId. if (newMod.Equivalent(uniMod)) newMod = uniMod.MatchVariableAndLossInclusion(newMod); else { // Finally, if the modification name is found in Unimod, but the modification in Unimod does not // match the dialog modification, prompt the user to use the Unimod modification definition instead. if (DialogResult.OK != MultiButtonMsgDlg.Show( this, TextUtil.LineSeparate(string.Format(Resources.EditStaticModDlg_OkDialog_This_modification_does_not_match_the_Unimod_specifications_for___0___, name), string.Empty, Resources.EditStaticModDlg_OkDialog_Use_non_standard_settings_for_this_name), MultiButtonMsgDlg.BUTTON_OK)) { return; } } } _modification = newMod; DialogResult = DialogResult.OK; }
public void OkDialog() { var helper = new MessageBoxHelper(this); string name; if (!helper.ValidateNameTextBox(textName, out name)) return; if (_existing.Contains(r => !ReferenceEquals(_parameters, r) && Equals(name, r.Name))) { helper.ShowTextBoxError(textName, Resources.EditCoVDlg_btnOk_Click_The_compensation_voltage_parameters___0___already_exist_, name); return; } double covMin; if (!helper.ValidateDecimalTextBox(textMin, 0, null, out covMin)) return; double covMax; if (!helper.ValidateDecimalTextBox(textMax, 0, null, out covMax)) return; if (covMax < covMin) { helper.ShowTextBoxError(textMax, Resources.EditCoVDlg_btnOk_Click_Maximum_compensation_voltage_cannot_be_less_than_minimum_compensation_volatage_); return; } int stepCountRough; if (!helper.ValidateNumberTextBox(textStepsRough, CompensationVoltageParameters.MIN_STEP_COUNT, CompensationVoltageParameters.MAX_STEP_COUNT, out stepCountRough)) return; int stepCountMedium; if (!helper.ValidateNumberTextBox(textStepsMedium, CompensationVoltageParameters.MIN_STEP_COUNT, CompensationVoltageParameters.MAX_STEP_COUNT, out stepCountMedium)) return; int stepCountFine; if (!helper.ValidateNumberTextBox(textStepsFine, CompensationVoltageParameters.MIN_STEP_COUNT, CompensationVoltageParameters.MAX_STEP_COUNT, out stepCountFine)) return; _parameters = new CompensationVoltageParameters(name, covMin, covMax, stepCountRough, stepCountMedium, stepCountFine); DialogResult = DialogResult.OK; }
public void OkDialog() { var helper = new MessageBoxHelper(this); string name; if (!helper.ValidateNameTextBox(textName, out name)) return; if (_existing.Contains(m => !ReferenceEquals(_measuredIon, m) && Equals(name, m.Name))) { helper.ShowTextBoxError(textName, Resources.EditMeasuredIonDlg_OkDialog_The_special_ion__0__already_exists, name); return; } if (radioFragment.Checked) { string cleavage; if (!ValidateAATextBox(helper, textFragment, false, out cleavage)) return; string restrict; if (!ValidateAATextBox(helper, textRestrict, true, out restrict)) return; SequenceTerminus direction = (comboDirection.SelectedIndex == 0 ? SequenceTerminus.C : SequenceTerminus.N); int minAas; if (!helper.ValidateNumberTextBox(textMinAas, MeasuredIon.MIN_MIN_FRAGMENT_LENGTH, MeasuredIon.MAX_MIN_FRAGMENT_LENGTH, out minAas)) return; _measuredIon = new MeasuredIon(name, cleavage, restrict, direction, minAas); } else { var customIon = ValidateCustomIon(name); if (customIon == null) return; _measuredIon = customIon; } DialogResult = DialogResult.OK; }
public void OkDialog() { var helper = new MessageBoxHelper(this); string name; if (!helper.ValidateNameTextBox(textName, out name)) return; string cleavageC; if (!helper.ValidateAATextBox(textCleavage, false, out cleavageC)) return; string restrictC; if (!helper.ValidateAATextBox(textRestrict, true, out restrictC)) return; string cleavageN; string restrictN; if (comboDirection.SelectedIndex == 2) { if (!helper.ValidateAATextBox(textCleavageN, false, out cleavageN)) return; if (!helper.ValidateAATextBox(textRestrictN, true, out restrictN)) return; } else if (comboDirection.SelectedIndex == 1) { cleavageN = cleavageC; cleavageC = null; restrictN = restrictC; restrictC = null; } else { cleavageN = null; restrictN = null; } Enzyme enzyme = new Enzyme(name, cleavageC, restrictC, cleavageN, restrictN); if (_enzyme == null && _existing.Contains(enzyme)) { helper.ShowTextBoxError(textName, Resources.EditEnzymeDlg_OnClosing_The_enzyme__0__already_exists, name); return; } _enzyme = enzyme; DialogResult = DialogResult.OK; }
public void OkDialog() { var helper = new MessageBoxHelper(this); string name; if (!helper.ValidateNameTextBox(textName, out name)) return; if (_columns.Count == 0) { MessageBox.Show(this, Resources.PivotReportDlg_OkDialog_A_report_must_have_at_least_one_column, Program.Name); return; } ReportSpec reportSpec = GetReport().GetReportSpec(name); if ((_reportSpec == null || !Equals(reportSpec.Name, _reportSpec.Name)) && _existing.Contains(reportSpec, new NameComparer<ReportSpec>())) { helper.ShowTextBoxError(textName, Resources.PivotReportDlg_OkDialog_The_report__0__already_exists, name); return; } _reportSpec = reportSpec; DialogResult = DialogResult.OK; Close(); }
public void OkDialog() { var helper = new MessageBoxHelper(this); if (NamedPathSets == null) { if (radioAddExisting.Checked) { if (comboName.SelectedIndex == -1) { MessageBox.Show(this, Resources.ImportResultsDlg_OkDialog_You_must_select_an_existing_set_of_results_to_which_to_append_new_data, Program.Name); comboName.Focus(); return; } if (!CanCreateMultiInjectionMethods()) return; NamedPathSets = GetDataSourcePathsFile(comboName.SelectedItem.ToString()); } else if (radioCreateMultiple.Checked) { NamedPathSets = GetDataSourcePathsFile(null); } else if (radioCreateMultipleMulti.Checked) { if (!CanCreateMultiInjectionMethods()) return; NamedPathSets = GetDataSourcePathsDir(); } else { string name; if (!helper.ValidateNameTextBox(textName, out name)) return; if (name.IndexOfAny(Path.GetInvalidFileNameChars()) != -1) { helper.ShowTextBoxError(textName, Resources.ImportResultsDlg_OkDialog_A_result_name_may_not_contain_any_of_the_characters___0___, Path.GetInvalidFileNameChars()); return; } if (ResultsExist(name)) { helper.ShowTextBoxError(textName, Resources.ImportResultsDlg_OkDialog_The_specified_name_already_exists_for_this_document); return; } NamedPathSets = GetDataSourcePathsFile(name); if (NamedPathSets == null) return; foreach (var namedPathSet in NamedPathSets) { // Look for a multiple injection replicate if (namedPathSet.Value.Length > 1) { // Make sure they are allowed if (!CanCreateMultiInjectionMethods()) return; // If so, then no need to check any others break; } } } } if (NamedPathSets == null) return; if (NamedPathSets.Length > 1) { string prefix = GetCommonPrefix(Array.ConvertAll(NamedPathSets, ns => ns.Key)); if (prefix.Length >= MIN_COMMON_PREFIX_LENGTH) { using (var dlgName = new ImportResultsNameDlg(prefix)) { var result = dlgName.ShowDialog(this); if (result == DialogResult.Cancel) { return; } if (result == DialogResult.Yes) { // Rename all the replicates to remove the specified prefix. for (int i = 0; i < NamedPathSets.Length; i++) { var namedSet = NamedPathSets[i]; NamedPathSets[i] = new KeyValuePair<string, MsDataFileUri[]>( namedSet.Key.Substring(dlgName.Prefix.Length), namedSet.Value); } } } } } // Always make sure multiple replicates have unique names. For single // replicate, the user will get an error. if (IsMultiple) EnsureUniqueNames(); DialogResult = DialogResult.OK; }
public void OkDialog() { var helper = new MessageBoxHelper(this); string name; if (!helper.ValidateNameTextBox(textName, out name)) return; // Allow updating the original modification if (LibrarySpec == null || !Equals(name, LibrarySpec.Name)) { // But not any other existing modification foreach (LibrarySpec mod in _existing) { if (Equals(name, mod.Name)) { helper.ShowTextBoxError(textName, Resources.EditLibraryDlg_OkDialog_The_library__0__already_exists, name); return; } } } String path = textPath.Text; if (!File.Exists(path)) { MessageBox.Show(this, string.Format(Resources.EditLibraryDlg_OkDialog_The_file__0__does_not_exist, path), Program.Name); textPath.Focus(); return; } if (FileEx.IsDirectory(path)) { MessageBox.Show(this, string.Format(Resources.EditLibraryDlg_OkDialog_The_path__0__is_a_directory, path), Program.Name); textPath.Focus(); return; } // Display an error message if the user is trying to add a BiblioSpec library, // and the library has the text "redundant" in the file name. if (path.EndsWith(BiblioSpecLiteSpec.EXT_REDUNDANT)) { var message = TextUtil.LineSeparate(string.Format(Resources.EditLibraryDlg_OkDialog_The_file__0__appears_to_be_a_redundant_library, path), Resources.EditLibraryDlg_OkDialog_Please_choose_a_non_redundant_library); MessageDlg.Show(this, string.Format(message, path)); textPath.Focus(); return; } var librarySpec = LibrarySpec.CreateFromPath(name, path); if (librarySpec == null) { MessageDlg.Show(this, string.Format(Resources.EditLibraryDlg_OkDialog_The_file__0__is_not_a_supported_spectral_library_file_format, path)); textPath.Focus(); return; } if (librarySpec is ChromatogramLibrarySpec) { using (var longWait = new LongWaitDlg{ Text = Resources.EditLibraryDlg_OkDialog_Loading_chromatogram_library }) { Library lib = null; try { try { longWait.PerformWork(this, 800, monitor => lib = librarySpec.LoadLibrary(new DefaultFileLoadMonitor(monitor))); } // ReSharper disable once EmptyGeneralCatchClause catch { // Library failed to load } LibraryRetentionTimes libRts; if (lib != null && lib.TryGetIrts(out libRts) && Settings.Default.RTScoreCalculatorList.All(calc => calc.PersistencePath != path)) { using (var addPredictorDlg = new AddRetentionTimePredictorDlg(name, path)) { switch (addPredictorDlg.ShowDialog(this)) { case DialogResult.OK: Settings.Default.RTScoreCalculatorList.Add(addPredictorDlg.Calculator); Settings.Default.RetentionTimeList.Add(addPredictorDlg.Regression); Settings.Default.Save(); break; case DialogResult.No: break; default: return; } } } } finally { if (null != lib) { foreach (var pooledStream in lib.ReadStreams) { pooledStream.CloseStream(); } } } } } _librarySpec = librarySpec; DialogResult = DialogResult.OK; Close(); }
public void OkDialog() { var helper = new MessageBoxHelper(this); string name; if (!helper.ValidateNameTextBox(textName, out name)) return; if (_existing.Contains(exc => !ReferenceEquals(_exclusion, exc) && Equals(name, exc.Name))) { helper.ShowTextBoxError(textName, Resources.EditExclusionDlg_OkDialog_The_peptide_exclusion__0__already_exists, name); return; } string exRegex = textExclusionRegex.Text.Trim(); if (string.IsNullOrEmpty(exRegex)) { helper.ShowTextBoxError(textExclusionRegex, Resources.EditExclusionDlg_OkDialog__0__must_contain_a_valid_regular_expression_); return; } try { // ReSharper disable ObjectCreationAsStatement new Regex(exRegex); // ReSharper restore ObjectCreationAsStatement } catch (Exception) { helper.ShowTextBoxError(textExclusionRegex, Resources.EditExclusionDlg_OkDialog_The_text__0__is_not_a_valid_regular_expression, exRegex); return; } bool includeMatch = radioNotMatching.Checked; bool matchMod = radioModSequence.Checked; PeptideExcludeRegex exclusion = new PeptideExcludeRegex(name, exRegex, includeMatch, matchMod); _exclusion = exclusion; DialogResult = DialogResult.OK; }