private void Paste(DataGridView dataGridView, bool enumerateProteins) { string text; try { text = ClipboardEx.GetText(); } catch (ExternalException) { MessageDlg.Show(this, ClipboardHelper.GetOpenClipboardMessage(Resources.PasteDlg_Paste_Failed_getting_data_from_the_clipboard)); return; } int numUnmatched; int numMultipleMatches; int numFiltered; int prevRowCount = dataGridView.RowCount; try { Paste(dataGridView, text, enumerateProteins, enumerateProteins, out numUnmatched, out numMultipleMatches, out numFiltered); } // User pasted invalid text. catch(InvalidDataException e) { dataGridView.Show(); // Show the invalid text, then remove all newly added rows. MessageDlg.ShowException(this, e); RemoveLastRows(dataGridView, dataGridView.RowCount - prevRowCount); return; } // If we have no unmatched, no multiple matches, and no filtered, we do not need to show // the FilterMatchedPeptidesDlg. if (numUnmatched + numMultipleMatches + numFiltered == 0) return; using (var filterPeptidesDlg = new FilterMatchedPeptidesDlg(numMultipleMatches, numUnmatched, numFiltered, dataGridView.RowCount - prevRowCount == 1)) { var result = filterPeptidesDlg.ShowDialog(this); // If the user is keeping all peptide matches, we don't need to redo the paste. bool keepAllPeptides = ((FilterMultipleProteinMatches == BackgroundProteome.DuplicateProteinsFilter.AddToAll || numMultipleMatches == 0) && (Settings.Default.LibraryPeptidesAddUnmatched || numUnmatched == 0) && (Settings.Default.LibraryPeptidesKeepFiltered || numFiltered == 0)); // If the user is filtering some peptides, or if the user clicked cancel, remove all rows added as // a result of the paste. if (result == DialogResult.Cancel || !keepAllPeptides) RemoveLastRows(dataGridView, dataGridView.RowCount - prevRowCount); // Redo the paste with the new filter settings. if (result != DialogResult.Cancel && !keepAllPeptides) Paste(dataGridView, text, enumerateProteins, !enumerateProteins, out numUnmatched, out numMultipleMatches, out numFiltered); } }
/// <summary> /// If peptides match to multiple proteins, ask the user what they want to do with these /// peptides. /// </summary> public DialogResult EnsureDuplicateProteinFilter(IWin32Window parent, bool single) { var result = DialogResult.OK; var multipleProteinsPerPeptideCount = PeptideMatches.Values.Count( pepMatch => pepMatch.Proteins != null && pepMatch.Proteins.Count > 1); var unmatchedPeptidesCount = PeptideMatches.Values.Count(pepMatch => pepMatch.Proteins != null && pepMatch.Proteins.Count == 0); var filteredPeptidesCount = PeptideMatches.Values.Count(pepMatch => !pepMatch.MatchesFilterSettings); if(multipleProteinsPerPeptideCount > 0 || unmatchedPeptidesCount > 0 || filteredPeptidesCount > 0) { using (var peptideProteinsDlg = new FilterMatchedPeptidesDlg(multipleProteinsPerPeptideCount, unmatchedPeptidesCount, filteredPeptidesCount, single)) { result = peptideProteinsDlg.ShowDialog(parent); } } return result; }