public void OnPasteClickHandler()
        {
            if (_curSelectedNode == null)
            {
                BarrageProject.LogWarning("Paste fail!Please select a node first");
                return;
            }
            NodeData nd = default(NodeData);

            if (!Clipboard.GetClipboardObject <NodeData>(out nd))
            {
                return;
            }
            if (nd == null)
            {
                BarrageProject.LogWarning("Paste fail!There is no data in clipboard");
                return;
            }
            BaseNode parent;
            int      insertIndex;

            GetParentNodeAndInsertIndexByInsertMode(_curInsertMode, _curSelectedNode, out parent, out insertIndex);
            NodeType childType = (NodeType)nd.type;

            if (!parent.CheckCanInsertChildNode(childType))
            {
                string msg = string.Format("can not insert {0} as child of {1}", childType, parent.GetNodeType());
                BarrageProject.LogError(msg);
                return;
            }
            BaseNode childNode = NodeManager.CreateNodesByNodeDatas(nd);

            if (parent.InsertChildNode(childNode, insertIndex))
            {
                parent.Expand(true);
                childNode.OnSelected(true);
                OpPasteHM hm = new OpPasteHM
                {
                    parentIndex   = NodeManager.GetNodeIndex(parent),
                    childIndex    = parent.GetChildIndex(childNode),
                    pasteNodeData = nd,
                };
                Undo.AddToUndoTask(hm);
            }
        }
Ejemplo n.º 2
0
        protected override HistoryMemento OnUndo()
        {
            BaseNode parent    = NodeManager.FindNodeByIndex(parentIndex);
            NodeType childType = (NodeType)delNodeData.type;

            if (parent.CheckCanInsertChildNode(childType))
            {
                BaseNode child = NodeManager.CreateNodesByNodeDatas(delNodeData);
                parent.InsertChildNode(child, childIndex);
                parent.Expand(true);
                child.OnSelected(true);
                var hm = new OpPasteHM
                {
                    parentIndex   = parentIndex,
                    childIndex    = childIndex,
                    pasteNodeData = delNodeData,
                };
                return(hm);
            }
            return(null);
        }