Skip to content

Commit

Permalink
Simplified Commands
Browse files Browse the repository at this point in the history
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
  • Loading branch information
EX3exp committed Oct 31, 2024
1 parent 43ded8e commit 23db624
Show file tree
Hide file tree
Showing 24 changed files with 253 additions and 256 deletions.
5 changes: 3 additions & 2 deletions Mirivoice/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -26,7 +25,7 @@ public override void DoAction()
lineBox.ScrollToEnd();
}

public override void UndoAction()
public void UnExecute()
{
if (LineBoxIndexLastAdded < 0)
return;
Expand All @@ -37,5 +36,6 @@ public override void UndoAction()
}



}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Mirivoice.Commands
{
public class AddLineBoxesReceiver : MReceiver
public class AddLineBoxesCommand : ICommand
{
private MainViewModel v;
private int InitialEndOfLineBoxCollection;
Expand All @@ -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 = @"\[(?<nickname>[^\]]+)\](?:\s*\((?<style>[^\)]+)\))?";
var regex = new Regex(pattern);
Expand Down Expand Up @@ -72,7 +68,7 @@ public override void DoAction()
}
else
{

AddLineBox(line.Trim());
results.Add(line.Trim());
}
Expand All @@ -81,14 +77,21 @@ public override void DoAction()

MainManager.Instance.DefaultVoicerIndex = DefaultVoicerOriginal;
MainManager.Instance.DefaultMetaIndex = DefaultVoicerMetaOriginal;
}

public void SetScript(string newscript) // should be called when script is changed
{
script = newscript;
InitialEndOfLineBoxCollection = v.LineBoxCollection.Count - 1; // if undo, remove all lineboxes after this index

}

public override void UndoAction()

public void UnExecute()
{
for (int i = v.LineBoxCollection.Count - 1; i > InitialEndOfLineBoxCollection; i--)
{


if (v.CurrentLineBox == v.LineBoxCollection[i])
{
Expand All @@ -104,7 +107,6 @@ public override void UndoAction()
v.LineBoxCollection.RemoveAt(i);
}
}




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Mirivoice.Commands
{
public class DelLineBoxReceiver : MReceiver
public class DelLineBoxCommand : ICommand
{
private MainViewModel v;
private LineBoxView l;
Expand All @@ -21,13 +21,13 @@ public class DelLineBoxReceiver : MReceiver

private SingleLineEditorView lastEditor;

public DelLineBoxReceiver(MainViewModel mainViewModel, LineBoxView l)
public DelLineBoxCommand(MainViewModel mainViewModel, LineBoxView l)
{
this.l = l;
v = mainViewModel;
}

public override void DoAction()
public void Execute(bool isRedoing)
{
lastLineBox = l; // backup
LineBoxIndexLastDeleted = Int32.Parse(l.viewModel.LineNo) - 1;
Expand All @@ -36,7 +36,7 @@ public override void DoAction()
RefreshLineNos(control);




v.LineBoxCollection.RemoveAt(RemoveIndex);

Expand All @@ -46,8 +46,8 @@ public override void DoAction()
v.CurrentSingleLineEditor = null;
lastResults = new ObservableCollection<MResult>(l.MResultsCollection);
v.MResultsCollection.Clear();
if (v.CurrentEditIndex == 1)

if (v.CurrentEditIndex == 1)
{
v.CurrentEdit = null;
v.OnPropertyChanged(nameof(v.CurrentEdit));
Expand All @@ -56,12 +56,10 @@ public override void DoAction()

RefreshLineNos(control);
v.OnPropertyChanged(nameof(v.CurrentSingleLineEditor));

}

public override void UndoAction()
public void UnExecute()
{

v.LineBoxCollection.Insert(LineBoxIndexLastDeleted, lastLineBox);
RefreshLineNos(control);
if (lastEditor != null)
Expand All @@ -79,6 +77,7 @@ public override void UndoAction()

}
}


void RefreshLineNos(ItemsControl i)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

namespace Mirivoice.Commands
{
public class DuplicateLineBoxReceiver : MReceiver
public class DuplicateLineBoxCommand : ICommand
{
private LineBoxView l;
private int LineBoxIndexLastAdded;
public DuplicateLineBoxReceiver(LineBoxView l)
public DuplicateLineBoxCommand(LineBoxView l)
{
this.l = l;
}

public override void DoAction()
public void Execute(bool isRedoing)
{
MLinePrototype mLinePrototype = new MLinePrototype(l);
int LineNoToBeAdded = Int32.Parse(l.viewModel.LineNo);
Expand All @@ -31,16 +31,15 @@ public override void DoAction()
metaIndex++;
}
var lineBox = new LineBoxView(mLinePrototype, l.v, LineNoToBeAdded + 1, l.viewModel.voicerSelector.CurrentDefaultVoicerIndex, metaIndex, true);


l.v.LineBoxCollection.Insert(LineNoToBeAdded, lineBox);
LineBoxIndexLastAdded = LineNoToBeAdded;

RefreshLineNos();

}

public override void UndoAction()
public void UnExecute()
{
if (LineBoxIndexLastAdded < 0)
return;
Expand Down
30 changes: 30 additions & 0 deletions Mirivoice/Commands/LockLineBoxCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Mirivoice.Views;
using System;

namespace Mirivoice.Commands
{
[Obsolete("[still working class]")]
public class LockLineBoxCommand : ICommand
{
// Still implementing
LineBoxView l;

public LockLineBoxCommand(LineBoxView lineBoxView)
{
l = lineBoxView;
}


public void Execute(bool isRedoing)
{
l.UnLock(false);
}

public void UnExecute()
{
l.UnLock(true);
}


}
}
28 changes: 0 additions & 28 deletions Mirivoice/Commands/LockLineBoxReceiver.cs

This file was deleted.

5 changes: 4 additions & 1 deletion Mirivoice/Commands/MCommand.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
namespace Mirivoice.Commands
using System;

namespace Mirivoice.Commands
{
[Obsolete("This class will be obsolete, use ICommand instead")]
public class MCommand : ICommand
{
private readonly MReceiver _receiver;
Expand Down
1 change: 1 addition & 0 deletions Mirivoice/Commands/MOriginator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Mirivoice.Commands
{
[Obsolete("This class will be obsolete, use ICommand instead")]
public class MOriginator<T>
{
protected T obj;
Expand Down
1 change: 1 addition & 0 deletions Mirivoice/Commands/MReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Mirivoice.Commands
{
[Obsolete("This class will be obsolete, use ICommand instead")]
public abstract class MReceiver
{
protected readonly List<object> _data = new List<object>();
Expand Down
2 changes: 2 additions & 0 deletions Mirivoice/Commands/Memento.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public T Pop()
return states.Pop();
}

public bool CanPop => states.Count > 0;

public int Count => states.Count;
public override string ToString()
{
Expand Down
2 changes: 2 additions & 0 deletions Mirivoice/Commands/MementoCommand.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Serilog;
using System;

namespace Mirivoice.Commands
{
[Obsolete("This class will be obsolete, use ICommand with Memento instead")]
public class MementoCommand<T> : ICommand
{
// Handles undo/redo in combobox, textbox, etc.
Expand Down
25 changes: 0 additions & 25 deletions Mirivoice/Commands/SetComboboxOriginator.cs

This file was deleted.

Loading

0 comments on commit 23db624

Please sign in to comment.