From 23db624f29cf56e018b0e60f77af520bccf17ffa Mon Sep 17 00:00:00 2001 From: EX3 Date: Thu, 31 Oct 2024 21:07:28 +0900 Subject: [PATCH] Simplified Commands TODO 1. Simplify other commands too 2. Currently slider's undo&redo memento saving is triggered whenever it is edited - Needs to change triggering points into mouse pressed / mouse released --- Mirivoice/App.axaml.cs | 5 +- ...ineBoxReceiver.cs => AddLineBoxCommand.cs} | 14 ++-- ...oxesReceiver.cs => AddLineBoxesCommand.cs} | 26 +++---- ...ineBoxReceiver.cs => DelLineBoxCommand.cs} | 17 +++-- ...Receiver.cs => DuplicateLineBoxCommand.cs} | 11 ++- Mirivoice/Commands/LockLineBoxCommand.cs | 30 ++++++++ Mirivoice/Commands/LockLineBoxReceiver.cs | 28 -------- Mirivoice/Commands/MCommand.cs | 5 +- Mirivoice/Commands/MOriginator.cs | 1 + Mirivoice/Commands/MReceiver.cs | 1 + Mirivoice/Commands/Memento.cs | 2 + Mirivoice/Commands/MementoCommand.cs | 2 + Mirivoice/Commands/SetComboboxOriginator.cs | 25 ------- Mirivoice/Commands/SetProsodyCommand.cs | 55 ++++++++++++++ Mirivoice/Commands/TextBoxEditCommand.cs | 57 +++++++++++++++ Mirivoice/Commands/TextBoxEditOriginator.cs | 25 ------- .../Mirivoice.Core/Editor/MTextBoxEditor.cs | 72 ++++--------------- Mirivoice/Mirivoice.Core/Format/MResult.cs | 42 +++-------- Mirivoice/ViewModels/MainViewModel.cs | 29 +------- .../VoicerSelectingViewModelBase.cs | 9 ++- Mirivoice/Views/LineBoxView.axaml.cs | 15 ++-- Mirivoice/Views/MainView.axaml | 4 +- Mirivoice/Views/MainView.axaml.cs | 32 +++++++-- Mirivoice/Views/MainWindow.axaml | 2 +- 24 files changed, 253 insertions(+), 256 deletions(-) rename Mirivoice/Commands/{AddLineBoxReceiver.cs => AddLineBoxCommand.cs} (75%) rename Mirivoice/Commands/{AddLineBoxesReceiver.cs => AddLineBoxesCommand.cs} (92%) rename Mirivoice/Commands/{DelLineBoxReceiver.cs => DelLineBoxCommand.cs} (89%) rename Mirivoice/Commands/{DuplicateLineBoxReceiver.cs => DuplicateLineBoxCommand.cs} (88%) create mode 100644 Mirivoice/Commands/LockLineBoxCommand.cs delete mode 100644 Mirivoice/Commands/LockLineBoxReceiver.cs delete mode 100644 Mirivoice/Commands/SetComboboxOriginator.cs create mode 100644 Mirivoice/Commands/SetProsodyCommand.cs create mode 100644 Mirivoice/Commands/TextBoxEditCommand.cs delete mode 100644 Mirivoice/Commands/TextBoxEditOriginator.cs diff --git a/Mirivoice/App.axaml.cs b/Mirivoice/App.axaml.cs index 7b4c8f8..8f2234b 100644 --- a/Mirivoice/App.axaml.cs +++ b/Mirivoice/App.axaml.cs @@ -65,9 +65,10 @@ public override void OnFrameworkInitializationCompleted() } } - mainviewModel.OnPropertyChanged((mainviewModel.Title)); + mainWindow.Content = new MainView(mainviewModel); mainWindow.DataContext = mainviewModel; - desktop.MainWindow = mainWindow; + mainviewModel.OnPropertyChanged((mainviewModel.Title)); + desktop.MainWindow = mainWindow; } base.OnFrameworkInitializationCompleted(); diff --git a/Mirivoice/Commands/AddLineBoxReceiver.cs b/Mirivoice/Commands/AddLineBoxCommand.cs similarity index 75% rename from Mirivoice/Commands/AddLineBoxReceiver.cs rename to Mirivoice/Commands/AddLineBoxCommand.cs index 49a577e..a462b41 100644 --- a/Mirivoice/Commands/AddLineBoxReceiver.cs +++ b/Mirivoice/Commands/AddLineBoxCommand.cs @@ -3,21 +3,20 @@ namespace Mirivoice.Commands { - public class AddLineBoxReceiver : MReceiver + public class AddLineBoxCommand : ICommand { private readonly MainViewModel v; private int LineBoxIndexLastAdded; - public AddLineBoxReceiver(MainViewModel mainViewModel) + public AddLineBoxCommand(MainViewModel mainViewModel) { v = mainViewModel; } - public override void DoAction() + public void Execute(bool isRedoing) { - - var lineBox = new LineBoxView(v); + var lineBox = new LineBoxView(v); int LineNoToBeAdded = v.LineBoxCollection.Count + 1; - + lineBox.viewModel.SetLineNo(LineNoToBeAdded); lineBox.ShouldPhonemizeWhenSelected = true; @@ -26,7 +25,7 @@ public override void DoAction() lineBox.ScrollToEnd(); } - public override void UndoAction() + public void UnExecute() { if (LineBoxIndexLastAdded < 0) return; @@ -37,5 +36,6 @@ public override void UndoAction() } + } } diff --git a/Mirivoice/Commands/AddLineBoxesReceiver.cs b/Mirivoice/Commands/AddLineBoxesCommand.cs similarity index 92% rename from Mirivoice/Commands/AddLineBoxesReceiver.cs rename to Mirivoice/Commands/AddLineBoxesCommand.cs index 81371b9..f047dff 100644 --- a/Mirivoice/Commands/AddLineBoxesReceiver.cs +++ b/Mirivoice/Commands/AddLineBoxesCommand.cs @@ -10,7 +10,7 @@ namespace Mirivoice.Commands { - public class AddLineBoxesReceiver : MReceiver + public class AddLineBoxesCommand : ICommand { private MainViewModel v; private int InitialEndOfLineBoxCollection; @@ -20,23 +20,19 @@ public class AddLineBoxesReceiver : MReceiver int DefaultVoicerMetaOriginal; - public AddLineBoxesReceiver(MainViewModel mainViewModel) + public AddLineBoxesCommand(MainViewModel mainViewModel) { v = mainViewModel; InitialEndOfLineBoxCollection = v.LineBoxCollection.Count - 1; // if undo, remove all lineboxes after this index DefaultVoicerOriginal = MainManager.Instance.DefaultVoicerIndex; DefaultVoicerMetaOriginal = MainManager.Instance.DefaultMetaIndex; - } - public void SetScript(string newscript) // should be called when script is changed - { - script = newscript; + script = v.mTextBoxEditor.CurrentScript; InitialEndOfLineBoxCollection = v.LineBoxCollection.Count - 1; // if undo, remove all lineboxes after this index - } - public override void DoAction() + public void Execute(bool isRedoing) { string pattern = @"\[(?[^\]]+)\](?:\s*\((?