public List <Node> AttachTo(Node targetParent) { List <Node> newlyCreated = new List <Node>(); if (m_clippedNodes.Count == 0) { return(newlyCreated); } Node actualParent = targetParent; if (m_clippedNodes.Contains(targetParent) || m_clippedNodes[0].Parent == targetParent.Parent) { actualParent = targetParent.Parent; } if (actualParent == null) { Logging.Instance.Message("SceneClipboard.AttachTo() 时发现目标父节点无效,操作失败。"); return(newlyCreated); } List <Node> tmpList = new List <Node>(); foreach (string str in m_clippedContent) { Node n = NodeJsonUtil.StringToNode(str); if (n == null) { Logging.Instance.Message("SceneClipboard.AttachTo() 时发现无效节点,操作失败。"); return(newlyCreated); } n.Position = n.Position + new System.Drawing.Size(m_offset, m_offset); tmpList.Add(n); } foreach (var node in tmpList) { actualParent.Attach(node); newlyCreated.Add(node); } if (m_isCutting) { foreach (var node in m_clippedNodes) { if (node.Parent != null) { node.Parent.Detach(node); } } } IncrementOffset(); return(newlyCreated); }
public Node LoadFrom(string targetLocation) { try { // read JSON directly from a file using (StreamReader file = File.OpenText(targetLocation)) using (JsonTextReader reader = new JsonTextReader(file)) { JObject jsonObject = (JObject)JToken.ReadFrom(reader); return(NodeJsonUtil.JObjectToNode(jsonObject)); } } catch (Exception e) { Logging.Instance.Log(e.Message); return(null); } }
public bool SetClippedContent(List <Node> nodes, bool isCutting) { ClearClippedContent(); // 确保节点列表有效 if (nodes.Count == 0) { return(false); } // 确保节点列表有共同的父节点 Node parent = nodes[0].Parent; foreach (Node n in nodes) { if (parent != n.Parent) { Logging.Instance.Message("待操作的节点没有一个公共的父节点。"); return(false); } } foreach (Node n in nodes) { string str = NodeJsonUtil.NodeToString(n); if (str.Length == 0) { Logging.Instance.Message("SetClippedContent() 时发现无效节点,操作失败。"); return(false); } m_clippedContent.Add(str); m_clippedNodes.Add(n); } ResetOffset(); m_isCutting = isCutting; SceneEdEventNotifier.Instance.Emit_RefreshScene(RefreshSceneOpt.Refresh_All); return(true); }
public bool SaveTo(Node node, string targetLocation) { string text = NodeJsonUtil.NodeToString(node); if (text.Length == 0) { return(false); } try { using (StreamWriter file = File.CreateText(targetLocation)) { file.Write(text); } } catch (System.Exception ex) { Logging.Instance.LogExceptionDetail(ex); return(false); } return(true); }
public override void Redo() { NodeJsonUtil.PopulateExistingNodeWithString(m_targetNode, m_changedContent); }
public override void Undo() { NodeJsonUtil.PopulateExistingNodeWithString(m_targetNode, m_initialContent); }
public void ChangeCommitted() { m_changedContent = NodeJsonUtil.NodeToString(m_targetNode); }
public Action_PropertyChange(Node targetNode) { m_targetNode = targetNode; m_initialContent = NodeJsonUtil.NodeToString(m_targetNode); }