Browse Source

fix #266

pull/315/head
Siegfried Pammer 12 years ago
parent
commit
928aa02111
  1. 11
      src/Main/Base/Project/Src/Internal/ConditionEvaluators/WindowActiveEvaluator.cs
  2. 8
      src/Main/Base/Project/Src/Internal/ConditionEvaluators/WindowOpenEvaluator.cs
  3. 12
      src/Main/Core/Project/Src/AddInTree/AddIn/ComplexCondition.cs
  4. 29
      src/Main/Core/Project/Src/AddInTree/AddIn/Condition.cs
  5. 10
      src/Main/Core/Project/Src/AddInTree/AddIn/ExtensionPath.cs
  6. 4
      src/Main/Core/Project/Src/AddInTree/AddIn/Runtime.cs

11
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) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System; using System;
using System.ComponentModel.Design;
using System.Linq;
using System.Reflection;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
@ -25,18 +28,14 @@ namespace ICSharpCode.SharpDevelop
{ {
public bool IsValid(object caller, Condition condition) public bool IsValid(object caller, Condition condition)
{ {
if (SD.Workbench == null) {
return false;
}
string activeWindow = condition.Properties["activewindow"]; string activeWindow = condition.Properties["activewindow"];
if (activeWindow == "*") { if (activeWindow == "*") {
return SD.Workbench.ActiveWorkbenchWindow != null; return SD.Workbench.ActiveWorkbenchWindow != null;
} }
Type activeWindowType = Type.GetType(activeWindow, false); Type activeWindowType = condition.AddIn.FindType(activeWindow);
if (activeWindowType == null) { if (activeWindowType == null) {
//SD.Log.WarnFormatted("WindowActiveCondition: cannot find Type {0}", activeWindow); SD.Log.WarnFormatted("WindowActiveCondition: cannot find Type {0}", activeWindow);
return false; return false;
} }

8
src/Main/Base/Project/Src/Internal/ConditionEvaluators/WindowOpenEvaluator.cs

@ -26,15 +26,11 @@ namespace ICSharpCode.SharpDevelop
{ {
public bool IsValid(object caller, Condition condition) public bool IsValid(object caller, Condition condition)
{ {
if (SD.Workbench == null) {
return false;
}
string openWindow = condition.Properties["openwindow"]; string openWindow = condition.Properties["openwindow"];
Type openWindowType = Type.GetType(openWindow, false); Type openWindowType = condition.AddIn.FindType(openWindow);
if (openWindowType == null) { if (openWindowType == null) {
//SD.Log.WarnFormatted("WindowOpenCondition: cannot find Type {0}", openWindow); SD.Log.WarnFormatted("WindowOpenCondition: cannot find Type {0}", openWindow);
return false; return false;
} }

12
src/Main/Core/Project/Src/AddInTree/AddIn/ComplexCondition.cs

@ -42,9 +42,9 @@ namespace ICSharpCode.Core
return !condition.IsValid(parameter); 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; 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; 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));
} }
} }
} }

29
src/Main/Core/Project/Src/AddInTree/AddIn/Condition.cs

@ -13,6 +13,9 @@ namespace ICSharpCode.Core
string name; string name;
Properties properties; Properties properties;
ConditionFailedAction action; ConditionFailedAction action;
public AddIn AddIn { get; private set; }
/// <summary> /// <summary>
/// Returns the action which occurs, when this condition fails. /// Returns the action which occurs, when this condition fails.
/// </summary> /// </summary>
@ -24,6 +27,7 @@ namespace ICSharpCode.Core
action = value; action = value;
} }
} }
public string Name { public string Name {
get { get {
return name; 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.name = name;
this.properties = properties; this.properties = properties;
action = properties.Get("action", ConditionFailedAction.Exclude); 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); Properties properties = Properties.ReadFromAttributes(reader);
string conditionName = properties["name"]; 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); Properties properties = Properties.ReadFromAttributes(reader);
reader.Read(); reader.Read();
@ -76,13 +81,13 @@ namespace ICSharpCode.Core
case XmlNodeType.Element: case XmlNodeType.Element:
switch (reader.LocalName) { switch (reader.LocalName) {
case "And": case "And":
condition = AndCondition.Read(reader); condition = AndCondition.Read(reader, addIn);
goto exit; goto exit;
case "Or": case "Or":
condition = OrCondition.Read(reader); condition = OrCondition.Read(reader, addIn);
goto exit; goto exit;
case "Not": case "Not":
condition = NegatedCondition.Read(reader); condition = NegatedCondition.Read(reader, addIn);
goto exit; goto exit;
default: default:
throw new AddInLoadException("Invalid element name '" + reader.LocalName throw new AddInLoadException("Invalid element name '" + reader.LocalName
@ -99,7 +104,7 @@ namespace ICSharpCode.Core
return condition; return condition;
} }
public static ICondition[] ReadConditionList(XmlReader reader, string endElement) public static ICondition[] ReadConditionList(XmlReader reader, string endElement, AddIn addIn)
{ {
List<ICondition> conditions = new List<ICondition>(); List<ICondition> conditions = new List<ICondition>();
while (reader.Read()) { while (reader.Read()) {
@ -112,16 +117,16 @@ namespace ICSharpCode.Core
case XmlNodeType.Element: case XmlNodeType.Element:
switch (reader.LocalName) { switch (reader.LocalName) {
case "And": case "And":
conditions.Add(AndCondition.Read(reader)); conditions.Add(AndCondition.Read(reader, addIn));
break; break;
case "Or": case "Or":
conditions.Add(OrCondition.Read(reader)); conditions.Add(OrCondition.Read(reader, addIn));
break; break;
case "Not": case "Not":
conditions.Add(NegatedCondition.Read(reader)); conditions.Add(NegatedCondition.Read(reader, addIn));
break; break;
case "Condition": case "Condition":
conditions.Add(Condition.Read(reader)); conditions.Add(Condition.Read(reader, addIn));
break; break;
default: default:
throw new AddInLoadException("Invalid element name '" + reader.LocalName throw new AddInLoadException("Invalid element name '" + reader.LocalName

10
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) 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<ICondition> conditionStack = new Stack<ICondition>(); Stack<ICondition> conditionStack = new Stack<ICondition>();
List<Codon> innerCodons = new List<Codon>(); List<Codon> innerCodons = new List<Codon>();
@ -78,15 +78,15 @@ namespace ICSharpCode.Core
case XmlNodeType.Element: case XmlNodeType.Element:
string elementName = reader.LocalName; string elementName = reader.LocalName;
if (elementName == "Condition") { if (elementName == "Condition") {
conditionStack.Push(Condition.Read(reader)); conditionStack.Push(Condition.Read(reader, addIn));
} else if (elementName == "ComplexCondition") { } else if (elementName == "ComplexCondition") {
conditionStack.Push(Condition.ReadComplexCondition(reader)); conditionStack.Push(Condition.ReadComplexCondition(reader, addIn));
} else { } else {
Codon newCodon = new Codon(this.AddIn, elementName, Properties.ReadFromAttributes(reader), conditionStack.ToArray()); Codon newCodon = new Codon(this.AddIn, elementName, Properties.ReadFromAttributes(reader), conditionStack.ToArray());
innerCodons.Add(newCodon); innerCodons.Add(newCodon);
if (!reader.IsEmptyElement) { if (!reader.IsEmptyElement) {
ExtensionPath subPath = this.AddIn.GetExtensionPath(this.Name + "/" + newCodon.Id); ExtensionPath subPath = this.AddIn.GetExtensionPath(this.Name + "/" + newCodon.Id);
subPath.DoSetUp(reader, elementName); subPath.DoSetUp(reader, elementName, addIn);
} }
} }
break; break;

4
src/Main/Core/Project/Src/AddInTree/AddIn/Runtime.cs

@ -154,10 +154,10 @@ namespace ICSharpCode.Core
case XmlNodeType.Element: case XmlNodeType.Element:
switch (reader.LocalName) { switch (reader.LocalName) {
case "Condition": case "Condition":
conditionStack.Push(Condition.Read(reader)); conditionStack.Push(Condition.Read(reader, addIn));
break; break;
case "ComplexCondition": case "ComplexCondition":
conditionStack.Push(Condition.ReadComplexCondition(reader)); conditionStack.Push(Condition.ReadComplexCondition(reader, addIn));
break; break;
case "Import": case "Import":
runtimes.Add(Runtime.Read(addIn, reader, hintPath, conditionStack)); runtimes.Add(Runtime.Read(addIn, reader, hintPath, conditionStack));

Loading…
Cancel
Save