Skip to content

Commit

Permalink
Handle aborts from the configure loop dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
sandermvanvliet committed Nov 21, 2023
1 parent 53f5ea6 commit 6da42de
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/RoadCaptain.App.RouteBuilder/DelegateDecorator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public async Task<MessageBoxResult> 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));
}
Expand Down
3 changes: 2 additions & 1 deletion src/RoadCaptain.App.RouteBuilder/DesignTimeWindowService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public Task<MessageBoxResult> 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();
}
Expand Down
3 changes: 2 additions & 1 deletion src/RoadCaptain.App.RouteBuilder/IWindowService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public interface IWindowService : RoadCaptain.App.Shared.IWindowService
Task<bool> ShowDefaultSportSelectionDialog(SportType sport);
Task<MessageBoxResult> ShowShouldSaveRouteDialog();
Task<MessageBoxResult> 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<TokenResponse?> ShowLogInDialog(Window owner);
Window? GetCurrentWindow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ private async Task<CommandResult> 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;
Expand Down
2 changes: 2 additions & 0 deletions src/RoadCaptain.App.RouteBuilder/ViewModels/RouteViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public LoopMode LoopMode
{
if (value == _loopMode) return;
_loopMode = value;
IsTainted = true;
this.RaisePropertyChanged();
}
}
Expand All @@ -120,6 +121,7 @@ public int? NumberOfLoops
{
if (value == _numberOfLoops) return;
_numberOfLoops = value;
IsTainted = true;
this.RaisePropertyChanged();
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/RoadCaptain.App.RouteBuilder/WindowService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public async Task<MessageBoxResult> 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<MakeLoopDialog>();
Expand All @@ -121,25 +121,25 @@ public async Task<MessageBoxResult> 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)
Expand Down

0 comments on commit 6da42de

Please sign in to comment.