private void menuItemDebugOutputList_Click(object sender, EventArgs e) { if (tagTreeView.Nodes.Count == 0) { Debug.WriteLine("アイテム=0"); return; } Debug.WriteLine("------------------------------------------------------------"); foreach (TreeNode tagNode in tagTreeView.Nodes[0].Nodes) { KagTag tag = tagNode.Tag as KagTag; if (tag == null) { continue; } foreach (TreeNode attrNode in tagNode.Nodes) { KagTagAttr attr = attrNode.Tag as KagTagAttr; if (attr == null) { continue; } Debug.WriteLine(String.Format("{0, -20}{1, -15}{2}", tag.Name, attr.Name, attr.Format)); } } }
/// <summary> /// 現在の編集内容をノードに保存する /// </summary> /// <param name="node"></param> private void saveNode(TreeNode node) { if (node == null) { return; } if (tagPanel.Visible) { KagTag tag = new KagTag(); tag.Name = tagNameBox.Text; tag.Group = tagGropuBox.Text; tag.ShortInfo = tagShortInfoBox.Text; tag.Remarks = tagLongInfoBox.Text; node.Tag = tag; node.Text = tag.Name; } else if (attrPanel.Visible) { KagTagAttr attr = new KagTagAttr(); attr.Name = attrNameBox.Text; attr.Required = attrRequiredBox.Text; attr.Format = attrFormatBox.Text; attr.ShortInfo = attrShortInfoBox.Text; attr.Info = attrLongInfoBox.Text; node.Tag = attr; node.Text = attr.Name; } else { //何もしない } }
/// <summary> /// タグ属性ノードを読み込む /// </summary> /// <param name="attrElement">タグ属性エレメント</param> private TreeNode readTagAttrNode(XmlElement attrElement) { TreeNode attrNode = new TreeNode(); KagTagAttr attr = new KagTagAttr(); foreach (XmlElement node in attrElement.ChildNodes) { switch (node.Name) { case "attrname": attr.Name = node.InnerText; break; case "attrshortinfo": attr.ShortInfo = node.InnerText; break; case "attrrequired": attr.Required = node.InnerText; break; case "attrformat": attr.Format = convertReadString(node.InnerXml); break; case "attrinfo": attr.Info = node.InnerText; break; } } attrNode.Text = attr.Name; attrNode.Tag = attr; return(attrNode); }
/// <summary> /// 現在のタグに属性追加 /// </summary> private void menuItemPopAddAttr_Click(object sender, EventArgs e) { string name = "NewAttr"; TreeNode node = tagTreeView.SelectedNode.Nodes.Add(name); KagTagAttr attr = new KagTagAttr(); attr.Name = name; node.Tag = attr; showNode(node); }
/// <summary> /// 属性入力パネルを表示する /// </summary> /// <param name="attr"></param> private void showAttrPanel(KagTagAttr attr) { attrPanel.Visible = true; attrPanel.Dock = DockStyle.Fill; if (attr != null) { attrNameBox.Text = attr.Name; attrRequiredBox.Text = attr.Required; attrFormatBox.Text = attr.Format; attrShortInfoBox.Text = attr.ShortInfo; attrLongInfoBox.Text = attr.Info; } defaultPanel.Visible = false; tagPanel.Visible = false; }
/// <summary> /// ツリーノードからファイルを保存する /// </summary> /// <param name="node">"tdb"ノード</param> public void SaveFromTreeNode(TreeNode node, string filePath) { if (node == null || filePath == "") { Debug.WriteLine("保存できるノードがありません"); return; } m_filePath = filePath; using (FileStream fs = new FileStream(m_filePath, FileMode.Create)) { using (XmlTextWriter xw = new XmlTextWriter(fs, Encoding.UTF8)) { xw.Formatting = Formatting.Indented; xw.WriteStartDocument(); xw.WriteStartElement("tdb"); foreach (TreeNode tagNode in node.Nodes) { KagTag tag = tagNode.Tag as KagTag; if (tag == null) { continue; } xw.WriteStartElement("tag"); xw.WriteAttributeString("id", String.Format("tag_{0}", tag.Name)); writeElement(xw, "tagname", tag.Name); writeElement(xw, "group", tag.Group); writeElement(xw, "tagshortinfo", tag.ShortInfo); writeElement(xw, "tagremarks", tag.Remarks); foreach (TreeNode attrNode in tagNode.Nodes) { KagTagAttr attr = attrNode.Tag as KagTagAttr; if (attr == null) { continue; } xw.WriteStartElement("attr"); xw.WriteAttributeString("id", String.Format("attr_{0}_{1}", tag.Name, attr.Name)); writeElement(xw, "attrname", attr.Name); writeElement(xw, "attrshortinfo", attr.ShortInfo); writeElement(xw, "attrrequired", attr.Required); writeElement(xw, "attrformat", attr.Format); writeElement(xw, "attrinfo", attr.Info); xw.WriteEndElement(); } xw.WriteEndElement(); } xw.WriteEndElement(); xw.WriteEndDocument(); } } }