From 48c15c4d2ddda68fcdaa754e6acd39a44ea056a8 Mon Sep 17 00:00:00 2001 From: Raphael Winkler Date: Sun, 17 Mar 2024 10:02:02 +0100 Subject: [PATCH] Disabled undo/redo commands as long as a dialog or the guide overlay is open --- SLC_LayoutEditor/Resources/patchnotes.txt | 1 + SLC_LayoutEditor/SLC_LayoutEditor.csproj | 1 + .../ViewModel/Commands/HistoryCommandBase.cs | 17 +++++++++++++++++ .../ViewModel/Commands/RedoCommand.cs | 4 ++-- .../ViewModel/Commands/UndoCommand.cs | 4 ++-- SLC_LayoutEditor/ViewModel/MainViewModel.cs | 5 +++++ 6 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 SLC_LayoutEditor/ViewModel/Commands/HistoryCommandBase.cs diff --git a/SLC_LayoutEditor/Resources/patchnotes.txt b/SLC_LayoutEditor/Resources/patchnotes.txt index c0353cc..00c5bf7 100644 --- a/SLC_LayoutEditor/Resources/patchnotes.txt +++ b/SLC_LayoutEditor/Resources/patchnotes.txt @@ -2,6 +2,7 @@ Added: You can now manage pre-packaged templates either via "Editor" -> "Manage default templates" or via the settings Added: Two new default templates have been added ("B744 - Boeing 747-400" and "B748 - Boeing 747-8i") Changed: Added some more logging to the undo/redo system +Changed: The undo and redo commands (Ctrl+Z and Ctrl+Y) are now only available if no dialog or guide overlay is open or the current view is not the editor (e.g. settings) Fixed: Potential fix for a crash when undoing/redoing a step Fixed: "Rows" and "Columns" texts have been swapped Fixed: When undoing or redoing multiple steps, the editor no longer checks for issues for every step \ No newline at end of file diff --git a/SLC_LayoutEditor/SLC_LayoutEditor.csproj b/SLC_LayoutEditor/SLC_LayoutEditor.csproj index 14c720d..8f3296a 100644 --- a/SLC_LayoutEditor/SLC_LayoutEditor.csproj +++ b/SLC_LayoutEditor/SLC_LayoutEditor.csproj @@ -288,6 +288,7 @@ + diff --git a/SLC_LayoutEditor/ViewModel/Commands/HistoryCommandBase.cs b/SLC_LayoutEditor/ViewModel/Commands/HistoryCommandBase.cs new file mode 100644 index 0000000..f17a061 --- /dev/null +++ b/SLC_LayoutEditor/ViewModel/Commands/HistoryCommandBase.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tasty.ViewModel.Commands; + +namespace SLC_LayoutEditor.ViewModel.Commands +{ + internal class HistoryCommandBase : CommandBase + { + public override bool CanExecute(object parameter) + { + return parameter is MainViewModel vm && vm.AllowHistoryCommands; + } + } +} diff --git a/SLC_LayoutEditor/ViewModel/Commands/RedoCommand.cs b/SLC_LayoutEditor/ViewModel/Commands/RedoCommand.cs index 2ebdc1b..57747c8 100644 --- a/SLC_LayoutEditor/ViewModel/Commands/RedoCommand.cs +++ b/SLC_LayoutEditor/ViewModel/Commands/RedoCommand.cs @@ -7,11 +7,11 @@ namespace SLC_LayoutEditor.ViewModel.Commands { - internal class RedoCommand : CommandBase + internal class RedoCommand : HistoryCommandBase { public override bool CanExecute(object parameter) { - return parameter is MainViewModel vm && !vm.IsViewNotEditor && vm.History.CanRedo; + return base.CanExecute(parameter) && parameter is MainViewModel vm && vm.History.CanRedo; } public override void Execute(object parameter) diff --git a/SLC_LayoutEditor/ViewModel/Commands/UndoCommand.cs b/SLC_LayoutEditor/ViewModel/Commands/UndoCommand.cs index 4e19bcf..535c5a8 100644 --- a/SLC_LayoutEditor/ViewModel/Commands/UndoCommand.cs +++ b/SLC_LayoutEditor/ViewModel/Commands/UndoCommand.cs @@ -7,11 +7,11 @@ namespace SLC_LayoutEditor.ViewModel.Commands { - internal class UndoCommand : CommandBase + internal class UndoCommand : HistoryCommandBase { public override bool CanExecute(object parameter) { - return parameter is MainViewModel vm && !vm.IsViewNotEditor && vm.History.CanUndo; + return base.CanExecute(parameter) && parameter is MainViewModel vm && vm.History.CanUndo; } public override void Execute(object parameter) diff --git a/SLC_LayoutEditor/ViewModel/MainViewModel.cs b/SLC_LayoutEditor/ViewModel/MainViewModel.cs index 0cc1f80..eadebef 100644 --- a/SLC_LayoutEditor/ViewModel/MainViewModel.cs +++ b/SLC_LayoutEditor/ViewModel/MainViewModel.cs @@ -262,6 +262,8 @@ public CabinDeckControl SelectedDeck } } + public bool AllowHistoryCommands => !IsViewNotEditor && !IsDialogOpen && !mIsGuideOpen; + public bool IsViewNotEditor => !(mContent is LayoutEditor) && App.Settings.WelcomeScreenShown; public bool IsTourRunning => App.GuidedTour?.IsTourRunning ?? false; @@ -276,6 +278,9 @@ public CabinDeckControl SelectedDeck public int MaxSteps => FixedValues.TOTAL_TOUR_STEPS; + /// + /// Defines if any is currently open + /// public bool IsGuideOpen { get => mIsGuideOpen;