private void contextMenuStripItem_Opening(object sender, CancelEventArgs e) { if (treeView.SelectedNode == null) { e.Cancel = true; return; } if (treeView.SelectedNode.Tag == null) { toolStripMenuItemCommand.Visible = false; toolStripMenuItemRename.Visible = false; toolStripMenuItemIconSettings.Visible = false; } else { foreach (ToolStripItem menuItem in contextMenuStrip.Items) { menuItem.Visible = true; } ItemProperty tag = (ItemProperty)treeView.SelectedNode.Tag; toolStripMenuItemRemoveIcon.Enabled = tag.HasIcon(); toolStripMenuItemCommand.Visible = !tag.IsSubMenu; if (tag.HasIcon()) { toolStripComboBoxIconSize.Enabled = true; if (tag.HasCustomIconSize()) { toolStripComboBoxIconSize.Text = tag.IconSize.ToString(); } else { toolStripComboBoxIconSize.Text = toolStripComboBoxIconSize.Items[0].ToString(); } } else { toolStripComboBoxIconSize.Enabled = false; toolStripComboBoxIconSize.Text = ""; } } if (treeView.SelectedNode.Parent == null) { toolStripMenuItemMoveToPrevLevel.Enabled = false; } else { toolStripMenuItemMoveToPrevLevel.Enabled = treeView.SelectedNode.Parent != null; } toolStripMenuItemMoveUp.Enabled = treeView.SelectedNode.PrevNode != null; toolStripMenuItemMoveDown.Enabled = treeView.SelectedNode.NextNode != null; }
void XML_GenerateContent(XmlDocument curDoc, XmlElement xmlParent, TreeNodeCollection nodes) { foreach (TreeNode curNode in nodes) { if (curNode.Tag == null) { xmlParent.AppendChild(curDoc.CreateElement("separator")); } else { XmlElement curXMLNode; ItemProperty tag = (ItemProperty)curNode.Tag; if (tag.IsSubMenu) { curXMLNode = curDoc.CreateElement("submenu"); } else { curXMLNode = curDoc.CreateElement("item"); curXMLNode.InnerText = "" + tag.Command + ""; if (tag.Arguments != "") { curXMLNode.InnerText += "|" + tag.Arguments + ""; } } curXMLNode.SetAttribute("text", curNode.Text); if (tag.HasIcon()) { curXMLNode.SetAttribute("icon", tag.IconFile); if (tag.IconIndex > 0) { curXMLNode.SetAttribute("index", tag.IconIndex.ToString()); } if (tag.HasCustomIconSize()) { curXMLNode.SetAttribute("size", tag.IconSize.ToString()); } } if (tag.IsSubMenu) { XML_GenerateContent(curDoc, curXMLNode, curNode.Nodes); } xmlParent.AppendChild(curXMLNode); } } }