|
@@ -8,14 +8,9 @@ namespace PixiEditor.ViewModels.SubViewModels.Main;
|
|
|
[Command.Group("PixiEditor.Undo", "Undo")]
|
|
|
internal class UndoViewModel : SubViewModel<ViewModelMain>
|
|
|
{
|
|
|
- public event EventHandler UndoRedoCalled;
|
|
|
-
|
|
|
public UndoViewModel(ViewModelMain owner)
|
|
|
: base(owner)
|
|
|
{
|
|
|
- //var result = Directory.CreateDirectory(StorageBasedChange.DefaultUndoChangeLocation);
|
|
|
-
|
|
|
- //ClearUndoTempDirectory();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -25,14 +20,10 @@ internal class UndoViewModel : SubViewModel<ViewModelMain>
|
|
|
IconPath = "E7A6", IconEvaluator = "PixiEditor.FontIcon")]
|
|
|
public void Redo()
|
|
|
{
|
|
|
- UndoRedoCalled?.Invoke(this, EventArgs.Empty);
|
|
|
-
|
|
|
- //sometimes CanRedo gets changed after UndoRedoCalled invoke, so check again (normally this is checked by the relaycommand)
|
|
|
- if (CanRedo())
|
|
|
- {
|
|
|
- //Owner.BitmapManager.ActiveDocument.UndoManager.Redo();
|
|
|
- //Owner.BitmapManager.ActiveDocument.ChangesSaved = false;
|
|
|
- }
|
|
|
+ var doc = Owner.DocumentManagerSubViewModel.ActiveDocument;
|
|
|
+ if (doc is null || doc.UpdateableChangeActive || !doc.HasSavedRedo)
|
|
|
+ return;
|
|
|
+ doc.Redo();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -42,26 +33,10 @@ internal class UndoViewModel : SubViewModel<ViewModelMain>
|
|
|
IconPath = "E7A7", IconEvaluator = "PixiEditor.FontIcon")]
|
|
|
public void Undo()
|
|
|
{
|
|
|
- UndoRedoCalled?.Invoke(this, EventArgs.Empty);
|
|
|
-
|
|
|
- //sometimes CanUndo gets changed after UndoRedoCalled invoke, so check again (normally this is checked by the relaycommand)
|
|
|
- if (CanUndo())
|
|
|
- {
|
|
|
- //Owner.BitmapManager.ActiveDocument.UndoManager.Undo();
|
|
|
- //Owner.BitmapManager.ActiveDocument.ChangesSaved = false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// Removes all files from %tmp%/PixiEditor/UndoStack/.
|
|
|
- /// </summary>
|
|
|
- public void ClearUndoTempDirectory()
|
|
|
- {
|
|
|
- /*DirectoryInfo dirInfo = new DirectoryInfo(StorageBasedChange.DefaultUndoChangeLocation);
|
|
|
- foreach (FileInfo file in dirInfo.GetFiles())
|
|
|
- {
|
|
|
- file.Delete();
|
|
|
- }*/
|
|
|
+ var doc = Owner.DocumentManagerSubViewModel.ActiveDocument;
|
|
|
+ if (doc is null || doc.UpdateableChangeActive || !doc.HasSavedUndo)
|
|
|
+ return;
|
|
|
+ doc.Undo();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -72,7 +47,10 @@ internal class UndoViewModel : SubViewModel<ViewModelMain>
|
|
|
[Evaluator.CanExecute("PixiEditor.Undo.CanUndo")]
|
|
|
public bool CanUndo()
|
|
|
{
|
|
|
- return false;
|
|
|
+ var doc = Owner.DocumentManagerSubViewModel.ActiveDocument;
|
|
|
+ if (doc is null)
|
|
|
+ return false;
|
|
|
+ return !doc.UpdateableChangeActive && doc.HasSavedUndo;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -83,6 +61,9 @@ internal class UndoViewModel : SubViewModel<ViewModelMain>
|
|
|
[Evaluator.CanExecute("PixiEditor.Undo.CanRedo")]
|
|
|
public bool CanRedo()
|
|
|
{
|
|
|
- return false;
|
|
|
+ var doc = Owner.DocumentManagerSubViewModel.ActiveDocument;
|
|
|
+ if (doc is null)
|
|
|
+ return false;
|
|
|
+ return !doc.UpdateableChangeActive && doc.HasSavedRedo;
|
|
|
}
|
|
|
}
|