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="tag"></param> private void showTagPanel(KagTag tag) { tagPanel.Visible = true; tagPanel.Dock = DockStyle.Fill; if (tag != null) { tagNameBox.Text = tag.Name; tagGropuBox.Text = tag.Group; tagShortInfoBox.Text = tag.ShortInfo; tagLongInfoBox.Text = tag.Remarks; } defaultPanel.Visible = false; attrPanel.Visible = false; }
/// <summary> /// 新規にタグ追加 /// </summary> private void menuItemPopAddTag_Click(object sender, EventArgs e) { if (tagTreeView.Nodes.Count == 0) { return; //まだ何も開いていないときは何もしない } string name = "NewTag"; TreeNode node = tagTreeView.Nodes[0].Nodes.Add(name); //tdbノードの下に追加する KagTag tag = new KagTag(); tag.Name = name; node.Tag = tag; showNode(node); }
/// <summary> /// タグノードを読み込む /// </summary> /// <param name="tagElement">タグエレメント</param> private TreeNode readTagNode(XmlElement tagElement) { TreeNode tagNode = new TreeNode(); KagTag tag = new KagTag(); foreach (XmlElement node in tagElement.ChildNodes) { switch (node.Name) { case "tagname": tag.Name = node.InnerText; break; case "group": tag.Group = node.InnerText; break; case "tagshortinfo": tag.ShortInfo = node.InnerText; break; case "tagremarks": tag.Remarks = convertReadString(node.InnerXml); break; case "attr": TreeNode attrNode = readTagAttrNode(node); if (attrNode == null) { //取得できなかった時、またはすでに登録済みの場合は登録しない break; } tagNode.Nodes.Add(attrNode); break; } } tagNode.Text = tag.Name; tagNode.Tag = tag; return(tagNode); }
/// <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(); } } }