Skip to content

Commit

Permalink
Improved default undo method
Browse files Browse the repository at this point in the history
  • Loading branch information
flabbet committed Dec 14, 2021
1 parent f68b5ef commit 9cdfce6
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions PixiEditor/Models/Tools/BitmapOperationTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ public abstract class BitmapOperationTool : Tool

public override void BeforeUse()
{
if (UseDefaultUndoMethod)
if (UseDefaultUndoMethod && !RequiresPreviewLayer)
{
Document doc = ViewModels.ViewModelMain.Current.BitmapManager.ActiveDocument;
_change = new StorageBasedChange(doc, new[] { doc.ActiveLayer }, true);
InitializeStorageBasedChange();
}
}

Expand All @@ -36,12 +35,24 @@ public override void AfterUse()
{
if (!UseDefaultUndoMethod)
return;

if (RequiresPreviewLayer)
{
InitializeStorageBasedChange();
}

var document = ViewModels.ViewModelMain.Current.BitmapManager.ActiveDocument;
var args = new object[] { _change.Document };
document.UndoManager.AddUndoChange(_change.ToChange(UndoStorageBasedChange, args));
_change = null;
}

private void InitializeStorageBasedChange()
{
Document doc = ViewModels.ViewModelMain.Current.BitmapManager.ActiveDocument;
_change = new StorageBasedChange(doc, new[] {doc.ActiveLayer}, true);
}

private void UndoStorageBasedChange(Layer[] layers, UndoLayer[] data, object[] args)
{
Document document = (Document)args[0];
Expand Down

0 comments on commit 9cdfce6

Please sign in to comment.