From 6da42de95203797d1bf5f8b7ee1534730bb50be3 Mon Sep 17 00:00:00 2001 From: Sander van Vliet Date: Tue, 21 Nov 2023 14:56:29 +0100 Subject: [PATCH] Handle aborts from the configure loop dialog --- .../DelegateDecorator.cs | 3 ++- .../DesignTimeWindowService.cs | 3 ++- src/RoadCaptain.App.RouteBuilder/IWindowService.cs | 3 ++- .../ViewModels/RouteSegmentListViewModel.cs | 5 +++++ .../ViewModels/RouteViewModel.cs | 2 ++ src/RoadCaptain.App.RouteBuilder/WindowService.cs | 12 ++++++------ 6 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/RoadCaptain.App.RouteBuilder/DelegateDecorator.cs b/src/RoadCaptain.App.RouteBuilder/DelegateDecorator.cs index bb0dcdff..18416772 100644 --- a/src/RoadCaptain.App.RouteBuilder/DelegateDecorator.cs +++ b/src/RoadCaptain.App.RouteBuilder/DelegateDecorator.cs @@ -85,7 +85,8 @@ public async Task ShowClearRouteDialog() return await InvokeIfNeededAsync(() => _decorated.ShowClearRouteDialog()); } - public async Task<(LoopMode Mode, int? NumberOfLoops)> ShowRouteLoopDialog(LoopMode? loopMode = null, int? numberOfLoops = null) + public async Task<(bool Success, LoopMode Mode, int? NumberOfLoops)> ShowRouteLoopDialog( + LoopMode? loopMode = null, int? numberOfLoops = null) { return await InvokeIfNeededAsync(() => _decorated.ShowRouteLoopDialog(loopMode, numberOfLoops)); } diff --git a/src/RoadCaptain.App.RouteBuilder/DesignTimeWindowService.cs b/src/RoadCaptain.App.RouteBuilder/DesignTimeWindowService.cs index b1041a75..fc548aff 100644 --- a/src/RoadCaptain.App.RouteBuilder/DesignTimeWindowService.cs +++ b/src/RoadCaptain.App.RouteBuilder/DesignTimeWindowService.cs @@ -79,7 +79,8 @@ public Task ShowClearRouteDialog() throw new System.NotImplementedException(); } - public Task<(LoopMode Mode, int? NumberOfLoops)> ShowRouteLoopDialog(LoopMode? loopMode = null, int? numberOfLoops = null) + public Task<(bool Success, LoopMode Mode, int? NumberOfLoops)> ShowRouteLoopDialog( + LoopMode? loopMode = null, int? numberOfLoops = null) { throw new System.NotImplementedException(); } diff --git a/src/RoadCaptain.App.RouteBuilder/IWindowService.cs b/src/RoadCaptain.App.RouteBuilder/IWindowService.cs index 35080364..cfb2fd4c 100644 --- a/src/RoadCaptain.App.RouteBuilder/IWindowService.cs +++ b/src/RoadCaptain.App.RouteBuilder/IWindowService.cs @@ -17,7 +17,8 @@ public interface IWindowService : RoadCaptain.App.Shared.IWindowService Task ShowDefaultSportSelectionDialog(SportType sport); Task ShowShouldSaveRouteDialog(); Task ShowClearRouteDialog(); - Task<(LoopMode Mode, int? NumberOfLoops)> ShowRouteLoopDialog(LoopMode? loopMode = null, int? numberOfLoops = null); + Task<(bool Success, LoopMode Mode, int? NumberOfLoops)> ShowRouteLoopDialog(LoopMode? loopMode = null, + int? numberOfLoops = null); Task ShowSaveRouteDialog(string? lastUsedFolder, RouteViewModel routeViewModel); Task ShowLogInDialog(Window owner); Window? GetCurrentWindow(); diff --git a/src/RoadCaptain.App.RouteBuilder/ViewModels/RouteSegmentListViewModel.cs b/src/RoadCaptain.App.RouteBuilder/ViewModels/RouteSegmentListViewModel.cs index d391c4cd..7ae4cfd0 100644 --- a/src/RoadCaptain.App.RouteBuilder/ViewModels/RouteSegmentListViewModel.cs +++ b/src/RoadCaptain.App.RouteBuilder/ViewModels/RouteSegmentListViewModel.cs @@ -29,6 +29,11 @@ private async Task ConfigureLoop() { var shouldCreateLoop = await _windowService.ShowRouteLoopDialog(Route.LoopMode, Route.NumberOfLoops); + if (!shouldCreateLoop.Success) + { + return CommandResult.Aborted(); + } + if (shouldCreateLoop.Mode is LoopMode.Infinite or LoopMode.Constrained) { Route.LoopMode = shouldCreateLoop.Mode; diff --git a/src/RoadCaptain.App.RouteBuilder/ViewModels/RouteViewModel.cs b/src/RoadCaptain.App.RouteBuilder/ViewModels/RouteViewModel.cs index 7a88bb47..72ce2a4c 100644 --- a/src/RoadCaptain.App.RouteBuilder/ViewModels/RouteViewModel.cs +++ b/src/RoadCaptain.App.RouteBuilder/ViewModels/RouteViewModel.cs @@ -109,6 +109,7 @@ public LoopMode LoopMode { if (value == _loopMode) return; _loopMode = value; + IsTainted = true; this.RaisePropertyChanged(); } } @@ -120,6 +121,7 @@ public int? NumberOfLoops { if (value == _numberOfLoops) return; _numberOfLoops = value; + IsTainted = true; this.RaisePropertyChanged(); } } diff --git a/src/RoadCaptain.App.RouteBuilder/WindowService.cs b/src/RoadCaptain.App.RouteBuilder/WindowService.cs index a2366524..c9f718b4 100644 --- a/src/RoadCaptain.App.RouteBuilder/WindowService.cs +++ b/src/RoadCaptain.App.RouteBuilder/WindowService.cs @@ -104,7 +104,7 @@ public async Task ShowClearRouteDialog() MessageBoxIcon.Question); } - public async Task<(LoopMode Mode, int? NumberOfLoops)> ShowRouteLoopDialog(LoopMode? loopMode = null, + public async Task<(bool Success, LoopMode Mode, int? NumberOfLoops)> ShowRouteLoopDialog(LoopMode? loopMode = null, int? numberOfLoops = null) { var makeLoopDialog = Resolve(); @@ -121,25 +121,25 @@ public async Task ShowClearRouteDialog() if (makeLoopDialog.DialogResult != DialogResult.Confirm) { - return (LoopMode.Unknown, null); + return (false, LoopMode.Unknown, null); } if (makeLoopDialogViewModel.NoLoop) { - return (LoopMode.Unknown, null); + return (true, LoopMode.Unknown, null); } if (makeLoopDialogViewModel.InfiniteLoop) { - return (LoopMode.Infinite, null); + return (true, LoopMode.Infinite, null); } if (makeLoopDialogViewModel.ConstrainedLoop) { - return (LoopMode.Constrained, makeLoopDialogViewModel.NumberOfLoops); + return (true, LoopMode.Constrained, makeLoopDialogViewModel.NumberOfLoops); } - return (LoopMode.Unknown, null); + return (true, LoopMode.Unknown, null); } public async Task ShowSaveRouteDialog(string? lastUsedFolder, RouteViewModel routeViewModel)