Skip to content

Commit

Permalink
Add invoker method
Browse files Browse the repository at this point in the history
  • Loading branch information
gshinohara committed Sep 15, 2024
1 parent 8dc3b68 commit 3f4cb11
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions WireEventImplementor/WireInstances.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Grasshopper.GUI.Canvas;
using Grasshopper;
using Grasshopper.GUI.Canvas;
using Grasshopper.GUI.Canvas.Interaction;
using Grasshopper.Kernel;
using System;
Expand Down Expand Up @@ -33,6 +34,23 @@ public static class WireInstances

private static TaskCompletionSource<WireStatus> m_source = new TaskCompletionSource<WireStatus>();

public static void OnWiring(WireStatus wireStatus)
{
Wiring?.Invoke(wireStatus);
}

public static void OnPreWired(WireStatus wireStatus)
{
PreWired?.Invoke(wireStatus);
}

public static void OnPostWired(WireStatus wireStatus)
{
PostWired?.Invoke(wireStatus);
if (Instances.ActiveCanvas.ActiveInteraction is GH_WireInteraction)
Instances.ActiveCanvas.ActiveInteraction = null;
}

/// <summary>
/// Call when canvas created.
/// </summary>
Expand All @@ -54,10 +72,10 @@ private static void Canvas_MouseMove(object sender, MouseEventArgs e)
m_source = new TaskCompletionSource<WireStatus>();

if (status.WireTarget == null)
Wiring?.Invoke(status);
OnWiring(status);
else
{
PreWired?.Invoke(status);
OnPreWired(status);
m_source.SetResult(status);
}
}
Expand All @@ -71,7 +89,7 @@ private static async void Canvas_MouseUp(object sender, MouseEventArgs e)
WireStatus status = await m_source.Task;
m_source = new TaskCompletionSource<WireStatus>();

PostWired?.Invoke(status);
OnPostWired(status);

(sender as GH_Canvas).Refresh();
}
Expand Down

0 comments on commit 3f4cb11

Please sign in to comment.