diff --git a/Mirivoice/Commands/SwapLineBoxReceiver.cs b/Mirivoice/Commands/SwapLineBoxCommand.cs similarity index 83% rename from Mirivoice/Commands/SwapLineBoxReceiver.cs rename to Mirivoice/Commands/SwapLineBoxCommand.cs index 6b6e9c9..4d2f0fc 100644 --- a/Mirivoice/Commands/SwapLineBoxReceiver.cs +++ b/Mirivoice/Commands/SwapLineBoxCommand.cs @@ -4,14 +4,14 @@ namespace Mirivoice.Commands { - public class SwapLineBoxReceiver: MReceiver + public class SwapLineBoxCommand: ICommand { private MainViewModel v; private int i1; private int i2; - public SwapLineBoxReceiver(MainViewModel mainViewModel) + public SwapLineBoxCommand(MainViewModel mainViewModel) { v = mainViewModel; } @@ -22,17 +22,16 @@ public void SetLineBoxesIdx(int i1, int i2) this.i2 = i2; } - public override void DoAction() + public void Execute(bool isRedoing) { LineBoxView t1 = v.LineBoxCollection[i1]; v.LineBoxCollection.RemoveAt(i1); v.LineBoxCollection.Insert(i2, t1); RefreshLineNos(); - } - public override void UndoAction() + public void UnExecute() { LineBoxView t1 = v.LineBoxCollection[i1]; v.LineBoxCollection.RemoveAt(i1); @@ -40,6 +39,7 @@ public override void UndoAction() RefreshLineNos(); } + void RefreshLineNos() { foreach (LineBoxView lineBox in v.LineBoxCollection) diff --git a/Mirivoice/Views/LineBoxView.axaml.cs b/Mirivoice/Views/LineBoxView.axaml.cs index edb99eb..3d234bb 100644 --- a/Mirivoice/Views/LineBoxView.axaml.cs +++ b/Mirivoice/Views/LineBoxView.axaml.cs @@ -189,7 +189,6 @@ public LineBoxView(MainViewModel v, string line="") //lockButton = this.FindControl("lockButton"); _currentCacheName = AudioManager.GetUniqueCachePath(); - SetCommands(v); mouseEntered = false; isDragging = false; @@ -236,7 +235,6 @@ public LineBoxView(MLinePrototype mLinePrototype, MainViewModel v, int index, in Exp = mLinePrototype.Exp; //lockButton = this.FindControl("lockButton"); - SetCommands(v); if (mLinePrototype.PhonemeEdit is not null || mLinePrototype.PhonemeEdit.Length > 0) { @@ -292,21 +290,12 @@ public LineBoxView(MLinePrototype mLinePrototype, MainViewModel v, int index, in } // Commands - public MCommand SwapLineBoxCommand { get; set; } - SwapLineBoxReceiver swapLineBoxReceiver; + //public MCommand LockLineBoxCommand { get; set; } //LockLineBoxReceiver lockLineBoxReceiver; - public void SetCommands(MainViewModel v) - { - - swapLineBoxReceiver = new SwapLineBoxReceiver(v); - SwapLineBoxCommand = new MCommand(swapLineBoxReceiver); - //lockLineBoxReceiver = new LockLineBoxReceiver(this); - //LockLineBoxCommand = new MCommand(lockLineBoxReceiver); - } public void ScrollToEnd() { @@ -704,9 +693,10 @@ private void OnDragEnd(object sender, PointerReleasedEventArgs e) if (v.LineBoxCollection.IndexOf(this) != targetIndex ) { - - swapLineBoxReceiver.SetLineBoxesIdx(v.LineBoxCollection.IndexOf(this), targetIndex); - + + + SwapLineBoxCommand SwapLineBoxCommand = new SwapLineBoxCommand(v); + SwapLineBoxCommand.SetLineBoxesIdx(v.LineBoxCollection.IndexOf(this), targetIndex); MainManager.Instance.cmd.ExecuteCommand(SwapLineBoxCommand); } }