コード例 #1
0
ファイル: XmlAttributeAdapter.cs プロジェクト: xwiz/WixEdit
        public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            if (xmlNodeDefinition == null) {
                // maybe the existing properties can be edited?
                ArrayList properties = new ArrayList();
                foreach (XmlAttribute xmlAttribute in xmlNode.Attributes) {
                    // We could add an UITypeEditor if desired
                    ArrayList attrs = new ArrayList();
                    attrs.Add(new EditorAttribute(typeof(UITypeEditor), typeof(UITypeEditor)));
                    attrs.Add(new CategoryAttribute("WXS Attribute"));
                    attrs.Add(new TypeConverterAttribute(typeof(StringConverter)));

                    // Make Attribute array
                    Attribute[] attrArray = (Attribute[])attrs.ToArray(typeof(Attribute));

                    // Create and add PropertyDescriptor
                    XmlAttributePropertyDescriptor pd = new XmlAttributePropertyDescriptor(wixFiles, xmlAttribute, null,
                        xmlAttribute.Name, attrArray);

                    properties.Add(pd);
                }

                PropertyDescriptor[] propertiesArray = properties.ToArray(typeof(PropertyDescriptor)) as PropertyDescriptor[];

                return new PropertyDescriptorCollection(propertiesArray);
            }

            ArrayList props = new ArrayList();

            // Show all existing + required elements
            XmlNodeList xmlAttributeDefinitions = xmlNodeDefinition.SelectNodes("xs:attribute", wixFiles.XsdNsmgr);
            foreach(XmlNode xmlAttributeDefinition in xmlAttributeDefinitions) {
                XmlAttribute xmlAttribute = xmlNode.Attributes[xmlAttributeDefinition.Attributes["name"].Value];

                if (xmlAttribute == null) {
                    if (xmlAttributeDefinition.Attributes["use"] == null ||
                        xmlAttributeDefinition.Attributes["use"].Value != "required") {
                        continue;
                    }

                    // If there is no attibute present, create one.
                    if (xmlAttribute == null) {
                        // Do not call UndoManager.BeginNewCommandRange here, because this can happen after
                        // an undo/redo action when viewing some node. That would mess up the undo mechanism.
                        // So the adding of mandatory attributes will be added to the last undo command sequence.

                        xmlAttribute = xmlNode.OwnerDocument.CreateAttribute(xmlAttributeDefinition.Attributes["name"].Value);
                        xmlNode.Attributes.Append(xmlAttribute);
                    }
                }

                ArrayList attrs = new ArrayList();

                // Add default attributes Category, TypeConverter and Description
                attrs.Add(new CategoryAttribute("WXS Attribute"));
                attrs.Add(new TypeConverterAttribute(GetAttributeTypeConverter(xmlAttributeDefinition)));

                // Get some documentation
                XmlNode deprecated = xmlAttributeDefinition.SelectSingleNode("xs:annotation/xs:appinfo/xse:deprecated", wixFiles.XsdNsmgr);
                XmlNode documentation = xmlAttributeDefinition.SelectSingleNode("xs:annotation/xs:documentation", wixFiles.XsdNsmgr);
                if(deprecated != null || documentation != null) {
                    string docuString = "";
                    if(deprecated != null) {
                        docuString = "** DEPRECATED **\r\n";
                    }

                    if (documentation != null) {
                        docuString = documentation.InnerText;
                        docuString = docuString.Replace("\t", " ");
                        docuString = docuString.Replace("\r\n", " ");
                    }

                    string tmpDocuString = docuString;
                    do {
                        docuString = tmpDocuString;
                        tmpDocuString = docuString.Replace("  ", " ");
                    } while (docuString != tmpDocuString);

                    docuString = tmpDocuString;
                    docuString = docuString.Trim(' ');

                    attrs.Add(new DescriptionAttribute(docuString));
                }

                bool needsBrowse = false;
                if (xmlAttributeDefinition.Attributes["name"] != null) {
                    string attName = xmlNodeElement.Attributes["name"].Value;

                    if (xmlAttributeDefinition.Attributes["name"].Value == "SourceFile") {
                        needsBrowse = true;
                    } else if (xmlAttributeDefinition.Attributes["name"].Value == "Source") {
                        needsBrowse = true;
                    } else if (xmlAttributeDefinition.Attributes["name"].Value == "FileSource") {
                        needsBrowse = true;
                    } else if (xmlAttributeDefinition.Attributes["name"].Value == "Layout") {
                        needsBrowse = true;
                    } else if (xmlAttributeDefinition.Attributes["name"].Value == "src") {
                        needsBrowse = true;
                    }
                }

                if (needsBrowse) {
                    // We could add an UITypeEditor if desired
                    attrs.Add(new EditorAttribute(typeof(FilteredFileNameEditor),typeof(System.Drawing.Design.UITypeEditor)));

                    // Make Attribute array
                    Attribute[] attrArray = (Attribute[])attrs.ToArray(typeof(Attribute));

                    // BinaryElementPropertyDescriptor also uses the src attribute, and a possibility to use relative paths.
                    FileXmlAttributePropertyDescriptor pd = new FileXmlAttributePropertyDescriptor(xmlNode, wixFiles, xmlAttributeDefinition, xmlAttributeDefinition.Attributes["name"].Value, attrArray);

                    props.Add(pd);
                } else {
                    // We could add an UITypeEditor if desired
                    // attrs.Add(new EditorAttribute(?property.EditorTypeName?, typeof(UITypeEditor)));
                    attrs.Add(new EditorAttribute(GetAttributeEditor(xmlAttributeDefinition), typeof(UITypeEditor)));

                    // Make Attribute array
                    Attribute[] attrArray = (Attribute[])attrs.ToArray(typeof(Attribute));

                    // Create and add PropertyDescriptor
                    XmlAttributePropertyDescriptor pd = new XmlAttributePropertyDescriptor(wixFiles, xmlAttribute, xmlAttributeDefinition,
                        xmlAttributeDefinition.Attributes["name"].Value, attrArray);

                    props.Add(pd);
                }
            }

            // Add InnerText if required or present.
            if (
                (XmlNodeDefinition.Name == "xs:extension" &&
                    ( (xmlNode.InnerText != null && xmlNode.InnerText.Length > 0) || showInnerTextIfEmpty == true) ) ||
                (XmlNodeDefinition.Name == "xs:element" && showInnerTextIfEmpty == true) ) {
                ArrayList attrs = new ArrayList();

                // Add default attributes Category, TypeConverter and Description
                attrs.Add(new CategoryAttribute("WXS Attribute"));
                attrs.Add(new TypeConverterAttribute(typeof(StringConverter)));
                attrs.Add(new EditorAttribute(typeof(MultiLineUITypeEditor), typeof(UITypeEditor)));
                attrs.Add(new DescriptionAttribute("InnerText of the element."));

                // Make Attribute array
                Attribute[] attrArray = (Attribute[])attrs.ToArray(typeof(Attribute));

                // Create and add PropertyDescriptor
                InnerTextPropertyDescriptor pd = new InnerTextPropertyDescriptor(wixFiles, xmlNode, attrArray);

                props.Add(pd);
            }

            if (editSubNodes)
            {
                XmlNodeList subNodes = xmlNode.SelectNodes("*", WixFiles.WxsNsmgr);
                if (subNodes.Count >= 1)
                {
                    ArrayList attrs = new ArrayList();

                    if (subNodes.Count == 1)
                    {
                        attrs.Add(new EditorAttribute(typeof(SearchElementTypeEditor), typeof(UITypeEditor)));
                        attrs.Add(new DescriptionAttribute("Sub Elements of the element."));
                    }

                    // Make Attribute array
                    Attribute[] attrArray = (Attribute[])attrs.ToArray(typeof(Attribute));

                    // Create and add PropertyDescriptor
                    PropertySearchElementPropertyDescriptor pd = new PropertySearchElementPropertyDescriptor(wixFiles, xmlNode,
                        "SubElements", attrArray);

                    props.Add(pd);
                }
            }

            PropertyDescriptor[] propArray = props.ToArray(typeof(PropertyDescriptor)) as PropertyDescriptor[];

            return new PropertyDescriptorCollection(propArray);
        }
コード例 #2
0
        public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            if (xmlNodeDefinition == null)
            {
                // maybe the existing properties can be edited?
                ArrayList properties = new ArrayList();
                foreach (XmlAttribute xmlAttribute in xmlNode.Attributes)
                {
                    // We could add an UITypeEditor if desired
                    ArrayList attrs = new ArrayList();
                    attrs.Add(new EditorAttribute(typeof(UITypeEditor), typeof(UITypeEditor)));
                    attrs.Add(new CategoryAttribute("WXS Attribute"));
                    attrs.Add(new TypeConverterAttribute(typeof(StringConverter)));


                    // Make Attribute array
                    Attribute[] attrArray = (Attribute[])attrs.ToArray(typeof(Attribute));

                    // Create and add PropertyDescriptor
                    XmlAttributePropertyDescriptor pd = new XmlAttributePropertyDescriptor(wixFiles, xmlAttribute, null,
                                                                                           xmlAttribute.Name, attrArray);

                    properties.Add(pd);
                }


                PropertyDescriptor[] propertiesArray = properties.ToArray(typeof(PropertyDescriptor)) as PropertyDescriptor[];

                return(new PropertyDescriptorCollection(propertiesArray));
            }

            ArrayList props = new ArrayList();

            // Show all existing + required elements
            XmlNodeList xmlAttributeDefinitions = xmlNodeDefinition.SelectNodes("xs:attribute", wixFiles.XsdNsmgr);

            foreach (XmlNode xmlAttributeDefinition in xmlAttributeDefinitions)
            {
                XmlAttribute xmlAttribute = xmlNode.Attributes[xmlAttributeDefinition.Attributes["name"].Value];

                if (xmlAttribute == null)
                {
                    if (xmlAttributeDefinition.Attributes["use"] == null ||
                        xmlAttributeDefinition.Attributes["use"].Value != "required")
                    {
                        continue;
                    }

                    // If there is no attibute present, create one.
                    if (xmlAttribute == null)
                    {
                        // Do not call UndoManager.BeginNewCommandRange here, because this can happen after
                        // an undo/redo action when viewing some node. That would mess up the undo mechanism.
                        // So the adding of mandatory attributes will be added to the last undo command sequence.

                        xmlAttribute = xmlNode.OwnerDocument.CreateAttribute(xmlAttributeDefinition.Attributes["name"].Value);
                        xmlNode.Attributes.Append(xmlAttribute);
                    }
                }

                ArrayList attrs = new ArrayList();

                // Add default attributes Category, TypeConverter and Description
                attrs.Add(new CategoryAttribute("WXS Attribute"));
                attrs.Add(new TypeConverterAttribute(GetAttributeTypeConverter(xmlAttributeDefinition)));

                // Get some documentation
                XmlNode deprecated    = xmlAttributeDefinition.SelectSingleNode("xs:annotation/xs:appinfo/xse:deprecated", wixFiles.XsdNsmgr);
                XmlNode documentation = xmlAttributeDefinition.SelectSingleNode("xs:annotation/xs:documentation", wixFiles.XsdNsmgr);
                if (deprecated != null || documentation != null)
                {
                    string docuString = "";
                    if (deprecated != null)
                    {
                        docuString = "** DEPRECATED **\r\n";
                    }

                    if (documentation != null)
                    {
                        docuString = documentation.InnerText;
                        docuString = docuString.Replace("\t", " ");
                        docuString = docuString.Replace("\r\n", " ");
                    }

                    string tmpDocuString = docuString;
                    do
                    {
                        docuString    = tmpDocuString;
                        tmpDocuString = docuString.Replace("  ", " ");
                    } while (docuString != tmpDocuString);

                    docuString = tmpDocuString;
                    docuString = docuString.Trim(' ');

                    attrs.Add(new DescriptionAttribute(docuString));
                }

                bool needsBrowse = false;
                if (xmlAttributeDefinition.Attributes["name"] != null)
                {
                    string attName = xmlNodeElement.Attributes["name"].Value;

                    if (xmlAttributeDefinition.Attributes["name"].Value == "SourceFile")
                    {
                        needsBrowse = true;
                    }
                    else if (xmlAttributeDefinition.Attributes["name"].Value == "Source")
                    {
                        needsBrowse = true;
                    }
                    else if (xmlAttributeDefinition.Attributes["name"].Value == "FileSource")
                    {
                        needsBrowse = true;
                    }
                    else if (xmlAttributeDefinition.Attributes["name"].Value == "Layout")
                    {
                        needsBrowse = true;
                    }
                    else if (xmlAttributeDefinition.Attributes["name"].Value == "src")
                    {
                        needsBrowse = true;
                    }
                }

                if (needsBrowse)
                {
                    // We could add an UITypeEditor if desired
                    attrs.Add(new EditorAttribute(typeof(FilteredFileNameEditor), typeof(System.Drawing.Design.UITypeEditor)));

                    // Make Attribute array
                    Attribute[] attrArray = (Attribute[])attrs.ToArray(typeof(Attribute));

                    // BinaryElementPropertyDescriptor also uses the src attribute, and a possibility to use relative paths.
                    FileXmlAttributePropertyDescriptor pd = new FileXmlAttributePropertyDescriptor(xmlNode, wixFiles, xmlAttributeDefinition, xmlAttributeDefinition.Attributes["name"].Value, attrArray);

                    props.Add(pd);
                }
                else
                {
                    // We could add an UITypeEditor if desired
                    // attrs.Add(new EditorAttribute(?property.EditorTypeName?, typeof(UITypeEditor)));
                    attrs.Add(new EditorAttribute(GetAttributeEditor(xmlAttributeDefinition), typeof(UITypeEditor)));

                    // Make Attribute array
                    Attribute[] attrArray = (Attribute[])attrs.ToArray(typeof(Attribute));

                    // Create and add PropertyDescriptor
                    XmlAttributePropertyDescriptor pd = new XmlAttributePropertyDescriptor(wixFiles, xmlAttribute, xmlAttributeDefinition,
                                                                                           xmlAttributeDefinition.Attributes["name"].Value, attrArray);

                    props.Add(pd);
                }
            }

            // Add InnerText if required or present.
            if (
                (XmlNodeDefinition.Name == "xs:extension" &&
                 ((xmlNode.InnerText != null && xmlNode.InnerText.Length > 0) || showInnerTextIfEmpty == true)) ||
                (XmlNodeDefinition.Name == "xs:element" && showInnerTextIfEmpty == true))
            {
                ArrayList attrs = new ArrayList();

                // Add default attributes Category, TypeConverter and Description
                attrs.Add(new CategoryAttribute("WXS Attribute"));
                attrs.Add(new TypeConverterAttribute(typeof(StringConverter)));
                attrs.Add(new EditorAttribute(typeof(MultiLineUITypeEditor), typeof(UITypeEditor)));
                attrs.Add(new DescriptionAttribute("InnerText of the element."));


                // Make Attribute array
                Attribute[] attrArray = (Attribute[])attrs.ToArray(typeof(Attribute));

                // Create and add PropertyDescriptor
                InnerTextPropertyDescriptor pd = new InnerTextPropertyDescriptor(wixFiles, xmlNode, attrArray);

                props.Add(pd);
            }

            if (editSubNodes)
            {
                XmlNodeList subNodes = xmlNode.SelectNodes("*", WixFiles.WxsNsmgr);
                if (subNodes.Count >= 1)
                {
                    ArrayList attrs = new ArrayList();

                    if (subNodes.Count == 1)
                    {
                        attrs.Add(new EditorAttribute(typeof(SearchElementTypeEditor), typeof(UITypeEditor)));
                        attrs.Add(new DescriptionAttribute("Sub Elements of the element."));
                    }

                    // Make Attribute array
                    Attribute[] attrArray = (Attribute[])attrs.ToArray(typeof(Attribute));

                    // Create and add PropertyDescriptor
                    PropertySearchElementPropertyDescriptor pd = new PropertySearchElementPropertyDescriptor(wixFiles, xmlNode,
                                                                                                             "SubElements", attrArray);

                    props.Add(pd);
                }
            }

            PropertyDescriptor[] propArray = props.ToArray(typeof(PropertyDescriptor)) as PropertyDescriptor[];

            return(new PropertyDescriptorCollection(propArray));
        }