Skip to content

Commit

Permalink
Terminate ToolSession on undo/redo (fix #296)
Browse files Browse the repository at this point in the history
  • Loading branch information
Equbuxu committed Dec 18, 2021
1 parent 2062c58 commit ffe2eab
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
4 changes: 3 additions & 1 deletion PixiEditor/Models/Controllers/BitmapManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public bool OnlyReferenceLayer
private ToolSession activeSession = null;


public BitmapManager(ToolsViewModel tools)
public BitmapManager(ToolsViewModel tools, UndoViewModel undo)
{
_tools = tools;

Expand All @@ -98,6 +98,8 @@ public BitmapManager(ToolsViewModel tools)
ToolSessionController.KeyStateChanged += (_, _) => UpdateActionDisplay(_tools.ActiveTool);
BitmapOperations = new BitmapOperationsUtility(this, tools);

undo.UndoRedoCalled += (_, _) => ToolSessionController.ForceStopActiveSessionIfAny();

DocumentChanged += BitmapManager_DocumentChanged;

_highlightPen = new PenTool(this)
Expand Down
6 changes: 3 additions & 3 deletions PixiEditor/Models/Controllers/UndoManager.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using PixiEditor.Models.Undo;
using PixiEditor.ViewModels;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using PixiEditor.Models.Undo;
using PixiEditor.ViewModels;

namespace PixiEditor.Models.Controllers
{
Expand Down Expand Up @@ -210,4 +210,4 @@ private void SetPropertyValue(object target, string propName, object value)
return new Tuple<PropertyInfo, object>(target.GetType().GetProperty(bits.Last()), target);
}
}
}
}
15 changes: 13 additions & 2 deletions PixiEditor/ViewModels/SubViewModels/Main/UndoViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using PixiEditor.Helpers;
using PixiEditor.Models.Undo;
using System;
using System.IO;

namespace PixiEditor.ViewModels.SubViewModels.Main
Expand All @@ -10,6 +11,8 @@ public class UndoViewModel : SubViewModel<ViewModelMain>

public RelayCommand RedoCommand { get; set; }

public event EventHandler UndoRedoCalled;

public UndoViewModel(ViewModelMain owner)
: base(owner)
{
Expand All @@ -29,7 +32,11 @@ public UndoViewModel(ViewModelMain owner)
/// <param name="parameter">CommandProperty.</param>
public void Redo(object parameter)
{
Owner.BitmapManager.ActiveDocument.UndoManager.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(null))
Owner.BitmapManager.ActiveDocument.UndoManager.Redo();
}

/// <summary>
Expand All @@ -38,7 +45,11 @@ public void Redo(object parameter)
/// <param name="parameter">CommandParameter.</param>
public void Undo(object parameter)
{
Owner.BitmapManager.ActiveDocument.UndoManager.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(null))
Owner.BitmapManager.ActiveDocument.UndoManager.Undo();
}

/// <summary>
Expand Down

0 comments on commit ffe2eab

Please sign in to comment.