Browse Source

Added blocking change concept

flabbet 10 months ago
parent
commit
37ad54507b

+ 1 - 1
src/PixiEditor/Models/DocumentModels/ChangeExecutionController.cs

@@ -17,7 +17,7 @@ internal class ChangeExecutionController
     public ShapeCorners LastTransformState { get; private set; }
     public VecI LastPixelPosition => lastPixelPos;
     public VecD LastPrecisePosition => lastPrecisePos;
-    public bool IsChangeActive => currentSession is not null;
+    public bool IsBlockingChangeActive => currentSession is not null && currentSession.BlocksOtherActions;
     
     public event Action ToolSessionFinished;
 

+ 34 - 34
src/PixiEditor/Models/DocumentModels/Public/DocumentOperationsModule.cs

@@ -41,7 +41,7 @@ internal class DocumentOperationsModule : IDocumentOperations
     /// </summary>
     public void Select(RectI rect, SelectionMode mode = SelectionMode.New)
     {
-        if (Internals.ChangeController.IsChangeActive)
+        if (Internals.ChangeController.IsBlockingChangeActive)
             return;
         Internals.ActionAccumulator.AddFinishedActions(
             new SelectRectangle_Action(rect, mode),
@@ -53,7 +53,7 @@ internal class DocumentOperationsModule : IDocumentOperations
     /// </summary>
     public void ClearSelection()
     {
-        if (Internals.ChangeController.IsChangeActive)
+        if (Internals.ChangeController.IsBlockingChangeActive)
             return;
         Internals.ActionAccumulator.AddFinishedActions(new ClearSelection_Action());
     }
@@ -65,7 +65,7 @@ internal class DocumentOperationsModule : IDocumentOperations
     public void DeleteSelectedPixels(int frame, bool clearSelection = false)
     {
         var member = Document.SelectedStructureMember;
-        if (Internals.ChangeController.IsChangeActive || member is null)
+        if (Internals.ChangeController.IsBlockingChangeActive || member is null)
             return;
         bool drawOnMask = member is not ILayerHandler layer || layer.ShouldDrawOnMask;
         if (drawOnMask && !member.HasMaskBindable)
@@ -83,7 +83,7 @@ internal class DocumentOperationsModule : IDocumentOperations
     /// <param name="value">A value between 0 and 1</param>
     public void SetMemberOpacity(Guid memberGuid, float value)
     {
-        if (Internals.ChangeController.IsChangeActive || value is > 1 or < 0)
+        if (Internals.ChangeController.IsBlockingChangeActive || value is > 1 or < 0)
             return;
         Internals.ActionAccumulator.AddFinishedActions(
             new StructureMemberOpacity_Action(memberGuid, value),
@@ -108,7 +108,7 @@ internal class DocumentOperationsModule : IDocumentOperations
     /// </summary>
     public void ClearUndo()
     {
-        if (Internals.ChangeController.IsChangeActive)
+        if (Internals.ChangeController.IsBlockingChangeActive)
             return;
         Internals.ActionAccumulator.AddActions(new DeleteRecordedChanges_Action());
     }
@@ -119,7 +119,7 @@ internal class DocumentOperationsModule : IDocumentOperations
     /// <param name="images">The images to paste</param>
     public void PasteImagesAsLayers(List<DataImage> images, int frame)
     {
-        if (Internals.ChangeController.IsChangeActive)
+        if (Internals.ChangeController.IsBlockingChangeActive)
             return;
 
         RectI maxSize = new RectI(VecI.Zero, Document.SizeBindable);
@@ -151,14 +151,14 @@ internal class DocumentOperationsModule : IDocumentOperations
     /// <returns>The Guid of the new structure member or null if there is already an active change</returns>
     public Guid? CreateStructureMember(StructureMemberType type, string? name = null, bool finish = true)
     {
-        if (Internals.ChangeController.IsChangeActive)
+        if (Internals.ChangeController.IsBlockingChangeActive)
             return null;
         return Internals.StructureHelper.CreateNewStructureMember(type, name, finish);
     }
 
     public Guid? CreateStructureMember(Type structureMemberType, string? name = null, bool finish = true)
     {
-        if (Internals.ChangeController.IsChangeActive)
+        if (Internals.ChangeController.IsBlockingChangeActive)
             return null;
         
         return Internals.StructureHelper.CreateNewStructureMember(structureMemberType, name, finish);
@@ -170,7 +170,7 @@ internal class DocumentOperationsModule : IDocumentOperations
     /// <param name="guidValue">The Guid of the layer</param>
     public void DuplicateLayer(Guid guidValue)
     {
-        if (Internals.ChangeController.IsChangeActive)
+        if (Internals.ChangeController.IsBlockingChangeActive)
             return;
         Internals.ActionAccumulator.AddFinishedActions(new DuplicateLayer_Action(guidValue));
     }
@@ -181,7 +181,7 @@ internal class DocumentOperationsModule : IDocumentOperations
     /// <param name="guidValue">The Guid of the layer</param>
     public void DeleteStructureMember(Guid guidValue)
     {
-        if (Internals.ChangeController.IsChangeActive)
+        if (Internals.ChangeController.IsBlockingChangeActive)
             return;
         Internals.ActionAccumulator.AddFinishedActions(new DeleteStructureMember_Action(guidValue));
     }
@@ -192,7 +192,7 @@ internal class DocumentOperationsModule : IDocumentOperations
     /// <param name="guids">The Guids of the layers to delete</param>
     public void DeleteStructureMembers(IReadOnlyList<Guid> guids, bool selectNext = true)
     {
-        if (Internals.ChangeController.IsChangeActive)
+        if (Internals.ChangeController.IsBlockingChangeActive)
             return;
 
         Guid closestMember = FindClosestMember(guids);
@@ -221,7 +221,7 @@ internal class DocumentOperationsModule : IDocumentOperations
     /// <param name="anchor">Where the existing content should be put</param>
     public void ResizeCanvas(VecI newSize, ResizeAnchor anchor)
     {
-        if (Internals.ChangeController.IsChangeActive || newSize.X > 9999 || newSize.Y > 9999 || newSize.X < 1 ||
+        if (Internals.ChangeController.IsBlockingChangeActive || newSize.X > 9999 || newSize.Y > 9999 || newSize.X < 1 ||
             newSize.Y < 1)
             return;
 
@@ -250,7 +250,7 @@ internal class DocumentOperationsModule : IDocumentOperations
     /// <param name="resampling">The resampling method to use</param>
     public void ResizeImage(VecI newSize, ResamplingMethod resampling)
     {
-        if (Internals.ChangeController.IsChangeActive || newSize.X > 9999 || newSize.Y > 9999 || newSize.X < 1 ||
+        if (Internals.ChangeController.IsBlockingChangeActive || newSize.X > 9999 || newSize.Y > 9999 || newSize.X < 1 ||
             newSize.Y < 1)
             return;
 
@@ -279,7 +279,7 @@ internal class DocumentOperationsModule : IDocumentOperations
     /// <param name="newColor">The new color</param>
     public void ReplaceColor(PaletteColor oldColor, PaletteColor newColor, int frame)
     {
-        if (Internals.ChangeController.IsChangeActive || oldColor == newColor)
+        if (Internals.ChangeController.IsBlockingChangeActive || oldColor == newColor)
             return;
 
         Internals.ActionAccumulator.AddFinishedActions(new ReplaceColor_Action(oldColor.ToColor(), newColor.ToColor(),
@@ -302,7 +302,7 @@ internal class DocumentOperationsModule : IDocumentOperations
     /// </summary>
     public void CreateMask(IStructureMemberHandler member)
     {
-        if (Internals.ChangeController.IsChangeActive)
+        if (Internals.ChangeController.IsBlockingChangeActive)
             return;
         if (!member.MaskIsVisibleBindable)
             Internals.ActionAccumulator.AddActions(new StructureMemberMaskIsVisible_Action(true, member.Id));
@@ -314,7 +314,7 @@ internal class DocumentOperationsModule : IDocumentOperations
     /// </summary>
     public void DeleteMask(IStructureMemberHandler member)
     {
-        if (Internals.ChangeController.IsChangeActive)
+        if (Internals.ChangeController.IsBlockingChangeActive)
             return;
         Internals.ActionAccumulator.AddFinishedActions(new DeleteStructureMemberMask_Action(member.Id));
     }
@@ -324,7 +324,7 @@ internal class DocumentOperationsModule : IDocumentOperations
     /// </summary>
     public void ApplyMask(IStructureMemberHandler member, int frame)
     {
-        if (Internals.ChangeController.IsChangeActive)
+        if (Internals.ChangeController.IsBlockingChangeActive)
             return;
 
         Internals.ActionAccumulator.AddFinishedActions(new ApplyMask_Action(member.Id, frame),
@@ -375,7 +375,7 @@ internal class DocumentOperationsModule : IDocumentOperations
     /// </summary>
     public void Undo()
     {
-        if (Internals.ChangeController.IsChangeActive)
+        if (Internals.ChangeController.IsBlockingChangeActive)
         {
             Internals.ChangeController.MidChangeUndoInlet();
             return;
@@ -389,7 +389,7 @@ internal class DocumentOperationsModule : IDocumentOperations
     /// </summary>
     public void Redo()
     {
-        if (Internals.ChangeController.IsChangeActive)
+        if (Internals.ChangeController.IsBlockingChangeActive)
         {
             Internals.ChangeController.MidChangeRedoInlet();
             return;
@@ -400,7 +400,7 @@ internal class DocumentOperationsModule : IDocumentOperations
 
     public void NudgeSelectedObject(VecI distance)
     {
-        if (Internals.ChangeController.IsChangeActive)
+        if (Internals.ChangeController.IsBlockingChangeActive)
         {
             Internals.ChangeController.SelectedObjectNudgedInlet(distance);
         }
@@ -415,7 +415,7 @@ internal class DocumentOperationsModule : IDocumentOperations
     public void MoveStructureMember(Guid memberToMove, Guid memberToMoveIntoOrNextTo,
         StructureMemberPlacement placement)
     {
-        if (Internals.ChangeController.IsChangeActive || memberToMove == memberToMoveIntoOrNextTo)
+        if (Internals.ChangeController.IsBlockingChangeActive || memberToMove == memberToMoveIntoOrNextTo)
             return;
         Internals.StructureHelper.TryMoveStructureMember(memberToMove, memberToMoveIntoOrNextTo, placement);
     }
@@ -425,7 +425,7 @@ internal class DocumentOperationsModule : IDocumentOperations
     /// </summary>
     public void MergeStructureMembers(IReadOnlyList<Guid> members)
     {
-        if (Internals.ChangeController.IsChangeActive || members.Count < 2)
+        if (Internals.ChangeController.IsBlockingChangeActive || members.Count < 2)
             return;
 
         IStructureMemberHandler? node = Document.StructureHelper.FindNode<IStructureMemberHandler>(members[0]);
@@ -491,7 +491,7 @@ internal class DocumentOperationsModule : IDocumentOperations
     public void TransformSelectedArea(bool toolLinked)
     {
         if (Document.SelectedStructureMember is null ||
-            Internals.ChangeController.IsChangeActive && !toolLinked)
+            Internals.ChangeController.IsBlockingChangeActive && !toolLinked)
             return;
         Internals.ChangeController.TryStartExecutor(new TransformSelectedExecutor(toolLinked));
     }
@@ -521,7 +521,7 @@ internal class DocumentOperationsModule : IDocumentOperations
     private void DrawImage(Surface image, ShapeCorners corners, Guid memberGuid, bool ignoreClipSymmetriesEtc,
         bool drawOnMask, int atFrame, bool finish)
     {
-        if (Internals.ChangeController.IsChangeActive)
+        if (Internals.ChangeController.IsBlockingChangeActive)
             return;
         Internals.ActionAccumulator.AddActions(
             new PasteImage_Action(image, corners, memberGuid, ignoreClipSymmetriesEtc, drawOnMask, atFrame, default),
@@ -535,7 +535,7 @@ internal class DocumentOperationsModule : IDocumentOperations
     /// </summary>
     public void ClipCanvas()
     {
-        if (Internals.ChangeController.IsChangeActive)
+        if (Internals.ChangeController.IsBlockingChangeActive)
             return;
         Internals.ActionAccumulator.AddFinishedActions(
             new ClipCanvas_Action(Document.AnimationHandler.ActiveFrameBindable));
@@ -551,7 +551,7 @@ internal class DocumentOperationsModule : IDocumentOperations
     /// </summary>
     public void FlipImage(FlipType flipType, List<Guid> membersToFlip, int frame)
     {
-        if (Internals.ChangeController.IsChangeActive)
+        if (Internals.ChangeController.IsBlockingChangeActive)
             return;
 
         Internals.ActionAccumulator.AddFinishedActions(new FlipImage_Action(flipType, frame, membersToFlip));
@@ -569,7 +569,7 @@ internal class DocumentOperationsModule : IDocumentOperations
     /// <param name="rotation">The degrees to rotate the members by</param>
     public void RotateImage(RotationAngle rotation, List<Guid> membersToRotate, int frame)
     {
-        if (Internals.ChangeController.IsChangeActive)
+        if (Internals.ChangeController.IsBlockingChangeActive)
             return;
 
         Internals.ActionAccumulator.AddFinishedActions(new RotateImage_Action(rotation, membersToRotate, frame));
@@ -580,7 +580,7 @@ internal class DocumentOperationsModule : IDocumentOperations
     /// </summary>
     public void CenterContent(IReadOnlyList<Guid> structureMembers, int frame)
     {
-        if (Internals.ChangeController.IsChangeActive)
+        if (Internals.ChangeController.IsBlockingChangeActive)
             return;
 
         Internals.ActionAccumulator.AddFinishedActions(new CenterContent_Action(structureMembers.ToList(), frame));
@@ -592,7 +592,7 @@ internal class DocumentOperationsModule : IDocumentOperations
     /// <param name="imageSize">The size of the image</param>
     public void ImportReferenceLayer(ImmutableArray<byte> imageBgra8888Bytes, VecI imageSize)
     {
-        if (Internals.ChangeController.IsChangeActive)
+        if (Internals.ChangeController.IsBlockingChangeActive)
             return;
 
         RectD referenceImageRect =
@@ -607,7 +607,7 @@ internal class DocumentOperationsModule : IDocumentOperations
     /// </summary>
     public void DeleteReferenceLayer()
     {
-        if (Internals.ChangeController.IsChangeActive || Document.ReferenceLayerHandler.ReferenceBitmap is null)
+        if (Internals.ChangeController.IsBlockingChangeActive || Document.ReferenceLayerHandler.ReferenceBitmap is null)
             return;
 
         Internals.ActionAccumulator.AddFinishedActions(new DeleteReferenceLayer_Action());
@@ -618,7 +618,7 @@ internal class DocumentOperationsModule : IDocumentOperations
     /// </summary>
     public void TransformReferenceLayer()
     {
-        if (Document.ReferenceLayerHandler.ReferenceBitmap is null || Internals.ChangeController.IsChangeActive)
+        if (Document.ReferenceLayerHandler.ReferenceBitmap is null || Internals.ChangeController.IsBlockingChangeActive)
             return;
         Internals.ChangeController.TryStartExecutor(new TransformReferenceLayerExecutor());
     }
@@ -628,7 +628,7 @@ internal class DocumentOperationsModule : IDocumentOperations
     /// </summary>
     public void ResetReferenceLayerPosition()
     {
-        if (Document.ReferenceLayerHandler.ReferenceBitmap is null || Internals.ChangeController.IsChangeActive)
+        if (Document.ReferenceLayerHandler.ReferenceBitmap is null || Internals.ChangeController.IsBlockingChangeActive)
             return;
 
 
@@ -728,7 +728,7 @@ internal class DocumentOperationsModule : IDocumentOperations
 
     public void Rasterize(Guid memberId)
     {
-        if (Internals.ChangeController.IsChangeActive)
+        if (Internals.ChangeController.IsBlockingChangeActive)
             return;
 
         Internals.ActionAccumulator.AddFinishedActions(new RasterizeMember_Action(memberId));    
@@ -736,7 +736,7 @@ internal class DocumentOperationsModule : IDocumentOperations
 
     public void InvokeCustomAction(Action action)
     {
-        if (Internals.ChangeController.IsChangeActive)
+        if (Internals.ChangeController.IsBlockingChangeActive)
             return;
 
         IAction targetAction = new InvokeAction_PassthroughAction(action);

+ 2 - 0
src/PixiEditor/Models/DocumentModels/UpdateableChangeExecutors/SimpleShapeToolExecutor.cs

@@ -40,6 +40,8 @@ internal abstract class SimpleShapeToolExecutor : UpdateableChangeExecutor
     protected Guid memberId;
     protected VecD startDrawingPos;
 
+    public override bool BlocksOtherActions => ActiveMode == ShapeToolMode.Drawing;
+
     public override ExecutionState Start()
     {
         IStructureMemberHandler? member = document?.SelectedStructureMember;

+ 1 - 0
src/PixiEditor/Models/DocumentModels/UpdateableChangeExecutors/UpdateableChangeExecutor.cs

@@ -22,6 +22,7 @@ internal abstract class UpdateableChangeExecutor
     protected Action<UpdateableChangeExecutor>? onEnded;
     public virtual ExecutorType Type => ExecutorType.Regular;
     public virtual ExecutorStartMode StartMode => ExecutorStartMode.RightAway;
+    public virtual bool BlocksOtherActions => true; 
 
     public void Initialize(IDocument document, DocumentInternalParts internals, IServiceProvider services,
         ChangeExecutionController controller, Action<UpdateableChangeExecutor> onEnded)

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

@@ -117,7 +117,7 @@ internal partial class DocumentViewModel : PixiObservableObject, IDocument
         get => horizontalSymmetryAxisEnabled;
         set
         {
-            if (!Internals.ChangeController.IsChangeActive)
+            if (!Internals.ChangeController.IsBlockingChangeActive)
                 Internals.ActionAccumulator.AddFinishedActions(
                     new SymmetryAxisState_Action(SymmetryAxisDirection.Horizontal, value));
         }
@@ -130,7 +130,7 @@ internal partial class DocumentViewModel : PixiObservableObject, IDocument
         get => verticalSymmetryAxisEnabled;
         set
         {
-            if (!Internals.ChangeController.IsChangeActive)
+            if (!Internals.ChangeController.IsBlockingChangeActive)
                 Internals.ActionAccumulator.AddFinishedActions(
                     new SymmetryAxisState_Action(SymmetryAxisDirection.Vertical, value));
         }
@@ -152,10 +152,10 @@ internal partial class DocumentViewModel : PixiObservableObject, IDocument
 
     private readonly HashSet<IStructureMemberHandler> softSelectedStructureMembers = new();
 
-    public bool UpdateableChangeActive => Internals.ChangeController.IsChangeActive;
+    public bool UpdateableChangeActive => Internals.ChangeController.IsBlockingChangeActive;
 
     public bool PointerDragChangeInProgress =>
-        Internals.ChangeController.IsChangeActive && Internals.ChangeController.LeftMousePressed;
+        Internals.ChangeController.IsBlockingChangeActive && Internals.ChangeController.LeftMousePressed;
 
     public bool HasSavedUndo => Internals.Tracker.HasSavedUndo;
     public bool HasSavedRedo => Internals.Tracker.HasSavedRedo;