Skip to content

Commit

Permalink
Other: Tweak the dialog service so dialogs report closing whether con…
Browse files Browse the repository at this point in the history
…firmed or cancelled.
  • Loading branch information
deanthecoder committed Jan 21, 2024
1 parent af8a406 commit 4442fdc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 2 additions & 6 deletions Speculator/CSharp.Utils/UI/DialogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class DialogService
{
public static DialogService Instance { get; } = new DialogService();

public void Warn(string message, string detail, string cancelButton, string actionButton, Action action, MaterialIconKind? icon = null)
public void Warn(string message, string detail, string cancelButton, string actionButton, Action<bool> onClose, MaterialIconKind? icon = null)
{
DialogHost.Show(new ConfirmationDialog
{
Expand All @@ -30,10 +30,6 @@ public void Warn(string message, string detail, string cancelButton, string acti
ActionBrush = Brushes.Red,
Icon = icon
},
(_, args) =>
{
if (Convert.ToBoolean(args.Parameter))
action();
});
(_, args) => onClose(Convert.ToBoolean(args.Parameter)));
}
}
8 changes: 6 additions & 2 deletions Speculator/Speculator/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,18 @@ public void SaveRom()
command.Cancelled += (_, _) => keyBlocker.Dispose();
command.Execute(null);
}

public void ResetMachine() =>
DialogService.Instance.Warn(
"Reset Emulator?",
"This will simulate a restart of the ZX Spectrum.",
"CANCEL",
"RESET",
() => Speccy.TheCpu.ResetAsync(),
confirmed =>
{
if (confirmed)
Speccy.TheCpu.ResetAsync();
},
MaterialIconKind.Power);

public void SetCursorJoystick(bool b) =>
Expand Down

0 comments on commit 4442fdc

Please sign in to comment.