private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            var tempInfos  = new List <Base.LinkInfo>(LinkInfos);
            var redoAction = new Action <object>((obj) =>
            {
                Clear();
            });

            redoAction.Invoke(null);
            EditorCommon.UndoRedo.UndoRedoManager.Instance.AddCommand(HostNodesContainer.HostControl.UndoRedoKey, null, redoAction, null,
                                                                      (obj) =>
            {
                foreach (var li in tempInfos)
                {
                    LinkInfos.Add(new Base.LinkInfo(HostNodesContainer.GetDrawCanvas(), li.m_linkFromObjectInfo, li.m_linkToObjectInfo));
                }
            }, "Remove Link");
            HostNodeControl.IsDirty = true;
        }
Exemple #2
0
        public LinkPinControl()
        {
            GUID  = Guid.NewGuid();
            Image = TryFindResource("VarPin_Disconnected") as ImageSource;
            mContextMenu.Style = TryFindResource(new ComponentResourceKey(typeof(ResourceLibrary.CustomResources), "ContextMenu_Default")) as Style;

            this.MouseRightButtonDown += (sender, e) =>
            {
                e.Handled = true;
            };
            this.MouseRightButtonUp += (sender, e) =>
            {
                if (mContextMenu != null)
                {
                    mContextMenu.Items.Clear();
                    AddContextMenuItem("删除所有链接", "Pin Action", (actionObj, arg) =>
                    {
                        var tempInfos  = new List <LinkInfo>(LinkInfos);
                        var redoAction = new Action <object>((obj) =>
                        {
                            Clear();
                        });
                        redoAction.Invoke(null);
                        EditorCommon.UndoRedo.UndoRedoManager.Instance.AddCommand(HostNodesContainer.HostControl.UndoRedoKey, null, redoAction, null,
                                                                                  (obj) =>
                        {
                            foreach (var li in tempInfos)
                            {
                                LinkInfos.Add(new LinkInfo(HostNodesContainer.GetDrawCanvas(), li.m_linkFromObjectInfo, li.m_linkToObjectInfo));
                            }
                        }, "Remove Link");
                        HostNodeControl.IsDirty = true;
                    });

                    foreach (var linkInfo in LinkInfos)
                    {
                        BaseNodeControl linkNode = null;
                        switch (LinkOpType)
                        {
                        case enLinkOpType.Start:
                            linkNode = linkInfo.m_linkToObjectInfo.HostNodeControl;
                            break;

                        case enLinkOpType.End:
                            linkNode = linkInfo.m_linkFromObjectInfo.HostNodeControl;
                            break;

                        case enLinkOpType.Both:
                            linkNode = null;
                            break;
                        }
                        if (linkNode == null)
                        {
                            return;
                        }
                        var str = linkNode.GetNodeDescriptionString();
                        AddContextMenuItem("删除连接到 " + str, "Pin Action", (actionObj, arg) =>
                        {
                            var undoRedoData = new DelLinkUndoRedoData()
                            {
                                ProcessInfo = linkInfo
                            };

                            var redoAction = new Action <object>((obj) =>
                            {
                                undoRedoData.ProcessInfo.Clear();
                                LinkInfos.Remove(undoRedoData.ProcessInfo);
                            });
                            redoAction.Invoke(null);
                            EditorCommon.UndoRedo.UndoRedoManager.Instance.AddCommand(HostNodesContainer.HostControl.UndoRedoKey, null, redoAction, null,
                                                                                      (obj) =>
                            {
                                undoRedoData.ProcessInfo = new LinkInfo(HostNodesContainer.GetDrawCanvas(), undoRedoData.ProcessInfo.m_linkFromObjectInfo, undoRedoData.ProcessInfo.m_linkToObjectInfo);
                                LinkInfos.Add(undoRedoData.ProcessInfo);
                            }, "Remove Link");
                            HostNodeControl.IsDirty = true;
                        });
                    }
                    OnCollectionContextMenus?.Invoke(this);
                    mContextMenu.IsOpen = true;
                }
                e.Handled = true;
            };
        }