Ejemplo n.º 1
0
        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)
                {
                    string name = component.Attributes["Id"].Value;

                    if (!node.ChildNodes.Cast <XmlNode>().Any(x => GetDisplayName(x) == name))
                    {
                        componentIds.Add(name);
                    }
                }
            }

            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);
            }
        }
Ejemplo n.º 2
0
        public void OnNewPropertyGridItem(object sender, EventArgs e)
        {
            wixFiles.UndoManager.BeginNewCommandRange();

            // Temporarily store the XmlAttributeAdapter
            XmlAttributeAdapter attAdapter = (XmlAttributeAdapter)elementPropertyGrid.SelectedObject;

            ArrayList attributes = new ArrayList();

            XmlNodeList xmlAttributes = attAdapter.XmlNodeDefinition.SelectNodes("xs:attribute", wixFiles.XsdNsmgr);

            foreach (XmlNode at in xmlAttributes)
            {
                string attName = at.Attributes["name"].Value;
                if (attAdapter.XmlNode.Attributes[attName] == null)
                {
                    attributes.Add(attName);
                }
            }

            if (attAdapter.XmlNodeDefinition.Name == "xs:extension")
            {
                bool hasInnerText = false;
                foreach (GridItem it in elementPropertyGrid.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())
            {
                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
                {
                    att = wixFiles.WxsDocument.CreateAttribute(newAttributeName);
                    attAdapter.XmlNode.Attributes.Append(att);
                }
            }

            // resetting the elementPropertyGrid.
            elementPropertyGrid.SelectedObject = null;
            // Update the elementPropertyGrid.
            elementPropertyGrid.SelectedObject = attAdapter;
            elementPropertyGrid.Update();

            string firstNewAttributeName = frm.SelectedStrings[0];

            foreach (GridItem it in elementPropertyGrid.SelectedGridItem.Parent.GridItems)
            {
                if (it.Label == firstNewAttributeName)
                {
                    elementPropertyGrid.SelectedGridItem = it;
                    break;
                }
            }
        }