Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent Shift Drag Crash when single group selected #13098

Merged
merged 2 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/DynamoCoreWpf/Commands/DynamoCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,20 @@ void OnModelCommandCompleted(DynamoModel.RecordableCommand command)
var dragC = command as DynamoModel.DragSelectionCommand;

if (DynamoModel.DragSelectionCommand.Operation.BeginDrag == dragC.DragOperation)
CurrentSpaceViewModel.BeginDragSelection(dragC.MouseCursor);
{
try
{
CurrentSpaceViewModel.BeginDragSelection(dragC.MouseCursor);
}
catch (Exception ex)
{
model.Logger.Log(ex.Message);
}
}
else
{
CurrentSpaceViewModel.EndDragSelection(dragC.MouseCursor);
}
break;

case "DeleteModelCommand":
Expand Down
9 changes: 9 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3252,4 +3252,7 @@ You can manage this in Preferences -&gt; Security.</value>
<data name="UnableToAccessTrustedDirectory" xml:space="preserve">
<value>Unable To Access Trusted Directory</value>
</data>
<data name="InvalidDraggingOperationMessgae" xml:space="preserve">
<value>Nothing is being dragged. If you see this message, most likely your recent Dynamo interaction is not recommended.</value>
</data>
</root>
3 changes: 3 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3239,4 +3239,7 @@ You can manage this in Preferences -&gt; Security.</value>
<data name="UnableToAccessTrustedDirectory" xml:space="preserve">
<value>Unable To Access Directory</value>
</data>
<data name="InvalidDraggingOperationMessgae" xml:space="preserve">
<value>Nothing is being dragged. If you see this message, most likely your recent Dynamo interaction is not recommended.</value>
</data>
</root>
32 changes: 11 additions & 21 deletions src/DynamoCoreWpf/ViewModels/Core/StateMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ partial class WorkspaceViewModel

#region State Machine Related Methods/Data Members

private StateMachine stateMachine = null;
private readonly StateMachine stateMachine = null;
private List<DraggedNode> draggedNodes = new List<DraggedNode>();

// When a new connector is created or a single connector is selected,
Expand Down Expand Up @@ -146,19 +146,12 @@ internal void BeginDragSelection(Point2D mouseCursor)

if (draggedNodes.Count <= 0) // There is nothing to drag.
{
string message = "Shouldn't get here if nothing is dragged";
throw new InvalidOperationException(message);
throw new InvalidOperationException(Wpf.Properties.Resources.InvalidDraggingOperationMessgae);
}
}

internal void UpdateDraggedSelection(Point2D mouseCursor)
{
if (draggedNodes.Count <= 0)
{
throw new InvalidOperationException(
"UpdateDraggedSelection cannot be called now");
}

foreach (DraggedNode draggedNode in draggedNodes)
draggedNode.Update(mouseCursor);
}
Expand Down Expand Up @@ -343,15 +336,15 @@ private void RecordSelectionForUndo(Point2D mousePoint)
List<ModelBase> changedPositionModels = new List<ModelBase>();
foreach (DraggedNode draggedNode in draggedNodes)
{
//Checks if the draggednoded has changed its position
//Checks if the dragged node has changed its position
if (draggedNode.HasChangedPosition(mousePoint))
{
ModelBase model = DynamoSelection.Instance.Selection.
Where((x) => (x is ModelBase)).Cast<ModelBase>().FirstOrDefault(x => x.GUID == draggedNode.guid);

changedPositionModels.Add(model);

//The nodes are being reseted to inital position for recording the model purposes
//The nodes are being reseted to initial position for recording the model purposes
draggedNode.UpdateInitialPosition();
}
}
Expand All @@ -363,15 +356,13 @@ private void RecordSelectionForUndo(Point2D mousePoint)
private void OnDragSelectionStarted(object sender, EventArgs e)
{
//Debug.WriteLine("Drag started : Visualization paused.");
if (DragSelectionStarted != null)
DragSelectionStarted(sender, e);
DragSelectionStarted?.Invoke(sender, e);
}

private void OnDragSelectionEnded(object sender, EventArgs e)
{
//Debug.WriteLine("Drag ended : Visualization unpaused.");
if (DragSelectionEnded != null)
DragSelectionEnded(sender, e);
DragSelectionEnded?.Invoke(sender, e);
}

#endregion
Expand All @@ -384,10 +375,12 @@ private void OnDragSelectionEnded(object sender, EventArgs e)
/// </summary>
public class DraggedNode
{
double deltaX = 0, deltaY = 0;
ILocatable locatable = null;
private readonly double deltaX = 0;
private readonly double deltaY = 0;
readonly ILocatable locatable = null;
internal Guid guid;
double initialPositionX = 0, initialPositionY = 0;
private readonly double initialPositionX = 0;
private readonly double initialPositionY = 0;

/// <summary>
/// Construct a DraggedNode for a given ILocatable object.
Expand All @@ -399,9 +392,6 @@ public class DraggedNode
/// <param name="mouseCursor">The mouse cursor at the point this
/// DraggedNode object is constructed. This is used to determine the
/// offset of the ILocatable from the mouse cursor.</param>
/// <param name="region">The region within which the ILocatable can
/// be moved. However, the movement of ILocatable will be limited by
/// region and that it cannot be moved beyond the region.</param>
///
public DraggedNode(ILocatable locatable, Point2D mouseCursor)
{
Expand Down