Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cancel button to 'Do you want to save?' message box #1185

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/TestCentric/testcentric.gui/IMessageDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@ public interface IMessageDisplay

bool YesNo(string message);

MessageBoxResult YesNoCancel(string message);

bool OkCancel(string message);
}

/// <summary>
/// Enum representing the return value of a MessageBox
/// It contains the identical values in same order as the DialogResult enum from Windows Forms
/// It has the same intention as the interface <see cref="IMessageDisplay"/> to hide any implementation details to the caller.
/// </summary>
public enum MessageBoxResult
{
None,
OK,
Cancel,
Abort,
Retry,
Ignore,
Yes,
No,
}
}
12 changes: 12 additions & 0 deletions src/TestCentric/testcentric.gui/MessageBoxDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ public static bool YesNo(string message, string caption)
return MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes;
}

public static MessageBoxResult YesNoCancel(string message, string caption)
{
DialogResult dialogResult = MessageBox.Show(message, caption, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
return dialogResult == DialogResult.Yes ? MessageBoxResult.Yes :
dialogResult == DialogResult.No ? MessageBoxResult.No : MessageBoxResult.Cancel;
}

public static bool OkCancel(string message)
{
return OkCancel(message, DEFAULT_CAPTION);
Expand Down Expand Up @@ -88,6 +95,11 @@ bool IMessageDisplay.YesNo(string message)
return YesNo(message, _caption);
}

MessageBoxResult IMessageDisplay.YesNoCancel(string message)
{
return YesNoCancel(message, _caption);
}

bool IMessageDisplay.OkCancel(string message)
{
return OkCancel(message, _caption);
Expand Down
20 changes: 12 additions & 8 deletions src/TestCentric/testcentric.gui/Presenters/TestCentricPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,8 @@ void OnRunFinished(ResultNode result)
_model.StopTestRun(true);
}

CloseProject();
//if (CloseProject() == DialogResult.Cancel)
// e.Cancel = true;
if (CloseProject() == MessageBoxResult.Cancel)
e.Cancel = true;
}

if (!e.Cancel)
Expand Down Expand Up @@ -684,15 +683,20 @@ private void SaveProject()

#region Close Methods

public void CloseProject()
public MessageBoxResult CloseProject()
{
if (!_options.Unattended && _model.TestCentricProject.IsDirty &&
_view.MessageDisplay.YesNo($"Do you want to save {_model.TestCentricProject.Name}?"))
MessageBoxResult messageBoxResult = MessageBoxResult.OK;
if (!_options.Unattended && _model.TestCentricProject.IsDirty)
{
SaveProject();
messageBoxResult = _view.MessageDisplay.YesNoCancel($"Do you want to save {_model.TestCentricProject.Name}?");
if (messageBoxResult == MessageBoxResult.Yes)
SaveProject();
}

_model.CloseProject();
if (messageBoxResult != MessageBoxResult.Cancel)
_model.CloseProject();

return messageBoxResult;
}

#endregion
Expand Down