Browse Source

Right click swapping after change finished

flabbet 11 months ago
parent
commit
4530e01459

+ 7 - 0
src/PixiEditor/Models/DocumentModels/ChangeExecutionController.cs

@@ -18,6 +18,8 @@ internal class ChangeExecutionController
     public VecI LastPixelPosition => lastPixelPos;
     public VecD LastPrecisePosition => lastPrecisePos;
     public bool IsChangeActive => currentSession is not null;
+    
+    public event Action ChangeFinished;
 
     private readonly IDocument document;
     private readonly IServiceProvider services;
@@ -101,6 +103,8 @@ internal class ChangeExecutionController
             throw new InvalidOperationException();
         currentSession = null;
         _queuedExecutor = null;
+        
+        ChangeFinished?.Invoke();
     }
 
     public bool TryStopActiveExecutor()
@@ -109,6 +113,8 @@ internal class ChangeExecutionController
             return false;
         currentSession.ForceStop();
         currentSession = null;
+        
+        ChangeFinished?.Invoke();
         return true;
     }
 
@@ -216,4 +222,5 @@ internal class ChangeExecutionController
     {
         currentSession?.OnColorChanged(color, false);
     }
+
 }

+ 4 - 0
src/PixiEditor/ViewModels/Document/DocumentViewModel.cs

@@ -61,6 +61,7 @@ internal partial class DocumentViewModel : PixiObservableObject, IDocument
 {
     public event EventHandler<LayersChangedEventArgs>? LayersChanged;
     public event EventHandler<DocumentSizeChangedEventArgs>? SizeChanged;
+    public event Action FinishedChange;
 
     private bool busy = false;
 
@@ -218,6 +219,8 @@ internal partial class DocumentViewModel : PixiObservableObject, IDocument
     {
         var serviceProvider = ViewModelMain.Current.Services;
         Internals = new DocumentInternalParts(this, serviceProvider);
+        Internals.ChangeController.ChangeFinished += () => FinishedChange?.Invoke();
+        
         Tools = new DocumentToolsModule(this, Internals);
         StructureHelper = new DocumentStructureModule(this);
         EventInlet = new DocumentEventsModule(this, Internals);
@@ -951,4 +954,5 @@ internal partial class DocumentViewModel : PixiObservableObject, IDocument
         Internals.Tracker.Dispose();
         Internals.Tracker.Document.Dispose();
     }
+
 }

+ 19 - 4
src/PixiEditor/ViewModels/SubViewModels/IoViewModel.cs

@@ -74,13 +74,13 @@ internal class IoViewModel : SubViewModel<ViewModelMain>
     {
         window.KeyDown += MainWindowKeyDown;
         window.KeyUp += MainWindowKeyUp;
-        
+
         window.Deactivated += keyboardFilter.DeactivatedInlet;
         window.Deactivated += mouseFilter.DeactivatedInlet;
-        
+
         window.Closing += HostWindowOnClosing;
     }
-    
+
     private void HostWindowOnClosing(object? sender, WindowClosingEventArgs e)
     {
         if (sender is not HostWindow hostWindow)
@@ -301,13 +301,28 @@ internal class IoViewModel : SubViewModel<ViewModelMain>
                                          }
                                         ):
 
-                Owner.ColorsSubViewModel.SwapColors(null);
+                if (!Owner.DocumentManagerSubViewModel.ActiveDocument.UpdateableChangeActive)
+                {
+                    Owner.ColorsSubViewModel.SwapColors(null);
+                }
+                else
+                {
+                    Owner.DocumentManagerSubViewModel.ActiveDocument.FinishedChange +=
+                        FinishedChange;
+                }
+
                 break;
             case MouseButton.Right when tools.RightClickMode == RightClickMode.Erase:
                 HandleRightMouseEraseUp(tools);
                 break;
         }
     }
+    
+    private void FinishedChange()
+    {
+        Owner.ColorsSubViewModel.SwapColors(null);
+        Owner.DocumentManagerSubViewModel.ActiveDocument.FinishedChange -= FinishedChange;
+    }
 
     private void HandleRightMouseEraseUp(IToolsHandler tools)
     {