private void OnCutClickHandler() { if (_curSelectedNode == null) { BarrageProject.LogWarning("Cut fail!Please select a node first"); return; } BaseNode parent = _curSelectedNode.GetParentNode(); if (parent == null) { BarrageProject.LogWarning("Cut fail!Node root is not deletable"); return; } if (!_curSelectedNode.IsDeletable) { BarrageProject.LogWarning(string.Format("Cut fail!Node {0} is not deletable", _curSelectedNode.GetNodeName())); return; } // 保存该节点的数据 NodeData nd = NodeManager.SaveAsNodeData(_curSelectedNode, true); if (!Clipboard.CopyToClipboard(nd)) { return; } //Clipboard.SetDataObject(nd); // 删除节点 int index = parent.GetChildIndex(_curSelectedNode); // 删除完成之后,默认选中下一个节点 if (parent.RemoveChildNode(_curSelectedNode)) { BaseNode newSelectNode = parent.GetChildByIndex(index); if (newSelectNode == null) { newSelectNode = parent.GetChildByIndex(index - 1); if (newSelectNode == null) { newSelectNode = parent; } } newSelectNode.OnSelected(true); OpDeleleHM hm = new OpDeleleHM { parentIndex = NodeManager.GetNodeIndex(parent), childIndex = index, delNodeData = nd, }; Undo.AddToUndoTask(hm); } }
private void OnDeleteClickHandler() { if (_curSelectedNode == null) { BarrageProject.LogWarning("Delete fail!Please select a node first"); return; } BaseNode parent = _curSelectedNode.GetParentNode(); if (parent == null) { BarrageProject.LogWarning("Delete fail!Node root is not deletable"); return; } if (!_curSelectedNode.IsDeletable) { BarrageProject.LogWarning(string.Format("Delete fail!Node {0} is not deletable", _curSelectedNode.GetNodeName())); return; } int indexInParent = parent.GetChildIndex(_curSelectedNode); NodeData nd = NodeManager.SaveAsNodeData(_curSelectedNode, true); // 删除完成之后,默认选中下一个节点 if (parent.RemoveChildNode(_curSelectedNode)) { BaseNode newSelectNode = parent.GetChildByIndex(indexInParent); if (newSelectNode == null) { newSelectNode = parent.GetChildByIndex(indexInParent - 1); if (newSelectNode == null) { newSelectNode = parent; } } newSelectNode.OnSelected(true); OpDeleleHM hm = new OpDeleleHM { parentIndex = NodeManager.GetNodeIndex(parent), childIndex = indexInParent, delNodeData = nd, }; Undo.AddToUndoTask(hm); } //else //{ // BarrageProject.LogWarning(string.Format("Delete fail!Node {0} is not deletable", _curSelectedNode.GetNodeName())); //} }
protected override HistoryMemento OnUndo() { BaseNode parent = NodeManager.FindNodeByIndex(parentIndex); BaseNode child = parent.GetChildByIndex(childIndex); if (parent.RemoveChildNode(child)) { parent.Expand(true); parent.OnSelected(true); var hm = new OpDeleleHM { parentIndex = parentIndex, childIndex = childIndex, delNodeData = insertNodeData, }; return(hm); } return(null); }