diff --git a/src/ParallelSpace/App.axaml.cs b/src/ParallelSpace/App.axaml.cs index 147efe5..3904c4d 100644 --- a/src/ParallelSpace/App.axaml.cs +++ b/src/ParallelSpace/App.axaml.cs @@ -28,12 +28,17 @@ public override void OnFrameworkInitializationCompleted() var window = new MainWindow { DataContext = vm }; - // Wire the add/edit dialog now that both window and view model exist. + // Wire dialogs now that both window and view model exist. vm.ShowEditor = async editor => { var dialog = new EditSpaceWindow { DataContext = editor }; return await dialog.ShowDialog(window); }; + vm.ShowConfirmation = async (title, message) => + { + var dialog = new ConfirmActionWindow(title, message); + return await dialog.ShowDialog(window); + }; desktop.MainWindow = window; desktop.ShutdownRequested += (_, _) => launcher.Dispose(); @@ -42,3 +47,4 @@ public override void OnFrameworkInitializationCompleted() base.OnFrameworkInitializationCompleted(); } } + diff --git a/src/ParallelSpace/ViewModels/MainWindowViewModel.cs b/src/ParallelSpace/ViewModels/MainWindowViewModel.cs index 31d58fd..086aa6f 100644 --- a/src/ParallelSpace/ViewModels/MainWindowViewModel.cs +++ b/src/ParallelSpace/ViewModels/MainWindowViewModel.cs @@ -27,6 +27,9 @@ public sealed partial class MainWindowViewModel : ObservableObject /// Set by the app: shows the add/edit dialog and returns true if saved. public Func>? ShowEditor { get; set; } + /// Set by the app: shows a confirmation dialog and returns true if accepted. + public Func>? ShowConfirmation { get; set; } + [ObservableProperty] private string _statusMessage = "Ready."; [ObservableProperty] private bool _hasDetectedApps; [ObservableProperty] private NavPage _selectedPage = NavPage.Spaces; @@ -344,15 +347,25 @@ public void LaunchSpace(SpaceViewModel vm) RefreshStatuses(); } - public void CloseSpace(SpaceViewModel vm) + public async Task CloseSpace(SpaceViewModel vm) { + if (ShowConfirmation is null || !await ShowConfirmation( + "Close application?", + "This application will be closed. You may need to sign in again the next time you launch it.")) + return; + _launcher.CloseAll(vm.Model); StatusMessage = $"Closed {vm.Name}."; RefreshStatuses(); } - public void RemoveSpace(SpaceViewModel vm) + public async Task RemoveSpace(SpaceViewModel vm) { + if (ShowConfirmation is null || !await ShowConfirmation( + "Remove application?", + "This application will be removed from your Spaces list. Its profile data folder will remain on your device.")) + return; + var index = Spaces.IndexOf(vm); Spaces.Remove(vm); @@ -413,3 +426,4 @@ private void OpenUrl(string url) catch (Exception ex) { StatusMessage = $"Couldn't open browser: {ex.Message}"; } } } + diff --git a/src/ParallelSpace/ViewModels/SpaceViewModel.cs b/src/ParallelSpace/ViewModels/SpaceViewModel.cs index 8658aca..55db263 100644 --- a/src/ParallelSpace/ViewModels/SpaceViewModel.cs +++ b/src/ParallelSpace/ViewModels/SpaceViewModel.cs @@ -90,11 +90,12 @@ public void NotifyEdited() private bool CanClose() => IsRunning; [RelayCommand(CanExecute = nameof(CanClose))] - private void Close() => _owner.CloseSpace(this); + private Task Close() => _owner.CloseSpace(this); [RelayCommand] private void OpenDataFolder() => _owner.OpenDataFolder(this); [RelayCommand] - private void Remove() => _owner.RemoveSpace(this); + private Task Remove() => _owner.RemoveSpace(this); } + diff --git a/src/ParallelSpace/Views/ConfirmActionWindow.axaml b/src/ParallelSpace/Views/ConfirmActionWindow.axaml new file mode 100644 index 0000000..5a5ced9 --- /dev/null +++ b/src/ParallelSpace/Views/ConfirmActionWindow.axaml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + +