Skip to content

Commit

Permalink
TODO simplify other commands too
Browse files Browse the repository at this point in the history
  • Loading branch information
EX3exp committed Nov 6, 2024
1 parent 23db624 commit a2d1138
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -22,24 +22,24 @@ 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);
v.LineBoxCollection.Insert(i2, t1);

RefreshLineNos();
}

void RefreshLineNos()
{
foreach (LineBoxView lineBox in v.LineBoxCollection)
Expand Down
20 changes: 5 additions & 15 deletions Mirivoice/Views/LineBoxView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ public LineBoxView(MainViewModel v, string line="")
//lockButton = this.FindControl<ToggleButton>("lockButton");
_currentCacheName = AudioManager.GetUniqueCachePath();

SetCommands(v);
mouseEntered = false;
isDragging = false;

Expand Down Expand Up @@ -236,7 +235,6 @@ public LineBoxView(MLinePrototype mLinePrototype, MainViewModel v, int index, in
Exp = mLinePrototype.Exp;

//lockButton = this.FindControl<ToggleButton>("lockButton");
SetCommands(v);

if (mLinePrototype.PhonemeEdit is not null || mLinePrototype.PhonemeEdit.Length > 0)
{
Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit a2d1138

Please sign in to comment.