diff options
-rw-r--r-- | Mono.Addins/Makefile.am | 2 | ||||
-rw-r--r-- | Mono.Addins/Mono.Addins.Database/AddinScanner.cs | 20 | ||||
-rw-r--r-- | Mono.Addins/Mono.Addins.Description/AddinDescription.cs | 9 | ||||
-rw-r--r-- | Mono.Addins/Mono.Addins.csproj | 2 | ||||
-rw-r--r-- | Mono.Addins/Mono.Addins/AddinDescriptionAttribute.cs | 73 | ||||
-rw-r--r-- | Mono.Addins/Mono.Addins/AddinNameAttribute.cs | 73 | ||||
-rw-r--r-- | Test/UnitTests/ExtensionModel/Properties.cs | 2 | ||||
-rw-r--r-- | Test/UnitTests/TestAddinDescription.cs | 8 |
8 files changed, 186 insertions, 3 deletions
diff --git a/Mono.Addins/Makefile.am b/Mono.Addins/Makefile.am index 9d72007..80d6197 100644 --- a/Mono.Addins/Makefile.am +++ b/Mono.Addins/Makefile.am @@ -74,6 +74,7 @@ FILES = \ Mono.Addins/AddinAttribute.cs \ Mono.Addins/AddinAuthorAttribute.cs \ Mono.Addins/AddinDependencyAttribute.cs \ + Mono.Addins/AddinDescriptionAttribute.cs \ Mono.Addins/AddinEngine.cs \ Mono.Addins/AddinErrorEventArgs.cs \ Mono.Addins/AddinEventArgs.cs \ @@ -82,6 +83,7 @@ FILES = \ Mono.Addins/AddinLocalizerGettextAttribute.cs \ Mono.Addins/AddinManager.cs \ Mono.Addins/AddinModuleAttribute.cs \ + Mono.Addins/AddinNameAttribute.cs \ Mono.Addins/AddinPropertyAttribute.cs \ Mono.Addins/AddinRegistry.cs \ Mono.Addins/AddinRootAttribute.cs \ diff --git a/Mono.Addins/Mono.Addins.Database/AddinScanner.cs b/Mono.Addins/Mono.Addins.Database/AddinScanner.cs index bef70d7..8206a83 100644 --- a/Mono.Addins/Mono.Addins.Database/AddinScanner.cs +++ b/Mono.Addins/Mono.Addins.Database/AddinScanner.cs @@ -265,7 +265,7 @@ namespace Mono.Addins.Database } // Check errors in the description - StringCollection errors = config.Verify (); + StringCollection errors = config.Verify (fs); if (database.IsGlobalRegistry && config.AddinId.IndexOf ('.') == -1) { errors.Add ("Add-ins registered in the global registry must have a namespace."); @@ -742,12 +742,30 @@ namespace Mono.Addins.Database config.Author += ", " + author.Name; } + // Name + + atts = reflector.GetCustomAttributes (asm, typeof(AddinNameAttribute), false); + foreach (AddinNameAttribute at in atts) { + if (string.IsNullOrEmpty (at.Locale)) + config.Name = at.Name; + else + config.Properties.SetPropertyValue ("Name", at.Name, at.Locale); + } + // Description object catt = reflector.GetCustomAttribute (asm, typeof(AssemblyDescriptionAttribute), false); if (catt != null && config.Description.Length == 0) config.Description = ((AssemblyDescriptionAttribute)catt).Description; + atts = reflector.GetCustomAttributes (asm, typeof(AddinDescriptionAttribute), false); + foreach (AddinDescriptionAttribute at in atts) { + if (string.IsNullOrEmpty (at.Locale)) + config.Description = at.Description; + else + config.Properties.SetPropertyValue ("Description", at.Description, at.Locale); + } + // Copyright catt = reflector.GetCustomAttribute (asm, typeof(AssemblyCopyrightAttribute), false); diff --git a/Mono.Addins/Mono.Addins.Description/AddinDescription.cs b/Mono.Addins/Mono.Addins.Description/AddinDescription.cs index 270a0cc..700d94b 100644 --- a/Mono.Addins/Mono.Addins.Description/AddinDescription.cs +++ b/Mono.Addins/Mono.Addins.Description/AddinDescription.cs @@ -174,7 +174,7 @@ namespace Mono.Addins.Description } set { name = value; } } - + /// <summary> /// Gets or sets the version. /// </summary> @@ -969,6 +969,11 @@ namespace Mono.Addins.Description /// </remarks> public StringCollection Verify () { + return Verify (new AddinFileSystemExtension ()); + } + + internal StringCollection Verify (AddinFileSystemExtension fs) + { StringCollection errors = new StringCollection (); if (IsRoot) { @@ -1003,7 +1008,7 @@ namespace Mono.Addins.Description if (bp != null) { foreach (string file in AllFiles) { string asmFile = Path.Combine (bp, file); - if (!File.Exists (asmFile)) + if (!fs.FileExists (asmFile)) errors.Add ("The file '" + asmFile + "' referenced in the manifest could not be found."); } } diff --git a/Mono.Addins/Mono.Addins.csproj b/Mono.Addins/Mono.Addins.csproj index 37a4308..7b534a9 100644 --- a/Mono.Addins/Mono.Addins.csproj +++ b/Mono.Addins/Mono.Addins.csproj @@ -139,6 +139,8 @@ <Compile Include="Mono.Addins.Description\AddinProperty.cs" /> <Compile Include="Mono.Addins.Description\AddinPropertyCollection.cs" /> <Compile Include="Mono.Addins\AddinPropertyAttribute.cs" /> + <Compile Include="Mono.Addins\AddinNameAttribute.cs" /> + <Compile Include="Mono.Addins\AddinDescriptionAttribute.cs" /> </ItemGroup> <ItemGroup> <Content Include="Mono.Addins.dll.config"> diff --git a/Mono.Addins/Mono.Addins/AddinDescriptionAttribute.cs b/Mono.Addins/Mono.Addins/AddinDescriptionAttribute.cs new file mode 100644 index 0000000..d79c4d8 --- /dev/null +++ b/Mono.Addins/Mono.Addins/AddinDescriptionAttribute.cs @@ -0,0 +1,73 @@ +// +// AddinDescriptionAttribute.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 +{ + /// <summary> + /// Describes the purpose of an add-in or add-in root + /// </summary> + [AttributeUsage (AttributeTargets.Assembly, AllowMultiple = true)] + public class AddinDescriptionAttribute: Attribute + { + /// <summary> + /// Initializes a new instance of the <see cref="Mono.Addins.AddinDescriptionAttribute"/> class. + /// </summary> + /// <param name='description'> + /// Description of the add-in + /// </param> + public AddinDescriptionAttribute (string description) + { + Description = description; + } + + /// <summary> + /// Initializes a new instance of the <see cref="Mono.Addins.AddinDescriptionAttribute"/> class. + /// </summary> + /// <param name='description'> + /// Description of the add-in + /// </param> + /// <param name='locale'> + /// Locale of the description (for example, 'en-US', or 'en') + /// </param> + public AddinDescriptionAttribute (string description, string locale) + { + Description = description; + Locale = locale; + } + + /// <value> + /// Description of the add-in + /// </value> + public string Description { get; set; } + + /// <summary> + /// Locale of the description (for example, 'en-US', or 'en') + /// </summary> + public string Locale { get; set; } + } +} + diff --git a/Mono.Addins/Mono.Addins/AddinNameAttribute.cs b/Mono.Addins/Mono.Addins/AddinNameAttribute.cs new file mode 100644 index 0000000..32f66c4 --- /dev/null +++ b/Mono.Addins/Mono.Addins/AddinNameAttribute.cs @@ -0,0 +1,73 @@ +// +// AddinNameAttribute.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 +{ + /// <summary> + /// Sets the display name of an add-in + /// </summary> + [AttributeUsage (AttributeTargets.Assembly, AllowMultiple = true)] + public class AddinNameAttribute: Attribute + { + /// <summary> + /// Initializes a new instance of the <see cref="Mono.Addins.AddinNameAttribute"/> class. + /// </summary> + /// <param name='name'> + /// Name of the add-in + /// </param> + public AddinNameAttribute (string name) + { + Name = name; + } + + /// <summary> + /// Initializes a new instance of the <see cref="Mono.Addins.AddinNameAttribute"/> class. + /// </summary> + /// <param name='name'> + /// Name of the add-in + /// </param> + /// <param name='locale'> + /// Locale of the name (for example, 'en-US', or 'en') + /// </param> + public AddinNameAttribute (string name, string locale) + { + Name = name; + Locale = locale; + } + + /// <value> + /// Name of the add-in + /// </value> + public string Name { get; set; } + + /// <summary> + /// Locale of the name (for example, 'en-US', or 'en') + /// </summary> + public string Locale { get; set; } + } +} + diff --git a/Test/UnitTests/ExtensionModel/Properties.cs b/Test/UnitTests/ExtensionModel/Properties.cs index e1ff905..d659114 100644 --- a/Test/UnitTests/ExtensionModel/Properties.cs +++ b/Test/UnitTests/ExtensionModel/Properties.cs @@ -29,3 +29,5 @@ using Mono.Addins; [assembly:AddinProperty ("Prop2", "Val2")] [assembly:AddinProperty ("Prop2", "ca-ES", "Val2Cat")] +[assembly:AddinName ("Una aplicación simple", "es")] +[assembly:AddinDescription ("Descripción de SimpleApp", "es")] diff --git a/Test/UnitTests/TestAddinDescription.cs b/Test/UnitTests/TestAddinDescription.cs index 731b480..f2bf97f 100644 --- a/Test/UnitTests/TestAddinDescription.cs +++ b/Test/UnitTests/TestAddinDescription.cs @@ -114,6 +114,14 @@ namespace UnitTests Assert.AreEqual ("Val1Cat", ad.Properties.GetPropertyValue ("Prop1")); Assert.AreEqual ("Val2", ad.Properties.GetPropertyValue ("Prop2","en-US")); Assert.AreEqual ("Val2Cat", ad.Properties.GetPropertyValue ("Prop2")); + + oldc = System.Threading.Thread.CurrentThread.CurrentCulture; + System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("es-ES"); + + Assert.AreEqual ("Una aplicación simple", ad.Name); + Assert.AreEqual ("Descripción de SimpleApp", ad.Description.Description); + + System.Threading.Thread.CurrentThread.CurrentCulture = oldc; } } } |