diff options
Diffstat (limited to 'Mono.Addins')
-rw-r--r-- | Mono.Addins/Makefile.am | 2 | ||||
-rw-r--r-- | Mono.Addins/Mono.Addins.Description/AddinDescription.cs | 38 | ||||
-rw-r--r-- | Mono.Addins/Mono.Addins.Description/AddinProperty.cs | 37 | ||||
-rw-r--r-- | Mono.Addins/Mono.Addins.Description/AddinPropertyCollection.cs | 103 | ||||
-rw-r--r-- | Mono.Addins/Mono.Addins.csproj | 2 | ||||
-rw-r--r-- | Mono.Addins/Mono.Addins/Addin.cs | 7 | ||||
-rw-r--r-- | Mono.Addins/Mono.Addins/AddinInfo.cs | 63 |
7 files changed, 195 insertions, 57 deletions
diff --git a/Mono.Addins/Makefile.am b/Mono.Addins/Makefile.am index 8e5af50..d6e9639 100644 --- a/Mono.Addins/Makefile.am +++ b/Mono.Addins/Makefile.am @@ -35,6 +35,8 @@ FILES = \ Mono.Addins.Description/AddinDependency.cs \ Mono.Addins.Description/AddinDescription.cs \ Mono.Addins.Description/AddinFlags.cs \ + Mono.Addins.Description/AddinProperty.cs \ + Mono.Addins.Description/AddinPropertyCollection.cs \ Mono.Addins.Description/AssemblyDependency.cs \ Mono.Addins.Description/ConditionTypeDescription.cs \ Mono.Addins.Description/ConditionTypeDescriptionCollection.cs \ diff --git a/Mono.Addins/Mono.Addins.Description/AddinDescription.cs b/Mono.Addins/Mono.Addins.Description/AddinDescription.cs index 3d589e9..232e41b 100644 --- a/Mono.Addins/Mono.Addins.Description/AddinDescription.cs +++ b/Mono.Addins/Mono.Addins.Description/AddinDescription.cs @@ -28,6 +28,7 @@ using System; using System.Collections; +using System.Collections.Generic; using System.IO; using System.Xml; using System.Xml.Serialization; @@ -77,6 +78,8 @@ namespace Mono.Addins.Description ExtensionNodeDescription localizer; object[] fileInfo; + AddinPropertyCollectionImpl properties; + internal static BinaryXmlTypeMap typeMap; static AddinDescription () @@ -505,6 +508,17 @@ namespace Mono.Addins.Description } /// <summary> + /// Custom properties specified in the add-in header + /// </summary> + public AddinPropertyCollection Properties { + get { + if (properties == null) + properties = new AddinPropertyCollectionImpl (); + return properties; + } + } + + /// <summary> /// Adds an extension point. /// </summary> /// <returns> @@ -760,6 +774,28 @@ namespace Mono.Addins.Description if (extensionPoints != null) extensionPoints.SaveXml (elem); + + XmlElement oldHeader = (XmlElement) elem.SelectSingleNode ("Header"); + if (properties == null || properties.Count == 0) { + if (oldHeader != null) + elem.RemoveChild (oldHeader); + } else { + if (oldHeader == null) { + oldHeader = elem.OwnerDocument.CreateElement ("Header"); + if (elem.FirstChild != null) + elem.InsertBefore (elem, elem.FirstChild); + else + elem.AppendChild (oldHeader); + } + oldHeader.RemoveAll (); + foreach (var prop in properties) { + XmlElement propElem = elem.OwnerDocument.CreateElement (prop.Name); + if (!string.IsNullOrEmpty (prop.Locale)) + propElem.SetAttribute ("locale", prop.Locale); + propElem.InnerText = prop.Value ?? string.Empty; + oldHeader.AppendChild (propElem); + } + } } @@ -1023,6 +1059,7 @@ namespace Mono.Addins.Description writer.WriteValue ("FilesInfo", fileInfo); writer.WriteValue ("Localizer", localizer); writer.WriteValue ("flags", (int)flags); + writer.WriteValue ("Properties", properties); } void IBinaryXmlElement.Read (BinaryXmlReader reader) @@ -1051,6 +1088,7 @@ namespace Mono.Addins.Description fileInfo = (object[]) reader.ReadValue ("FilesInfo", null); localizer = (ExtensionNodeDescription) reader.ReadValue ("Localizer"); flags = (AddinFlags) reader.ReadInt32Value ("flags"); + properties = (AddinPropertyCollectionImpl) reader.ReadValue ("Properties", new AddinPropertyCollectionImpl ()); if (mainModule != null) mainModule.SetParent (this); diff --git a/Mono.Addins/Mono.Addins.Description/AddinProperty.cs b/Mono.Addins/Mono.Addins.Description/AddinProperty.cs new file mode 100644 index 0000000..e9b25ab --- /dev/null +++ b/Mono.Addins/Mono.Addins.Description/AddinProperty.cs @@ -0,0 +1,37 @@ +// +// AddinProperty.cs +// +// Author: +// Lluis Sanchez Gual <lluis@novell.com> +// +// Copyright (c) 2011 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +using System; + +namespace Mono.Addins.Description +{ + public class AddinProperty + { + public string Name { get; set; } + public string Value { get; set; } + public string Locale { get; set; } + } +} + diff --git a/Mono.Addins/Mono.Addins.Description/AddinPropertyCollection.cs b/Mono.Addins/Mono.Addins.Description/AddinPropertyCollection.cs new file mode 100644 index 0000000..63f2339 --- /dev/null +++ b/Mono.Addins/Mono.Addins.Description/AddinPropertyCollection.cs @@ -0,0 +1,103 @@ +// +// AddinPropertyCollection.cs +// +// Author: +// Lluis Sanchez Gual <lluis@novell.com> +// +// Copyright (c) 2011 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +using System; +using System.Collections.Generic; + +namespace Mono.Addins.Description +{ + public interface AddinPropertyCollection: IEnumerable<AddinProperty> + { + string GetPropertyValue (string name); + string GetPropertyValue (string name, string locale); + void SetPropertyValue (string name, string value); + void SetPropertyValue (string name, string value, string locale); + void RemoveProperty (string name); + void RemoveProperty (string name, string locale); + } + + class AddinPropertyCollectionImpl: List<AddinProperty>, AddinPropertyCollection + { + public string GetPropertyValue (string name) + { + return GetPropertyValue (name, null); + } + + public string GetPropertyValue (string name, string locale) + { + AddinProperty best = null; + foreach (var p in this) { + if (p.Name == name) { + if (best == null) + best = p; + else if (string.IsNullOrEmpty (p.Locale)) + best = p; + if (p.Locale == locale) + return p.Value; + } + } + if (best != null) + return best.Value; + else + return string.Empty; + } + + public void SetPropertyValue (string name, string value) + { + SetPropertyValue (name, value, null); + } + + public void SetPropertyValue (string name, string value, string locale) + { + foreach (var p in this) { + if (p.Name == name && p.Locale == locale) { + p.Value = value; + return; + } + } + AddinProperty prop = new AddinProperty (); + prop.Name = name; + prop.Value = value; + prop.Locale = locale; + Add (prop); + } + + public void RemoveProperty (string name) + { + RemoveProperty (name, null); + } + + public void RemoveProperty (string name, string locale) + { + foreach (var p in this) { + if (p.Name == name && p.Locale == locale) { + Remove (p); + return; + } + } + } + } +} + diff --git a/Mono.Addins/Mono.Addins.csproj b/Mono.Addins/Mono.Addins.csproj index 64efccc..b0310c4 100644 --- a/Mono.Addins/Mono.Addins.csproj +++ b/Mono.Addins/Mono.Addins.csproj @@ -134,6 +134,8 @@ <Compile Include="Mono.Addins.Database\AddinFileSystemExtension.cs" /> <Compile Include="Mono.Addins.Database\SetupLocal.cs" /> <Compile Include="Mono.Addins\ContentType.cs" /> + <Compile Include="Mono.Addins.Description\AddinProperty.cs" /> + <Compile Include="Mono.Addins.Description\AddinPropertyCollection.cs" /> </ItemGroup> <ItemGroup> <Content Include="Mono.Addins.dll.config"> diff --git a/Mono.Addins/Mono.Addins/Addin.cs b/Mono.Addins/Mono.Addins/Addin.cs index d11c30d..f2392cb 100644 --- a/Mono.Addins/Mono.Addins/Addin.cs +++ b/Mono.Addins/Mono.Addins/Addin.cs @@ -90,6 +90,13 @@ namespace Mono.Addins get { return this.AddinInfo.Name; } } + /// <summary> + /// Custom properties specified in the add-in header + /// </summary> + public AddinPropertyCollection Properties { + get { return this.AddinInfo.Properties; } + } + internal string PrivateDataPath { get { return Path.Combine (database.AddinPrivateDataPath, Path.GetFileNameWithoutExtension (Description.FileName)); } } diff --git a/Mono.Addins/Mono.Addins/AddinInfo.cs b/Mono.Addins/Mono.Addins/AddinInfo.cs index 41f7bf5..162f6bf 100644 --- a/Mono.Addins/Mono.Addins/AddinInfo.cs +++ b/Mono.Addins/Mono.Addins/AddinInfo.cs @@ -51,8 +51,9 @@ namespace Mono.Addins bool isroot; DependencyCollection dependencies; DependencyCollection optionalDependencies; + AddinPropertyCollection properties; - public AddinInfo () + private AddinInfo () { dependencies = new DependencyCollection (); optionalDependencies = new DependencyCollection (); @@ -62,7 +63,6 @@ namespace Mono.Addins get { return Addin.GetFullId (namspace, id, version); } } - [XmlElement ("Id")] public string LocalId { get { return id; } set { id = value; } @@ -130,69 +130,16 @@ namespace Mono.Addins set { defaultEnabled = value; } } - [XmlArrayItem ("AddinDependency", typeof(AddinDependency))] - [XmlArrayItem ("AssemblyDependency", typeof(AssemblyDependency))] public DependencyCollection Dependencies { get { return dependencies; } } - [XmlArrayItem ("AddinDependency", typeof(AddinDependency))] - [XmlArrayItem ("AssemblyDependency", typeof(AssemblyDependency))] public DependencyCollection OptionalDependencies { get { return optionalDependencies; } } - public static AddinInfo ReadFromAddinFile (StreamReader r) - { - XmlDocument doc = new XmlDocument (); - doc.Load (r); - r.Close (); - - AddinInfo info = new AddinInfo (); - info.id = doc.DocumentElement.GetAttribute ("id"); - info.namspace = doc.DocumentElement.GetAttribute ("namespace"); - info.name = doc.DocumentElement.GetAttribute ("name"); - if (info.id == "") info.id = info.name; - info.version = doc.DocumentElement.GetAttribute ("version"); - info.author = doc.DocumentElement.GetAttribute ("author"); - info.copyright = doc.DocumentElement.GetAttribute ("copyright"); - info.url = doc.DocumentElement.GetAttribute ("url"); - info.description = doc.DocumentElement.GetAttribute ("description"); - info.category = doc.DocumentElement.GetAttribute ("category"); - info.baseVersion = doc.DocumentElement.GetAttribute ("compatVersion"); - - string s = doc.DocumentElement.GetAttribute ("defaultEnabled"); - info.defaultEnabled = s.Length == 0 || s == "true" || s == "yes"; - - s = doc.DocumentElement.GetAttribute ("isRoot"); - if (s.Length == 0) s = doc.DocumentElement.GetAttribute ("isroot"); - info.isroot = s == "true" || s == "yes"; - - ReadDependencies (info.Dependencies, info.OptionalDependencies, doc.DocumentElement); - - return info; - } - - static void ReadDependencies (DependencyCollection deps, DependencyCollection opDeps, XmlElement elem) - { - foreach (XmlElement dep in elem.SelectNodes ("Dependencies/Addin")) { - AddinDependency adep = new AddinDependency (); - adep.AddinId = dep.GetAttribute ("id"); - string v = dep.GetAttribute ("version"); - if (v.Length != 0) - adep.Version = v; - deps.Add (adep); - } - - foreach (XmlElement dep in elem.SelectNodes ("Dependencies/Assembly")) { - AssemblyDependency adep = new AssemblyDependency (); - adep.FullName = dep.GetAttribute ("name"); - adep.Package = dep.GetAttribute ("package"); - deps.Add (adep); - } - - foreach (XmlElement mod in elem.SelectNodes ("Module")) - ReadDependencies (opDeps, opDeps, mod); + public AddinPropertyCollection Properties { + get { return properties; } } internal static AddinInfo ReadFromDescription (AddinDescription description) @@ -218,6 +165,8 @@ namespace Mono.Addins foreach (Dependency dep in mod.Dependencies) info.OptionalDependencies.Add (dep); } + info.properties = description.Properties; + return info; } |