diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c18bc0a..5d20dc2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ > - Breaking Changes: > - Made the setter of NodifyEditor.IsPanning private > - Renamed StartCutting to BeginCutting in NodifyEditor +> - Renamed PushItems to UpdatePushedArea and StartPushingItems to BeginPushingItems in NodifyEditor > - Features: > - Added BeginPanning, UpdatePanning, EndPanning, CancelPanning and AllowPanningCancellation to NodifyEditor > - Added UpdateCuttingLine to NodifyEditor diff --git a/Nodify/EditorStates/EditorPushingItemsState.cs b/Nodify/EditorStates/EditorPushingItemsState.cs index f9ef89dd..99441115 100644 --- a/Nodify/EditorStates/EditorPushingItemsState.cs +++ b/Nodify/EditorStates/EditorPushingItemsState.cs @@ -25,11 +25,7 @@ public override void Enter(EditorState? from) public override void Exit() { - if (!Editor.IsPushingItems) - { - return; - } - + // TODO: This is not canceled on LostMouseCapture (add OnLostMouseCapture/OnCancel callback?) if (Canceled) { Editor.CancelPushingItems(); @@ -44,18 +40,18 @@ public override void HandleMouseMove(MouseEventArgs e) { if (Editor.IsPushingItems) { - Editor.PushItems(Editor.MouseLocation - _prevPosition); + Editor.UpdatePushedArea(Editor.MouseLocation - _prevPosition); _prevPosition = Editor.MouseLocation; } else { if (Math.Abs(Editor.MouseLocation.X - _prevPosition.X) >= _minDragDistance) { - Editor.StartPushingItems(_prevPosition, Orientation.Horizontal); + Editor.BeginPushingItems(_prevPosition, Orientation.Horizontal); } else if (Math.Abs(Editor.MouseLocation.Y - _prevPosition.Y) >= _minDragDistance) { - Editor.StartPushingItems(_prevPosition, Orientation.Vertical); + Editor.BeginPushingItems(_prevPosition, Orientation.Vertical); } } } diff --git a/Nodify/NodifyEditor.PushingItems.cs b/Nodify/NodifyEditor.PushingItems.cs index 624fac19..f9bc85f9 100644 --- a/Nodify/NodifyEditor.PushingItems.cs +++ b/Nodify/NodifyEditor.PushingItems.cs @@ -1,6 +1,5 @@ using System.Diagnostics; using System.Windows; -using System; using System.Windows.Controls; using System.Windows.Shapes; @@ -92,11 +91,15 @@ public Style PushedAreaStyle /// /// Starts the pushing items operation at the specified location with the specified orientation. /// + /// This method has no effect if a pushing operation is already in progress. /// The starting location for pushing items, in graph space coordinates. /// The orientation of the . - protected internal void StartPushingItems(Point location, Orientation orientation) + public void BeginPushingItems(Point location, Orientation orientation) { - Debug.Assert(!IsPushingItems); + if(IsPushingItems) + { + return; + } IsPushingItems = true; PushedAreaOrientation = orientation; @@ -107,30 +110,28 @@ protected internal void StartPushingItems(Point location, Orientation orientatio } /// - /// Cancels the current pushing operation and reverts the to its initial state. + /// Cancels the current pushing operation and reverts the to its initial state if is true. /// - /// Thrown if pushing item cancellation is not allowed (see ). - protected internal void CancelPushingItems() + /// This method has no effect if there's no pushing operation in progress. + public void CancelPushingItems() { - if (!AllowPushItemsCancellation) - throw new InvalidOperationException("Push items cancellation is not allowed"); - - Debug.Assert(IsPushingItems); - if (IsPushingItems) + if (!AllowPushItemsCancellation || !IsPushingItems) { - PushedArea = _pushStrategy!.Cancel(); - IsPushingItems = false; + return; } + + PushedArea = _pushStrategy!.Cancel(); + IsPushingItems = false; } /// - /// Updates the pushed area based on the specified amount. + /// Updates the pushed area based on the specified amount taking the into account. /// - /// The amount to adjust the pushed area by. + /// The amount to adjust the pushed area by. /// - /// This method adjusts the pushed area incrementally. It should only be called while a pushing operation is active (see ). + /// This method adjusts the pushed area incrementally. It should only be called while a pushing operation is active (see ). /// - protected internal void PushItems(Vector amount) + public void UpdatePushedArea(Vector amount) { Debug.Assert(IsPushingItems); PushedArea = _pushStrategy!.Push(amount); @@ -139,15 +140,17 @@ protected internal void PushItems(Vector amount) /// /// Ends the current pushing operation and finalizes the pushed area state. /// - protected internal void EndPushingItems() + /// This method has no effect if there's no pushing operation in progress. + public void EndPushingItems() { - Debug.Assert(IsPushingItems); - if (IsPushingItems) + if (!IsPushingItems) { - PushedArea = _pushStrategy!.End(); - _pushStrategy = null; - IsPushingItems = false; + return; } + + PushedArea = _pushStrategy!.End(); + _pushStrategy = null; + IsPushingItems = false; } private void UpdatePushedArea()