From 928aa0211117b42e48dcd61a49313a0fbf203f89 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 8 Jan 2014 22:32:10 +0100 Subject: [PATCH] fix #266 --- .../WindowActiveEvaluator.cs | 11 ++++--- .../WindowOpenEvaluator.cs | 8 ++--- .../Src/AddInTree/AddIn/ComplexCondition.cs | 12 ++++---- .../Project/Src/AddInTree/AddIn/Condition.cs | 29 +++++++++++-------- .../Src/AddInTree/AddIn/ExtensionPath.cs | 10 +++---- .../Project/Src/AddInTree/AddIn/Runtime.cs | 4 +-- 6 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/Main/Base/Project/Src/Internal/ConditionEvaluators/WindowActiveEvaluator.cs b/src/Main/Base/Project/Src/Internal/ConditionEvaluators/WindowActiveEvaluator.cs index 46fd666fe7..e83d68cb96 100644 --- a/src/Main/Base/Project/Src/Internal/ConditionEvaluators/WindowActiveEvaluator.cs +++ b/src/Main/Base/Project/Src/Internal/ConditionEvaluators/WindowActiveEvaluator.cs @@ -2,6 +2,9 @@ // This code is distributed under the GNU LGPL (for details please see \doc\license.txt) using System; +using System.ComponentModel.Design; +using System.Linq; +using System.Reflection; using ICSharpCode.Core; using ICSharpCode.SharpDevelop.Gui; @@ -25,18 +28,14 @@ namespace ICSharpCode.SharpDevelop { public bool IsValid(object caller, Condition condition) { - if (SD.Workbench == null) { - return false; - } - string activeWindow = condition.Properties["activewindow"]; if (activeWindow == "*") { return SD.Workbench.ActiveWorkbenchWindow != null; } - Type activeWindowType = Type.GetType(activeWindow, false); + Type activeWindowType = condition.AddIn.FindType(activeWindow); if (activeWindowType == null) { - //SD.Log.WarnFormatted("WindowActiveCondition: cannot find Type {0}", activeWindow); + SD.Log.WarnFormatted("WindowActiveCondition: cannot find Type {0}", activeWindow); return false; } diff --git a/src/Main/Base/Project/Src/Internal/ConditionEvaluators/WindowOpenEvaluator.cs b/src/Main/Base/Project/Src/Internal/ConditionEvaluators/WindowOpenEvaluator.cs index b11b70218f..3e83688553 100644 --- a/src/Main/Base/Project/Src/Internal/ConditionEvaluators/WindowOpenEvaluator.cs +++ b/src/Main/Base/Project/Src/Internal/ConditionEvaluators/WindowOpenEvaluator.cs @@ -26,15 +26,11 @@ namespace ICSharpCode.SharpDevelop { public bool IsValid(object caller, Condition condition) { - if (SD.Workbench == null) { - return false; - } - string openWindow = condition.Properties["openwindow"]; - Type openWindowType = Type.GetType(openWindow, false); + Type openWindowType = condition.AddIn.FindType(openWindow); if (openWindowType == null) { - //SD.Log.WarnFormatted("WindowOpenCondition: cannot find Type {0}", openWindow); + SD.Log.WarnFormatted("WindowOpenCondition: cannot find Type {0}", openWindow); return false; } diff --git a/src/Main/Core/Project/Src/AddInTree/AddIn/ComplexCondition.cs b/src/Main/Core/Project/Src/AddInTree/AddIn/ComplexCondition.cs index f564ae3976..0020f2468d 100644 --- a/src/Main/Core/Project/Src/AddInTree/AddIn/ComplexCondition.cs +++ b/src/Main/Core/Project/Src/AddInTree/AddIn/ComplexCondition.cs @@ -42,9 +42,9 @@ namespace ICSharpCode.Core return !condition.IsValid(parameter); } - public static ICondition Read(XmlReader reader) + public static ICondition Read(XmlReader reader, AddIn addIn) { - return new NegatedCondition(Condition.ReadConditionList(reader, "Not")[0]); + return new NegatedCondition(Condition.ReadConditionList(reader, "Not", addIn)[0]); } } @@ -94,9 +94,9 @@ namespace ICSharpCode.Core return true; } - public static ICondition Read(XmlReader reader) + public static ICondition Read(XmlReader reader, AddIn addIn) { - return new AndCondition(Condition.ReadConditionList(reader, "And")); + return new AndCondition(Condition.ReadConditionList(reader, "And", addIn)); } } @@ -147,9 +147,9 @@ namespace ICSharpCode.Core return false; } - public static ICondition Read(XmlReader reader) + public static ICondition Read(XmlReader reader, AddIn addIn) { - return new OrCondition(Condition.ReadConditionList(reader, "Or")); + return new OrCondition(Condition.ReadConditionList(reader, "Or", addIn)); } } } diff --git a/src/Main/Core/Project/Src/AddInTree/AddIn/Condition.cs b/src/Main/Core/Project/Src/AddInTree/AddIn/Condition.cs index f6b403b1fa..59547944b0 100644 --- a/src/Main/Core/Project/Src/AddInTree/AddIn/Condition.cs +++ b/src/Main/Core/Project/Src/AddInTree/AddIn/Condition.cs @@ -13,6 +13,9 @@ namespace ICSharpCode.Core string name; Properties properties; ConditionFailedAction action; + + public AddIn AddIn { get; private set; } + /// /// Returns the action which occurs, when this condition fails. /// @@ -24,6 +27,7 @@ namespace ICSharpCode.Core action = value; } } + public string Name { get { return name; @@ -42,8 +46,9 @@ namespace ICSharpCode.Core } } - public Condition(string name, Properties properties) + public Condition(string name, Properties properties, AddIn addIn) { + this.AddIn = addIn; this.name = name; this.properties = properties; action = properties.Get("action", ConditionFailedAction.Exclude); @@ -59,14 +64,14 @@ namespace ICSharpCode.Core } } - public static ICondition Read(XmlReader reader) + public static ICondition Read(XmlReader reader, AddIn addIn) { Properties properties = Properties.ReadFromAttributes(reader); string conditionName = properties["name"]; - return new Condition(conditionName, properties); + return new Condition(conditionName, properties, addIn); } - public static ICondition ReadComplexCondition(XmlReader reader) + public static ICondition ReadComplexCondition(XmlReader reader, AddIn addIn) { Properties properties = Properties.ReadFromAttributes(reader); reader.Read(); @@ -76,13 +81,13 @@ namespace ICSharpCode.Core case XmlNodeType.Element: switch (reader.LocalName) { case "And": - condition = AndCondition.Read(reader); + condition = AndCondition.Read(reader, addIn); goto exit; case "Or": - condition = OrCondition.Read(reader); + condition = OrCondition.Read(reader, addIn); goto exit; case "Not": - condition = NegatedCondition.Read(reader); + condition = NegatedCondition.Read(reader, addIn); goto exit; default: throw new AddInLoadException("Invalid element name '" + reader.LocalName @@ -99,7 +104,7 @@ namespace ICSharpCode.Core return condition; } - public static ICondition[] ReadConditionList(XmlReader reader, string endElement) + public static ICondition[] ReadConditionList(XmlReader reader, string endElement, AddIn addIn) { List conditions = new List(); while (reader.Read()) { @@ -112,16 +117,16 @@ namespace ICSharpCode.Core case XmlNodeType.Element: switch (reader.LocalName) { case "And": - conditions.Add(AndCondition.Read(reader)); + conditions.Add(AndCondition.Read(reader, addIn)); break; case "Or": - conditions.Add(OrCondition.Read(reader)); + conditions.Add(OrCondition.Read(reader, addIn)); break; case "Not": - conditions.Add(NegatedCondition.Read(reader)); + conditions.Add(NegatedCondition.Read(reader, addIn)); break; case "Condition": - conditions.Add(Condition.Read(reader)); + conditions.Add(Condition.Read(reader, addIn)); break; default: throw new AddInLoadException("Invalid element name '" + reader.LocalName diff --git a/src/Main/Core/Project/Src/AddInTree/AddIn/ExtensionPath.cs b/src/Main/Core/Project/Src/AddInTree/AddIn/ExtensionPath.cs index 53c73de78a..6bde5d8e47 100644 --- a/src/Main/Core/Project/Src/AddInTree/AddIn/ExtensionPath.cs +++ b/src/Main/Core/Project/Src/AddInTree/AddIn/ExtensionPath.cs @@ -57,10 +57,10 @@ namespace ICSharpCode.Core public static void SetUp(ExtensionPath extensionPath, XmlReader reader, string endElement) { - extensionPath.DoSetUp(reader, endElement); + extensionPath.DoSetUp(reader, endElement, extensionPath.addIn); } - void DoSetUp(XmlReader reader, string endElement) + void DoSetUp(XmlReader reader, string endElement, AddIn addIn) { Stack conditionStack = new Stack(); List innerCodons = new List(); @@ -78,15 +78,15 @@ namespace ICSharpCode.Core case XmlNodeType.Element: string elementName = reader.LocalName; if (elementName == "Condition") { - conditionStack.Push(Condition.Read(reader)); + conditionStack.Push(Condition.Read(reader, addIn)); } else if (elementName == "ComplexCondition") { - conditionStack.Push(Condition.ReadComplexCondition(reader)); + conditionStack.Push(Condition.ReadComplexCondition(reader, addIn)); } else { Codon newCodon = new Codon(this.AddIn, elementName, Properties.ReadFromAttributes(reader), conditionStack.ToArray()); innerCodons.Add(newCodon); if (!reader.IsEmptyElement) { ExtensionPath subPath = this.AddIn.GetExtensionPath(this.Name + "/" + newCodon.Id); - subPath.DoSetUp(reader, elementName); + subPath.DoSetUp(reader, elementName, addIn); } } break; diff --git a/src/Main/Core/Project/Src/AddInTree/AddIn/Runtime.cs b/src/Main/Core/Project/Src/AddInTree/AddIn/Runtime.cs index e82fb22700..bb8b83e8e2 100644 --- a/src/Main/Core/Project/Src/AddInTree/AddIn/Runtime.cs +++ b/src/Main/Core/Project/Src/AddInTree/AddIn/Runtime.cs @@ -154,10 +154,10 @@ namespace ICSharpCode.Core case XmlNodeType.Element: switch (reader.LocalName) { case "Condition": - conditionStack.Push(Condition.Read(reader)); + conditionStack.Push(Condition.Read(reader, addIn)); break; case "ComplexCondition": - conditionStack.Push(Condition.ReadComplexCondition(reader)); + conditionStack.Push(Condition.ReadComplexCondition(reader, addIn)); break; case "Import": runtimes.Add(Runtime.Read(addIn, reader, hintPath, conditionStack));