protected TreeNode CreateNewSubElement(string typeName) { if (currTreeView.SelectedNode == null) { return(null); } XmlNode node = currTreeView.SelectedNode.Tag as XmlNode; if (node == null) { return(null); } WixFiles.UndoManager.BeginNewCommandRange(); XmlElement newElement = node.OwnerDocument.CreateElement(typeName, WixFiles.GetNamespaceUri(typeName)); TreeNode control = new TreeNode(typeName); control.Tag = newElement; int imageIndex = ImageListFactory.GetImageIndex(typeName); if (imageIndex >= 0) { control.ImageIndex = imageIndex; control.SelectedImageIndex = imageIndex; } InsertNewXmlNode(node, newElement); currTreeView.SelectedNode.Nodes.Add(control); return(control); }
public void OnNewSubPropertyGridItem(object sender, EventArgs e) { XmlElement selectedElement = (XmlElement)GetSelectedGridObject(); MenuItem menuItem = sender as MenuItem; string typeName = menuItem.Text; // Remove the value attribute. if (selectedElement.HasAttribute("Value")) { if (selectedElement.GetAttribute("Value") != string.Empty) { if (DialogResult.No == MessageBox.Show(String.Format("The property has the value \"{0}\", adding an element {1} will remove this value.\r\n\r\nContinue adding the sub element {1}?", selectedElement.GetAttribute("Value"), typeName), "Remove existing property value?", MessageBoxButtons.YesNo)) { return; } } WixFiles.UndoManager.BeginNewCommandRange(); selectedElement.RemoveAttribute("Value"); } else if (selectedElement.InnerText != string.Empty) { if (DialogResult.No == MessageBox.Show(String.Format("The property has the value \"{0}\", adding an element {1} will remove this value.\r\n\r\nContinue adding the sub element {1}?", selectedElement.InnerText, typeName), "Remove existing property value?", MessageBoxButtons.YesNo)) { return; } WixFiles.UndoManager.BeginNewCommandRange(); selectedElement.InnerText = string.Empty; } else { WixFiles.UndoManager.BeginNewCommandRange(); } XmlElement newElement = selectedElement.OwnerDocument.CreateElement(typeName, WixFiles.GetNamespaceUri(typeName)); selectedElement.AppendChild(newElement); RefreshGrid(); }