Node AddNode(string nodename = "") { if (string.IsNullOrEmpty(nodename)) { nodename = "dict"; } Node nodeAdded = null; if (treeViewAdvControl.SelectedNode != null) { Node parent = treeViewAdvControl.SelectedNode.Tag as Node; PlistNodeData data = GetNodeData(treeViewAdvControl.SelectedNode); if (!CheckAddNodePossible(data.nodeType)) { ShowErrorMsg(CDefines.GetDStr("AddChildFailure")); return(null); } nodeAdded = AddChild(parent, nodename); if (data.nodeType == Constant.NodeTypeDefine.array) { nodeAdded.Text = "item"; } } else { nodeAdded = AddRoot(nodename); } PlistNodeData nodedata = InitNodeData(nodename); nodeAdded.Tag = nodedata; nodeAdded.Image = imageListToolbar.Images[nodedata.nodeType.ToString()]; haveUnsavedChanges = true; return(nodeAdded); }
Node AddNodeAndValue(Node parent, string nodename, object nodevalue) { if (string.IsNullOrEmpty(nodename)) { new Exception("node name can not be empty!"); } Node nodeAdded = null; if (parent != null) { PlistNodeData data = parent.Tag as PlistNodeData; if (!CheckAddNodePossible(data.nodeType)) { ShowErrorMsg(CDefines.GetDStr("AddChildFailure")); return(null); } nodeAdded = AddChild(parent, nodename); } else { nodeAdded = AddRoot(nodename); } Constant.NodeTypeDefine itemtype = GetItemTypeByValue(nodevalue); PlistNodeData nodedata = InitNodeData(itemtype, nodename); nodedata.SetNewValue(nodevalue); nodeAdded.Tag = nodedata; nodeAdded.Image = imageListToolbar.Images[nodedata.nodeType.ToString()]; haveUnsavedChanges = true; return(nodeAdded); }
private void RefreshKey(PlistNodeData data) { switch (data.nodeType) { case Constant.NodeTypeDefine.dict: txtBoxDictName.Text = data.key; break; case Constant.NodeTypeDefine.array: // break; case Constant.NodeTypeDefine.boolean: txtBoxBoolName.Text = data.key; break; case Constant.NodeTypeDefine.number: txtBoxNumberName.Text = data.key; break; case Constant.NodeTypeDefine.text: txtBoxStringName.Text = data.key; break; case Constant.NodeTypeDefine.datetime: txtBoxDateName.Text = data.key; break; default: return; } }
private void txtBoxNumberValue_Leave(object sender, EventArgs e) { if (treeViewAdvControl.SelectedNode == null) { return; } double num = 0; if (!double.TryParse(txtBoxNumberValue.Text, out num)) { txtBoxNumberValue.Text = "0"; ShowErrorMsg(CDefines.GetDStr("NotNumber")); return; } TreeNodeAdv nodeadv = treeViewAdvControl.SelectedNode; PlistNodeData data = GetNodeData(nodeadv); if (data.value_number != num) { data.value_number = num; haveUnsavedChanges = true; } }
private void RefreshEditPanel() { HideEditPanels(); if (treeViewAdvControl.SelectedNode == null) { return; } PlistNodeData data = GetNodeData(treeViewAdvControl.SelectedNode); if (data == null) { _DataNULLException(); } bool isArray = false; PlistNodeData datatemp = GetNodeData(treeViewAdvControl.SelectedNode.Parent); if (datatemp != null) { isArray = datatemp.nodeType == Constant.NodeTypeDefine.array; } ShowEditPanel(data, isArray); int index = cmbBoxNodeType.Items.IndexOf(GetNameFromType(data.nodeType)); if (index >= 0) { cmbBoxNodeType.SelectedIndex = index; } }
private void btnApplyType_Click(object sender, EventArgs e) { if (cmbBoxNodeType.SelectedIndex < 0) { return; } if (treeViewAdvControl.SelectedNode == null) { ShowErrorMsg(CDefines.GetDStr("NothingSelected")); return; } Constant.NodeTypeDefine newtype = GetTypeFromName(cmbBoxNodeType.SelectedItem.ToString()); PlistNodeData data = GetNodeData(treeViewAdvControl.SelectedNode); if (data.nodeType == newtype) { return; } object oldvalue = data.GetOldValue(); data.nodeType = newtype; data.SetNewValue(oldvalue); RefreshEditPanel(); RefreshTreeIcon(newtype); }
public void AddPlistNodeData(PlistNodeData parent, PlistNodeData child) { foreach (PlistNodeData node in nodeList) { if (node.uniquekey == parent.uniquekey) { child.uniquekey = makeUniqueKey(); nodeList.Add(child); if (!nodeRelationship.ContainsKey(parent.uniquekey)) { List <string> childList = new List <string>(); childList.Add(child.uniquekey); nodeRelationship.Add(parent.uniquekey, childList); } else { List <string> childList = nodeRelationship[parent.uniquekey]; childList.Add(child.uniquekey); nodeRelationship[parent.uniquekey] = childList; } return; } } throw new Exception("parent node not find, this could not happen."); }
private string GetKeyPlainText(PlistNodeData data) { if (data.nodeType == Constant.NodeTypeDefine.boolean) { return("bool"); } else if (data.nodeType == Constant.NodeTypeDefine.text) { return("string"); } else if (data.nodeType == Constant.NodeTypeDefine.number) { long d = 0; if (long.TryParse(data.value_number.ToString(), out d)) { return("integer"); } else { return("real"); } } else if (data.nodeType == Constant.NodeTypeDefine.datetime) { return("date"); } return(data.nodeType.ToString()); }
public bool PasteClip(TreeModel model, System.Windows.Forms.ImageList imagelist) { if (string.IsNullOrEmpty(tree.rootkey)) { return(false); } PlistNodeData data = tree.GetDataByUniqueKey(tree.rootkey); Node parentNode = new PlistNode(data.key); model.Nodes.Add(parentNode); parentNode.Image = imagelist.Images[data.nodeType.ToString()]; parentNode.Tag = data.DeepCopy(); foreach (string key in tree.nodeRelationship.Keys) { if (key == tree.rootkey) { List <string> childrenkey = tree.nodeRelationship[key]; foreach (string childkey in childrenkey) { DrawChildNode(parentNode, tree.GetDataByUniqueKey(childkey), imagelist); } } } return(true); }
public void AddPlistNodeData(PlistNodeData parent, PlistNodeData child) { foreach (PlistNodeData node in nodeList) { if (node.uniquekey == parent.uniquekey) { child.uniquekey = makeUniqueKey(); nodeList.Add(child); if (!nodeRelationship.ContainsKey(parent.uniquekey)) { List<string> childList = new List<string>(); childList.Add(child.uniquekey); nodeRelationship.Add(parent.uniquekey, childList); } else { List<string> childList = nodeRelationship[parent.uniquekey]; childList.Add(child.uniquekey); nodeRelationship[parent.uniquekey] = childList; } return; } } throw new Exception("parent node not find, this could not happen."); }
private void pasteToolStripButton_Click(object sender, EventArgs e) { CCClipBoard clip = CCClipBoard.SingletonInstance(); if (treeViewAdvControl.SelectedNode == null) { if (clip.PasteClip(_model, imageListToolbar)) { haveUnsavedChanges = true; } return; } Node parent = treeViewAdvControl.SelectedNode.Tag as Node; PlistNodeData data = GetNodeData(treeViewAdvControl.SelectedNode); if (!CheckAddNodePossible(data.nodeType)) { ShowErrorMsg(CDefines.GetDStr("AddChildFailure")); return; } if (clip.PasteClip(treeViewAdvControl.SelectedNode, imageListToolbar)) { haveUnsavedChanges = true; } }
private PlistNodeData InitNodeData(Constant.NodeTypeDefine nodetype, string key) { PlistNodeData data = new PlistNodeData(); data.nodeType = nodetype; data.key = key; return(data); }
private void UpdateDataKey() { TreeNodeAdv nodeadv = treeViewAdvControl.SelectedNode; if (nodeadv != null) { PlistNodeData data = GetNodeData(nodeadv); data.key = (nodeadv.Tag as Node).Text; RefreshKey(data); } }
public PlistNodeData DeepCopy() { PlistNodeData newData = new PlistNodeData(); newData.key = this.key; newData.nodeType = this.nodeType; newData.value_bool = this.value_bool; newData.value_date = this.value_date; newData.value_number = this.value_number; newData.value_string = this.value_string; return newData; }
public PlistNodeData DeepCopy() { PlistNodeData newData = new PlistNodeData(); newData.key = this.key; newData.nodeType = this.nodeType; newData.value_bool = this.value_bool; newData.value_date = this.value_date; newData.value_number = this.value_number; newData.value_string = this.value_string; return(newData); }
private void chkBoxBoolValue_CheckedChanged(object sender, EventArgs e) { if (treeViewAdvControl.SelectedNode == null) { return; } TreeNodeAdv nodeadv = treeViewAdvControl.SelectedNode; PlistNodeData data = GetNodeData(nodeadv); data.value_bool = chkBoxBoolValue.Checked; haveUnsavedChanges = true; }
PlistNodeData GetNodeData(TreeNodeAdv nodeadv) { if (nodeadv != null && nodeadv.Tag != null) { Node node = nodeadv.Tag as Node; if (node.Tag != null) { PlistNodeData data = node.Tag as PlistNodeData; return(data); } } return(null); }
private void datePicker_ValueChanged(object sender, EventArgs e) { if (treeViewAdvControl.SelectedNode == null) { return; } TreeNodeAdv nodeadv = treeViewAdvControl.SelectedNode; PlistNodeData data = GetNodeData(nodeadv); data.value_date = datePicker.Value.Date.AddHours(timePicker.Value.Hour) .AddMinutes(timePicker.Value.Minute).AddSeconds(timePicker.Value.Second); haveUnsavedChanges = true; }
private void txtBoxStringValue_Leave(object sender, EventArgs e) { if (treeViewAdvControl.SelectedNode == null) { return; } TreeNodeAdv nodeadv = treeViewAdvControl.SelectedNode; PlistNodeData data = GetNodeData(nodeadv); if (data.value_string != txtBoxStringValue.Text) { data.value_string = txtBoxStringValue.Text; haveUnsavedChanges = true; } }
void FetchNodeData(TreeNodeAdv parentNode, XElement xmlElm, bool parentIsArray) { PlistNodeData data = GetNodeData(parentNode); if (data == null) { _DataNULLException(); } if (data.nodeType == Constant.NodeTypeDefine.dict) { XElement dict = AddDictItem(xmlElm, data.key, parentIsArray); foreach (TreeNodeAdv nodeadvchild in parentNode.Children) { FetchNodeData(nodeadvchild, dict, false); } } else if (data.nodeType == Constant.NodeTypeDefine.array) { XElement array = AddArrayContainerItem(xmlElm, data.key, parentIsArray); foreach (TreeNodeAdv nodeadvchild in parentNode.Children) { PlistNodeData childdata = GetNodeData(nodeadvchild); FetchNodeData(nodeadvchild, array, true); } } else if (data.nodeType == Constant.NodeTypeDefine.boolean) { if (!parentIsArray) { xmlElm.Add(new XElement("key", data.key)); } if (data.value_bool) { xmlElm.Add(new XElement("true")); } else { xmlElm.Add(new XElement("false")); } } else { AddValueItem(xmlElm, data, parentIsArray); } }
private void ImportCSVAsDict(CsvLib.CsvStreamReader csvreader) { for (int i = 2; i <= csvreader.RowCount; i++) { if (csvreader.ColCount > 1) { Node newNode = AddNode("dict"); PlistNodeData data = newNode.Tag as PlistNodeData; data.key = csvreader[i, 1]; newNode.Text = data.key; for (int j = 2; j <= csvreader.ColCount; j++) { AddNodeAndValue(newNode, csvreader[1, j], csvreader[i, j]); } } } }
private void importToolStripButton_Click(object sender, EventArgs e) { if (treeViewAdvControl.SelectedNode == null) { ImportCSV(null, Constant.NodeTypeDefine.dict); return; } Node parent = treeViewAdvControl.SelectedNode.Tag as Node; PlistNodeData data = GetNodeData(treeViewAdvControl.SelectedNode); if (!CheckAddNodePossible(data.nodeType)) { ShowErrorMsg(CDefines.GetDStr("AddChildFailure")); return; } ImportCSV(parent, data.nodeType); }
private void ShowEditPanel(PlistNodeData data, bool isArray = false) { switch (data.nodeType) { case Constant.NodeTypeDefine.dict: panelDictEditor.Visible = true; txtBoxDictName.Text = data.key; txtBoxDictName.Enabled = !isArray; break; case Constant.NodeTypeDefine.datetime: panelDateEditor.Visible = true; txtBoxDateName.Text = data.key; datePicker.Value = data.value_date; timePicker.Value = data.value_date; txtBoxDateName.Enabled = !isArray; break; case Constant.NodeTypeDefine.boolean: panelBoolEditor.Visible = true; txtBoxBoolName.Text = data.key; chkBoxBoolValue.Checked = data.value_bool; txtBoxBoolName.Enabled = !isArray; break; case Constant.NodeTypeDefine.number: panelNumberEditor.Visible = true; txtBoxNumberName.Text = data.key; txtBoxNumberValue.Text = data.value_number.ToString(); txtBoxNumberName.Enabled = !isArray; break; case Constant.NodeTypeDefine.text: panelStringEditor.Visible = true; txtBoxStringName.Text = data.key; txtBoxStringValue.Text = data.value_string; txtBoxStringName.Enabled = !isArray; break; default: return; } }
private Node DataParser(string key, XElement xe, Node parent = null) { Node nodeAdded = parent == null?AddRoot(key) : AddChild(parent, key); Constant.NodeTypeDefine nodetype = GetTypeFromName(xe.Name.LocalName); string temp = xe.Name.LocalName.ToLower(); if (temp == "true" || temp == "false") { nodetype = Constant.NodeTypeDefine.boolean; } PlistNodeData data = InitNodeData(nodetype, key); switch (nodetype) { case Constant.NodeTypeDefine.boolean: data.value_bool = Convert.ToBoolean(xe.Name.LocalName); break; case Constant.NodeTypeDefine.number: data.value_number = Convert.ToDouble(xe.Value); break; case Constant.NodeTypeDefine.text: data.value_string = xe.Value; break; case Constant.NodeTypeDefine.datetime: data.value_date = Convert.ToDateTime(xe.Value); break; default: break; } nodeAdded.Tag = data; nodeAdded.Image = imageListToolbar.Images[data.nodeType.ToString()]; return(nodeAdded); }
private void DrawChildNode(Node parentNode, PlistNodeData data, System.Windows.Forms.ImageList imagelist) { Node nodeAdded = new PlistNode(data.key); parentNode.Nodes.Add(nodeAdded); nodeAdded.Tag = data.DeepCopy(); nodeAdded.Image = imagelist.Images[data.nodeType.ToString()]; if (!tree.nodeRelationship.ContainsKey(data.uniquekey)) { return; } foreach (string key in tree.nodeRelationship.Keys) { if (key == data.uniquekey) { List <string> childrenkey = tree.nodeRelationship[key]; foreach (string childkey in childrenkey) { DrawChildNode(nodeAdded, tree.GetDataByUniqueKey(childkey), imagelist); } } } }
public void SaveToPrivateClip(TreeNodeAdv selectedNode, TreeNodeAdv parentNode) { PlistNodeData data = GetNodeData(selectedNode); PlistNodeData dataParent = GetNodeData(parentNode); if (parentNode == null) { tree.ClearTree(); tree.AddRootNode(data); } else { tree.AddPlistNodeData(dataParent, data); } if (data.nodeType == Constant.NodeTypeDefine.dict || data.nodeType == Constant.NodeTypeDefine.array) { foreach (TreeNodeAdv nodeadvchild in selectedNode.Children) { SaveToPrivateClip(nodeadvchild, selectedNode); } } }
private void AddValueItem(XElement parent, PlistNodeData data, bool parentIsArray) { if (!parentIsArray) { parent.Add(new XElement("key", data.key)); } XElement child = new XElement(GetKeyPlainText(data)); switch (data.nodeType) { case Constant.NodeTypeDefine.boolean: child.SetValue(data.value_bool); break; case Constant.NodeTypeDefine.number: child.SetValue(data.value_number); break; case Constant.NodeTypeDefine.text: if (data.value_string != null) { child.SetValue(data.value_string); } break; case Constant.NodeTypeDefine.datetime: child.SetValue(data.value_date.ToUniversalTime().ToString(Constant.datetimeformat)); break; default: return; } parent.Add(child); }
private void XDocParser(XDocument xmldoc) { XElement topdict = xmldoc.Root.Element("dict"); XElementParser(topdict); foreach (Node node in _model.Nodes.ToList()) { if (node.Text == "version") { PlistNodeData data = node.Tag as PlistNodeData; if (data.nodeType == Constant.NodeTypeDefine.text) { version = Convert.ToDouble(data.value_string); node.Parent = null; } else if (data.nodeType == Constant.NodeTypeDefine.number) { version = Convert.ToDouble(data.value_number); node.Parent = null; } } txtBoxVersion.Text = txtBoxVersion.Text = FormatVersion(); } }
public void AddRootNode(PlistNodeData root) { nodeList.Add(root); root.uniquekey = makeUniqueKey(); rootkey = root.uniquekey; }
private void DrawChildNode(Node parentNode, PlistNodeData data, System.Windows.Forms.ImageList imagelist) { Node nodeAdded = new PlistNode(data.key); parentNode.Nodes.Add(nodeAdded); nodeAdded.Tag = data.DeepCopy(); nodeAdded.Image = imagelist.Images[data.nodeType.ToString()]; if(!tree.nodeRelationship.ContainsKey(data.uniquekey)) { return; } foreach(string key in tree.nodeRelationship.Keys) { if(key == data.uniquekey) { List<string> childrenkey = tree.nodeRelationship[key]; foreach(string childkey in childrenkey) { DrawChildNode(nodeAdded, tree.GetDataByUniqueKey(childkey), imagelist); } } } }