예제 #1
0
        public NodifyEditorViewModel()
        {
            DeleteSelectionCommand     = new DelegateCommand(DeleteSelection, () => SelectedNodes.Count > 0);
            CommentSelectionCommand    = new DelegateCommand(() => Schema.AddCommentAroundNodes(SelectedNodes, "New comment"), () => SelectedNodes.Count > 0);
            DisconnectConnectorCommand = new DelegateCommand <ConnectorViewModel>(c => c.Disconnect());
            CreateConnectionCommand    = new DelegateCommand <object>(target => Schema.TryAddConnection(PendingConnection.Source !, target), target => PendingConnection.Source != null && target != null);

            PendingConnection = new PendingConnectionViewModel
            {
                Graph = this
            };

            Schema = new GraphSchema();

            Connections.WhenAdded(c =>
            {
                c.Graph = this;
                c.Input.Connections.Add(c);
                c.Output.Connections.Add(c);
            })
            // Called when the collection is cleared
            .WhenRemoved(c =>
            {
                c.Input.Connections.Remove(c);
                c.Output.Connections.Remove(c);
            });

            Nodes.WhenAdded(x => x.Graph = this)
            // Not called when the collection is cleared
            .WhenRemoved(x =>
            {
                if (x is FlowNodeViewModel flow)
                {
                    flow.Disconnect();
                }
                else if (x is KnotNodeViewModel knot)
                {
                    knot.Connector.Disconnect();
                }
            })
            .WhenCleared(x => Connections.Clear());
        }