diff options
author | Lluis Sanchez <lluis@novell.com> | 2007-07-03 17:46:37 +0400 |
---|---|---|
committer | Lluis Sanchez <lluis@novell.com> | 2007-07-03 17:46:37 +0400 |
commit | 62e6d8921e4d1554d9513b9fffcc4f8ef75bbd3d (patch) | |
tree | e1fbf5750739e061e4a01572cdaac6a15e1b45d0 /Mono.Addins | |
parent | c5e47b77c401dc3117a3779c028c25d435a19c71 (diff) |
* Mono.Addins/AddinInfo.cs, Mono.Addins/Addin.cs,
Mono.Addins.Description/AddinDescription.cs,
Mono.Addins.Database/DatabaseConfiguration.cs,
Mono.Addins.Database/AddinDatabase.cs: Added support for add-ins
which are disabled by default.
* Mono.Addins.Database/AddinScanner.cs: Minor fix.
svn path=/trunk/mono-addins/; revision=81261
Diffstat (limited to 'Mono.Addins')
-rw-r--r-- | Mono.Addins/ChangeLog | 9 | ||||
-rw-r--r-- | Mono.Addins/Mono.Addins.Database/AddinDatabase.cs | 11 | ||||
-rw-r--r-- | Mono.Addins/Mono.Addins.Database/AddinScanner.cs | 4 | ||||
-rw-r--r-- | Mono.Addins/Mono.Addins.Database/DatabaseConfiguration.cs | 78 | ||||
-rw-r--r-- | Mono.Addins/Mono.Addins.Description/AddinDescription.cs | 22 | ||||
-rw-r--r-- | Mono.Addins/Mono.Addins/Addin.cs | 2 | ||||
-rw-r--r-- | Mono.Addins/Mono.Addins/AddinInfo.cs | 21 |
7 files changed, 125 insertions, 22 deletions
diff --git a/Mono.Addins/ChangeLog b/Mono.Addins/ChangeLog index 0cf95e2..7e743f8 100644 --- a/Mono.Addins/ChangeLog +++ b/Mono.Addins/ChangeLog @@ -1,3 +1,12 @@ +2007-07-03 Lluis Sanchez Gual <lluis@novell.com> + + * Mono.Addins/AddinInfo.cs, Mono.Addins/Addin.cs, + Mono.Addins.Description/AddinDescription.cs, + Mono.Addins.Database/DatabaseConfiguration.cs, + Mono.Addins.Database/AddinDatabase.cs: Added support for add-ins + which are disabled by default. + * Mono.Addins.Database/AddinScanner.cs: Minor fix. + 2007-07-02 Lluis Sanchez Gual <lluis@novell.com> * Mono.Addins/GettextCatalog.cs: Removed old copyright notice, since diff --git a/Mono.Addins/Mono.Addins.Database/AddinDatabase.cs b/Mono.Addins/Mono.Addins.Database/AddinDatabase.cs index 94c45d3..ee86f46 100644 --- a/Mono.Addins/Mono.Addins.Database/AddinDatabase.cs +++ b/Mono.Addins/Mono.Addins.Database/AddinDatabase.cs @@ -319,7 +319,10 @@ namespace Mono.Addins.Database { if (!exactVersionMatch) return IsAddinEnabled (id); - return !Configuration.DisabledAddins.Contains (id); + Addin ainfo = GetInstalledAddin (id, exactVersionMatch, false); + if (ainfo == null) + return false; + return Configuration.IsEnabled (id, ainfo.AddinInfo.EnabledByDefault); } public void EnableAddin (string id) @@ -347,7 +350,7 @@ namespace Mono.Addins.Database } } - Configuration.DisabledAddins.Remove (id); + Configuration.SetStatus (id, true, ainfo.AddinInfo.EnabledByDefault); SaveConfiguration (); if (AddinManager.IsInitialized && AddinManager.Registry.RegistryPath == registry.RegistryPath) @@ -363,7 +366,7 @@ namespace Mono.Addins.Database if (!IsAddinEnabled (id)) return; - Configuration.DisabledAddins.Add (id); + Configuration.SetStatus (id, false, ai.AddinInfo.EnabledByDefault); SaveConfiguration (); // Disable all add-ins which depend on it @@ -396,7 +399,7 @@ namespace Mono.Addins.Database } catch { // If something goes wrong, enable the add-in again - Configuration.DisabledAddins.Remove (id); + Configuration.SetStatus (id, true, ai.AddinInfo.EnabledByDefault); SaveConfiguration (); throw; } diff --git a/Mono.Addins/Mono.Addins.Database/AddinScanner.cs b/Mono.Addins/Mono.Addins.Database/AddinScanner.cs index d35efef..eac5be2 100644 --- a/Mono.Addins/Mono.Addins.Database/AddinScanner.cs +++ b/Mono.Addins/Mono.Addins.Database/AddinScanner.cs @@ -488,7 +488,7 @@ namespace Mono.Addins.Database asmFiles.Add (asmFile); Assembly asm = Util.LoadAssemblyForReflection (asmFile); assemblies.Add (asm); - scanResult.AddFileToIgnore (Util.GetFullPath (asm.Location)); + scanResult.AddFileToIgnore (Util.GetFullPath (asmFile)); } foreach (Assembly asm in assemblies) @@ -543,7 +543,7 @@ namespace Mono.Addins.Database asmFiles.Add (asmFile); Assembly asm = Util.LoadAssemblyForReflection (asmFile); assemblies.Add (asm); - scanResult.AddFileToIgnore (Util.GetFullPath (asm.Location)); + scanResult.AddFileToIgnore (Util.GetFullPath (asmFile)); } foreach (Assembly asm in assemblies) ScanAssemblyContents (config, asm, null, scanResult); diff --git a/Mono.Addins/Mono.Addins.Database/DatabaseConfiguration.cs b/Mono.Addins/Mono.Addins.Database/DatabaseConfiguration.cs index deb29bb..21323d2 100644 --- a/Mono.Addins/Mono.Addins.Database/DatabaseConfiguration.cs +++ b/Mono.Addins/Mono.Addins.Database/DatabaseConfiguration.cs @@ -29,14 +29,32 @@ using System; using System.IO; -using System.Collections.Specialized; +using System.Collections; using System.Xml; namespace Mono.Addins.Database { internal class DatabaseConfiguration { - public StringCollection DisabledAddins = new StringCollection (); + Hashtable addinStatus = new Hashtable (); + + public bool IsEnabled (string addinId, bool defaultValue) + { + if (addinStatus.Contains (addinId)) + return addinStatus [addinId] != null; + else + return defaultValue; + } + + public void SetStatus (string addinId, bool enabled, bool defaultValue) + { + if (enabled == defaultValue) + addinStatus.Remove (addinId); + else if (enabled) + addinStatus [addinId] = this; + else + addinStatus [addinId] = null; + } public static DatabaseConfiguration Read (string file) { @@ -46,20 +64,48 @@ namespace Mono.Addins.Database using (s) { XmlTextReader tr = new XmlTextReader (s); tr.MoveToContent (); + if (tr.IsEmptyElement) + return config; + tr.ReadStartElement ("Configuration"); tr.MoveToContent (); - tr.ReadStartElement ("DisabledAddins"); - tr.MoveToContent (); - if (!tr.IsEmptyElement) { - while (tr.NodeType != XmlNodeType.EndElement) { - if (tr.NodeType == XmlNodeType.Element) { - if (tr.LocalName == "Addin") - config.DisabledAddins.Add (tr.ReadElementString ()); + + while (tr.NodeType != XmlNodeType.EndElement) { + + if (tr.NodeType != XmlNodeType.Element || tr.IsEmptyElement) { + tr.Skip (); + } + else if (tr.LocalName == "DisabledAddins") { + // For back compatibility + tr.ReadStartElement (); + tr.MoveToContent (); + while (tr.NodeType != XmlNodeType.EndElement) { + if (tr.NodeType == XmlNodeType.Element && tr.LocalName == "Addin") + config.addinStatus [tr.ReadElementString ()] = null; + else + tr.Skip (); + tr.MoveToContent (); } - else - tr.Skip (); + tr.ReadEndElement (); + } + else if (tr.LocalName == "AddinStatus") { + tr.ReadStartElement (); tr.MoveToContent (); + while (tr.NodeType != XmlNodeType.EndElement) { + if (tr.NodeType == XmlNodeType.Element && tr.LocalName == "Addin") { + string aid = tr.GetAttribute ("id"); + string senabled = tr.GetAttribute ("enabled"); + if (senabled.Length == 0 || senabled == "True") + config.addinStatus [aid] = config; + else + config.addinStatus [aid] = null; + } + tr.Skip (); + tr.MoveToContent (); + } + tr.ReadEndElement (); } + tr.MoveToContent (); } } return config; @@ -72,9 +118,13 @@ namespace Mono.Addins.Database XmlTextWriter tw = new XmlTextWriter (s); tw.Formatting = Formatting.Indented; tw.WriteStartElement ("Configuration"); - tw.WriteStartElement ("DisabledAddins"); - foreach (string ad in DisabledAddins) - tw.WriteElementString ("Addin", ad); + tw.WriteStartElement ("AddinStatus"); + foreach (DictionaryEntry e in addinStatus) { + tw.WriteStartElement ("Addin"); + tw.WriteAttributeString ("id", (string)e.Key); + tw.WriteAttributeString ("enabled", (e.Value != null).ToString ()); + tw.WriteEndElement (); + } tw.WriteEndElement (); tw.WriteEndElement (); } diff --git a/Mono.Addins/Mono.Addins.Description/AddinDescription.cs b/Mono.Addins/Mono.Addins.Description/AddinDescription.cs index 3750cab..a4e0493 100644 --- a/Mono.Addins/Mono.Addins.Description/AddinDescription.cs +++ b/Mono.Addins/Mono.Addins.Description/AddinDescription.cs @@ -61,6 +61,7 @@ namespace Mono.Addins.Description bool isroot; bool hasUserId; bool canWrite = true; + bool defaultEnabled = true; ModuleDescription mainModule; ModuleCollection optionalModules; @@ -170,6 +171,11 @@ namespace Mono.Addins.Description set { isroot = value; } } + public bool EnabledByDefault { + get { return defaultEnabled; } + set { defaultEnabled = value; } + } + internal bool HasUserId { get { return hasUserId; } set { hasUserId = value; } @@ -388,6 +394,11 @@ namespace Mono.Addins.Description elem.SetAttribute ("compatVersion", compatVersion); else elem.RemoveAttribute ("compatVersion"); + + if (defaultEnabled) + elem.RemoveAttribute ("defaultEnabled"); + else + elem.SetAttribute ("defaultEnabled", "false"); if (author != null && author.Length > 0) elem.SetAttribute ("author", author); @@ -463,7 +474,14 @@ namespace Mono.Addins.Description config.description = elem.GetAttribute ("description"); config.category = elem.GetAttribute ("category"); config.basePath = elem.GetAttribute ("basePath"); - config.isroot = elem.GetAttribute ("isroot") == "true" || elem.GetAttribute ("isroot") == "yes"; + + string s = elem.GetAttribute ("isRoot"); + if (s.Length == 0) s = elem.GetAttribute ("isroot"); + config.isroot = s == "true" || s == "yes"; + + s = elem.GetAttribute ("defaultEnabled"); + config.defaultEnabled = s.Length == 0 || s == "true" || s == "yes"; + if (config.id.Length > 0) config.hasUserId = true; @@ -613,6 +631,7 @@ namespace Mono.Addins.Description writer.WriteValue ("category", category); writer.WriteValue ("basePath", basePath); writer.WriteValue ("sourceAddinFile", sourceAddinFile); + writer.WriteValue ("defaultEnabled", defaultEnabled); writer.WriteValue ("MainModule", MainModule); writer.WriteValue ("OptionalModules", OptionalModules); writer.WriteValue ("NodeSets", ExtensionNodeSets); @@ -636,6 +655,7 @@ namespace Mono.Addins.Description category = reader.ReadStringValue ("category"); basePath = reader.ReadStringValue ("basePath"); sourceAddinFile = reader.ReadStringValue ("sourceAddinFile"); + defaultEnabled = reader.ReadBooleanValue ("defaultEnabled"); mainModule = (ModuleDescription) reader.ReadValue ("MainModule"); optionalModules = (ModuleCollection) reader.ReadValue ("OptionalModules", new ModuleCollection (this)); nodeSets = (ExtensionNodeSetCollection) reader.ReadValue ("NodeSets", new ExtensionNodeSetCollection (this)); diff --git a/Mono.Addins/Mono.Addins/Addin.cs b/Mono.Addins/Mono.Addins/Addin.cs index 350091e..0c0d6e9 100644 --- a/Mono.Addins/Mono.Addins/Addin.cs +++ b/Mono.Addins/Mono.Addins/Addin.cs @@ -102,7 +102,7 @@ namespace Mono.Addins } public bool Enabled { - get { return database.IsAddinEnabled (AddinInfo.Id, true); } + get { return AddinInfo.IsRoot ? true : database.IsAddinEnabled (AddinInfo.Id, true); } set { if (value) database.EnableAddin (AddinInfo.Id, true); diff --git a/Mono.Addins/Mono.Addins/AddinInfo.cs b/Mono.Addins/Mono.Addins/AddinInfo.cs index 3fda182..41f7bf5 100644 --- a/Mono.Addins/Mono.Addins/AddinInfo.cs +++ b/Mono.Addins/Mono.Addins/AddinInfo.cs @@ -47,6 +47,8 @@ namespace Mono.Addins string url = ""; string description = ""; string category = ""; + bool defaultEnabled = true; + bool isroot; DependencyCollection dependencies; DependencyCollection optionalDependencies; @@ -71,6 +73,11 @@ namespace Mono.Addins set { namspace = value; } } + public bool IsRoot { + get { return isroot; } + set { isroot = value; } + } + public string Name { get { if (name != null && name.Length > 0) @@ -118,6 +125,11 @@ namespace Mono.Addins set { category = value; } } + public bool EnabledByDefault { + get { return defaultEnabled; } + set { defaultEnabled = value; } + } + [XmlArrayItem ("AddinDependency", typeof(AddinDependency))] [XmlArrayItem ("AssemblyDependency", typeof(AssemblyDependency))] public DependencyCollection Dependencies { @@ -148,7 +160,14 @@ namespace Mono.Addins 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; @@ -189,6 +208,8 @@ namespace Mono.Addins info.description = description.Description; info.category = description.Category; info.baseVersion = description.CompatVersion; + info.isroot = description.IsRoot; + info.defaultEnabled = description.EnabledByDefault; foreach (Dependency dep in description.MainModule.Dependencies) info.Dependencies.Add (dep); |