Skip to content

Commit

Permalink
* changed Run Peptide Search to keep wizard form close button visible (
Browse files Browse the repository at this point in the history
…#3337)

* changed Run Peptide Search to keep wizard form close button visible, but intercept it while search is running and display a confirmation dialog with yes/no buttons, with yes answer cancelling the search and closing the form when the search cancellation finishes
* added test for the "no" branch to TestDdaSearch
  • Loading branch information
chambm authored Jan 21, 2025
1 parent d29ca10 commit 0de1783
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 8 deletions.
11 changes: 11 additions & 0 deletions pwiz_tools/Skyline/Controls/WizardPages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
return base.ProcessCmdKey(ref msg, keyData);
}
}

public class WizardPageControl : UserControl
{
/// <summary>
/// Allow controls in a wizard to preempt close requests by the wizard's form. Returns true iff the close request should continue, false if it should be canceled.
/// </summary>
public virtual bool CanWizardClose()
{
return true;
}
}
}


Expand Down
21 changes: 19 additions & 2 deletions pwiz_tools/Skyline/FileUI/PeptideSearch/ImportPeptideSearchDlg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,12 @@ private static void AddPageControl<TControl>(TControl pageControl, TabPage tabPa
tabPage.Controls.Add(pageControl);
}

private UserControl GetPageControl(TabPage tabPage)
{
// Assume each tabPage only has a single UserControl; if that changes this function will need to be updated
return tabPage.Controls.OfType<UserControl>().SingleOrDefault();
}

public SrmDocument Document
{
get
Expand Down Expand Up @@ -998,7 +1004,6 @@ private void InitiateSearch()
btnNext.Enabled = false;
btnCancel.Enabled = false;
btnBack.Enabled = false;
ControlBox = false;

AbstractDdaConverter.MsdataFileFormat requiredFormat =
IsFeatureDetectionWorkflow
Expand Down Expand Up @@ -1085,7 +1090,6 @@ private void SearchControlSearchFinished(bool success)
{
btnCancel.Enabled = true;
btnBack.Enabled = true;
ControlBox = true;
btnNext.Enabled = success;
}

Expand Down Expand Up @@ -1484,8 +1488,21 @@ public void CloseWizard(DialogResult result)
DialogResult = result;
}

private bool CanWizardClose()
{
var wizardPageControl = GetPageControl(wizardPagesImportPeptideSearch.SelectedTab) as WizardPageControl;
return wizardPageControl == null || wizardPageControl.CanWizardClose();
}

protected override void OnFormClosing(FormClosingEventArgs e)
{
// Ask current WizardPageControl if wizard is in a good state to close
if (!CanWizardClose())
{
e.Cancel = true;
return;
}

// Close file handles to the peptide search library
ImportPeptideSearch.ClosePeptideSearchLibraryStreams(Document);

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -362,4 +362,7 @@ Click 'Retry' to try building again after placing the original spectrum files in
<data name="ImportPeptideSearchDlg_NextPage_Adding_detected_features_to_document" xml:space="preserve">
<value>Adding detected features to document</value>
</data>
<data name="SearchControl_CanWizardClose_Cannot_close_wizard_while_the_search_is_running_" xml:space="preserve">
<value>Cannot close wizard while the search is running. Do you want to cancel the search?</value>
</data>
</root>
19 changes: 18 additions & 1 deletion pwiz_tools/Skyline/FileUI/PeptideSearch/SearchControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@
using pwiz.Common.Controls;
using pwiz.Common.SystemUtil;
using pwiz.Skyline.Alerts;
using pwiz.Skyline.Controls;
using pwiz.Skyline.Util;
using pwiz.Skyline.Util.Extensions;

namespace pwiz.Skyline.FileUI.PeptideSearch
{
public abstract partial class SearchControl : UserControl, IProgressMonitor
public abstract partial class SearchControl : WizardPageControl, IProgressMonitor
{
public Action<IProgressStatus> UpdateUI;

Expand Down Expand Up @@ -266,6 +267,22 @@ public void Cancel()
btnCancel.Enabled = false;
}

public override bool CanWizardClose()
{
if (btnCancel.Enabled)
{
if (DialogResult.Yes == MessageDlg.Show(Parent,
PeptideSearchResources.SearchControl_CanWizardClose_Cannot_close_wizard_while_the_search_is_running_, false,
MessageBoxButtons.YesNo))
{
Cancel();
SearchFinished += _ => ParentForm?.Close();
}
return false;
}
return base.CanWizardClose();
}

private void btnCancel_Click(object sender, EventArgs e)
{
Cancel();
Expand Down
17 changes: 12 additions & 5 deletions pwiz_tools/Skyline/TestFunctional/DdaSearchTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,13 +407,20 @@ private void TestSearch()
{
importPeptideSearchDlg.SearchControl.SearchFinished += (success) => searchSucceeded = success;
importPeptideSearchDlg.BuildPepSearchLibControl.IncludeAmbiguousMatches = true;

// Cancel search
if (!errorExpected)
importPeptideSearchDlg.SearchControl.Cancel();
});

if (errorExpected)
if (!errorExpected)
{
SkylineWindow.BeginInvoke(new Action(importPeptideSearchDlg.Close)); // try to close (don't wait for return)
var cannotCloseDuringSearchDlg = WaitForOpenForm<MessageDlg>();
Assert.AreEqual(PeptideSearchResources.SearchControl_CanWizardClose_Cannot_close_wizard_while_the_search_is_running_,
cannotCloseDuringSearchDlg.Message);
OkDialog(cannotCloseDuringSearchDlg, cannotCloseDuringSearchDlg.ClickNo);

// Cancel search (but don't close wizard)
RunUI(importPeptideSearchDlg.SearchControl.Cancel);
}
else // errorExpected
{
var fastaFileNotFoundDlg = WaitForOpenForm<MessageDlg>();
var expectedMsg = new FileNotFoundException(GetSystemResourceString("IO.FileNotFound_FileName", GetTestPath(TestSettings.FastaFilename))).Message;
Expand Down

0 comments on commit 0de1783

Please sign in to comment.