private void CreateNodeFromType(object sender, Type type)
        {
            BonsaiNode node = Canvas.CreateNode(type);

            NodeSelection.SetSingleSelection(node);
            lastCreatedNodeToPosition = node;

            // This is to handle connecting a newly created node from the GenericMenu
            // triggered by a EditorNodeConnection action.
            if (pendingParentConnection != null)
            {
                EditorNodeConnecting.FinishConnection(Canvas, pendingParentConnection, node);
                pendingParentConnection = null;
                UpdateAbortableSelection();
            }
        }
        private void StartConnection(BonsaiInputEvent startEvent)
        {
            bool isOutputFocused = startEvent.isOutputFocused;

            BonsaiNode parent = isOutputFocused
              ? startEvent.node
              : EditorNodeConnecting.StartConnection(startEvent.node);

            if (parent != null)
            {
                ApplyAction = (BonsaiInputEvent applyEvent) =>
                {
                    if (applyEvent.node != null)
                    {
                        EditorNodeConnecting.FinishConnection(Canvas, parent, applyEvent.node);
                    }

                    // Connection dropped on canvas. Show create menu to make a new connected node.
                    // Only do this for connections started from the output port.
                    else if (isOutputFocused)
                    {
                        // We have to cache the parent because GenericMenu's callback upong selecting an item is deferred,
                        // and cannot handle node connection in this scope.
                        pendingParentConnection = parent;
                        Input.ShowCreateNodeMenu();
                    }
                };

                Viewer.CustomDraw = (CanvasTransform t) =>
                {
                    var start = t.CanvasToScreenSpace(parent.OutputRect.center);
                    var end   = Event.current.mousePosition;
                    Drawer.DrawRectConnectionScreenSpace(start, end, Color.white);
                    OnCanvasChanged();
                };
            }
        }