void mnuAddComponents_Click(object sender, EventArgs e) { if (currTreeView.SelectedNode == null) { return; } XmlNodeList components = WixFiles.WxsDocument.GetElementsByTagName("Component"); XmlNode node = currTreeView.SelectedNode.Tag as XmlNode; ArrayList componentIds = new ArrayList(); foreach (XmlNode component in components) { if (component.Attributes["Id"] != null && component.Attributes["Id"].Value != String.Empty) { componentIds.Add(component.Attributes["Id"].Value); } } SelectStringForm frm = new SelectStringForm("Select components"); frm.PossibleStrings = componentIds.ToArray(typeof(String)) as String[]; if (DialogResult.OK != frm.ShowDialog()) { return; } foreach (string componentId in frm.SelectedStrings) { TreeNode newNode = CreateNewSubElement("ComponentRef"); XmlNode newCompRef = newNode.Tag as XmlNode; XmlAttribute newAttr = WixFiles.WxsDocument.CreateAttribute("Id"); newNode.Text = componentId; newAttr.Value = componentId; newCompRef.Attributes.Append(newAttr); } }
public void OnNewPropertyGridItem(object sender, EventArgs e) { // Temporarily store the XmlAttributeAdapter XmlAttributeAdapter attAdapter = (XmlAttributeAdapter)CurrentGrid.SelectedObject; ArrayList attributes = new ArrayList(); string typeAttributeValue = null; XmlAttribute typeAttribute = attAdapter.XmlNode.Attributes["Type"]; if (typeAttribute != null) { typeAttributeValue = typeAttribute.Value; } XmlNodeList xmlAttributes = attAdapter.XmlNodeDefinition.SelectNodes("xs:attribute", WixFiles.XsdNsmgr); foreach (XmlNode at in xmlAttributes) { string attName = at.Attributes["name"].Value; if (!String.IsNullOrEmpty(typeAttributeValue) && !IsAttributeAllowedOnControlType(typeAttributeValue, attName)) { continue; } if (attAdapter.XmlNode.Attributes[attName] == null) { attributes.Add(attName); } } if (attAdapter.XmlNodeDefinition.Name == "xs:extension") { bool hasInnerText = false; foreach (GridItem it in CurrentGrid.SelectedGridItem.Parent.GridItems) { if (it.Label == "InnerText") { hasInnerText = true; break; } } if (hasInnerText == false) { attributes.Add("InnerText"); } } attributes.Sort(); SelectStringForm frm = new SelectStringForm(); frm.PossibleStrings = attributes.ToArray(typeof(String)) as String[]; if (DialogResult.OK != frm.ShowDialog() || frm.SelectedStrings.Length == 0) { return; } // Show dialog to choose from available items. XmlAttribute att = null; for (int i = 0; i < frm.SelectedStrings.Length; i++) { string newAttributeName = frm.SelectedStrings[i]; if (string.Equals(newAttributeName, "InnerText")) { attAdapter.ShowInnerTextIfEmpty = true; } else { WixFiles.UndoManager.BeginNewCommandRange(); att = WixFiles.WxsDocument.CreateAttribute(newAttributeName); attAdapter.XmlNode.Attributes.Append(att); } } CurrentGrid.SelectedObject = null; // Update the propertyGrid. CurrentGrid.SelectedObject = attAdapter; CurrentGrid.Update(); string firstNewAttributeName = frm.SelectedStrings[0]; foreach (GridItem it in CurrentGrid.SelectedGridItem.Parent.GridItems) { if (it.Label == firstNewAttributeName) { CurrentGrid.SelectedGridItem = it; break; } } }