Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 928aa02

Browse files
fix #266
1 parent 74ab0ec commit 928aa02

6 files changed

Lines changed: 37 additions & 37 deletions

File tree

src/Main/Base/Project/Src/Internal/ConditionEvaluators/WindowActiveEvaluator.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
33

44
using System;
5+
using System.ComponentModel.Design;
6+
using System.Linq;
7+
using System.Reflection;
58
using ICSharpCode.Core;
69
using ICSharpCode.SharpDevelop.Gui;
710

@@ -25,18 +28,14 @@ public class WindowActiveConditionEvaluator : IConditionEvaluator
2528
{
2629
public bool IsValid(object caller, Condition condition)
2730
{
28-
if (SD.Workbench == null) {
29-
return false;
30-
}
31-
3231
string activeWindow = condition.Properties["activewindow"];
3332
if (activeWindow == "*") {
3433
return SD.Workbench.ActiveWorkbenchWindow != null;
3534
}
3635

37-
Type activeWindowType = Type.GetType(activeWindow, false);
36+
Type activeWindowType = condition.AddIn.FindType(activeWindow);
3837
if (activeWindowType == null) {
39-
//SD.Log.WarnFormatted("WindowActiveCondition: cannot find Type {0}", activeWindow);
38+
SD.Log.WarnFormatted("WindowActiveCondition: cannot find Type {0}", activeWindow);
4039
return false;
4140
}
4241

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,11 @@ public class WindowOpenConditionEvaluator : IConditionEvaluator
2626
{
2727
public bool IsValid(object caller, Condition condition)
2828
{
29-
if (SD.Workbench == null) {
30-
return false;
31-
}
32-
3329
string openWindow = condition.Properties["openwindow"];
3430

35-
Type openWindowType = Type.GetType(openWindow, false);
31+
Type openWindowType = condition.AddIn.FindType(openWindow);
3632
if (openWindowType == null) {
37-
//SD.Log.WarnFormatted("WindowOpenCondition: cannot find Type {0}", openWindow);
33+
SD.Log.WarnFormatted("WindowOpenCondition: cannot find Type {0}", openWindow);
3834
return false;
3935
}
4036

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ public bool IsValid(object parameter)
4242
return !condition.IsValid(parameter);
4343
}
4444

45-
public static ICondition Read(XmlReader reader)
45+
public static ICondition Read(XmlReader reader, AddIn addIn)
4646
{
47-
return new NegatedCondition(Condition.ReadConditionList(reader, "Not")[0]);
47+
return new NegatedCondition(Condition.ReadConditionList(reader, "Not", addIn)[0]);
4848
}
4949
}
5050

@@ -94,9 +94,9 @@ public bool IsValid(object parameter)
9494
return true;
9595
}
9696

97-
public static ICondition Read(XmlReader reader)
97+
public static ICondition Read(XmlReader reader, AddIn addIn)
9898
{
99-
return new AndCondition(Condition.ReadConditionList(reader, "And"));
99+
return new AndCondition(Condition.ReadConditionList(reader, "And", addIn));
100100
}
101101
}
102102

@@ -147,9 +147,9 @@ public bool IsValid(object parameter)
147147
return false;
148148
}
149149

150-
public static ICondition Read(XmlReader reader)
150+
public static ICondition Read(XmlReader reader, AddIn addIn)
151151
{
152-
return new OrCondition(Condition.ReadConditionList(reader, "Or"));
152+
return new OrCondition(Condition.ReadConditionList(reader, "Or", addIn));
153153
}
154154
}
155155
}

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

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ public class Condition : ICondition
1313
string name;
1414
Properties properties;
1515
ConditionFailedAction action;
16+
17+
public AddIn AddIn { get; private set; }
18+
1619
/// <summary>
1720
/// Returns the action which occurs, when this condition fails.
1821
/// </summary>
@@ -24,6 +27,7 @@ public ConditionFailedAction Action {
2427
action = value;
2528
}
2629
}
30+
2731
public string Name {
2832
get {
2933
return name;
@@ -42,8 +46,9 @@ public Properties Properties {
4246
}
4347
}
4448

45-
public Condition(string name, Properties properties)
49+
public Condition(string name, Properties properties, AddIn addIn)
4650
{
51+
this.AddIn = addIn;
4752
this.name = name;
4853
this.properties = properties;
4954
action = properties.Get("action", ConditionFailedAction.Exclude);
@@ -59,14 +64,14 @@ public bool IsValid(object parameter)
5964
}
6065
}
6166

62-
public static ICondition Read(XmlReader reader)
67+
public static ICondition Read(XmlReader reader, AddIn addIn)
6368
{
6469
Properties properties = Properties.ReadFromAttributes(reader);
6570
string conditionName = properties["name"];
66-
return new Condition(conditionName, properties);
71+
return new Condition(conditionName, properties, addIn);
6772
}
6873

69-
public static ICondition ReadComplexCondition(XmlReader reader)
74+
public static ICondition ReadComplexCondition(XmlReader reader, AddIn addIn)
7075
{
7176
Properties properties = Properties.ReadFromAttributes(reader);
7277
reader.Read();
@@ -76,13 +81,13 @@ public static ICondition ReadComplexCondition(XmlReader reader)
7681
case XmlNodeType.Element:
7782
switch (reader.LocalName) {
7883
case "And":
79-
condition = AndCondition.Read(reader);
84+
condition = AndCondition.Read(reader, addIn);
8085
goto exit;
8186
case "Or":
82-
condition = OrCondition.Read(reader);
87+
condition = OrCondition.Read(reader, addIn);
8388
goto exit;
8489
case "Not":
85-
condition = NegatedCondition.Read(reader);
90+
condition = NegatedCondition.Read(reader, addIn);
8691
goto exit;
8792
default:
8893
throw new AddInLoadException("Invalid element name '" + reader.LocalName
@@ -99,7 +104,7 @@ public static ICondition ReadComplexCondition(XmlReader reader)
99104
return condition;
100105
}
101106

102-
public static ICondition[] ReadConditionList(XmlReader reader, string endElement)
107+
public static ICondition[] ReadConditionList(XmlReader reader, string endElement, AddIn addIn)
103108
{
104109
List<ICondition> conditions = new List<ICondition>();
105110
while (reader.Read()) {
@@ -112,16 +117,16 @@ public static ICondition[] ReadConditionList(XmlReader reader, string endElement
112117
case XmlNodeType.Element:
113118
switch (reader.LocalName) {
114119
case "And":
115-
conditions.Add(AndCondition.Read(reader));
120+
conditions.Add(AndCondition.Read(reader, addIn));
116121
break;
117122
case "Or":
118-
conditions.Add(OrCondition.Read(reader));
123+
conditions.Add(OrCondition.Read(reader, addIn));
119124
break;
120125
case "Not":
121-
conditions.Add(NegatedCondition.Read(reader));
126+
conditions.Add(NegatedCondition.Read(reader, addIn));
122127
break;
123128
case "Condition":
124-
conditions.Add(Condition.Read(reader));
129+
conditions.Add(Condition.Read(reader, addIn));
125130
break;
126131
default:
127132
throw new AddInLoadException("Invalid element name '" + reader.LocalName

src/Main/Core/Project/Src/AddInTree/AddIn/ExtensionPath.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ public ExtensionPath(string name, AddIn addIn)
5757

5858
public static void SetUp(ExtensionPath extensionPath, XmlReader reader, string endElement)
5959
{
60-
extensionPath.DoSetUp(reader, endElement);
60+
extensionPath.DoSetUp(reader, endElement, extensionPath.addIn);
6161
}
6262

63-
void DoSetUp(XmlReader reader, string endElement)
63+
void DoSetUp(XmlReader reader, string endElement, AddIn addIn)
6464
{
6565
Stack<ICondition> conditionStack = new Stack<ICondition>();
6666
List<Codon> innerCodons = new List<Codon>();
@@ -78,15 +78,15 @@ void DoSetUp(XmlReader reader, string endElement)
7878
case XmlNodeType.Element:
7979
string elementName = reader.LocalName;
8080
if (elementName == "Condition") {
81-
conditionStack.Push(Condition.Read(reader));
81+
conditionStack.Push(Condition.Read(reader, addIn));
8282
} else if (elementName == "ComplexCondition") {
83-
conditionStack.Push(Condition.ReadComplexCondition(reader));
83+
conditionStack.Push(Condition.ReadComplexCondition(reader, addIn));
8484
} else {
8585
Codon newCodon = new Codon(this.AddIn, elementName, Properties.ReadFromAttributes(reader), conditionStack.ToArray());
8686
innerCodons.Add(newCodon);
8787
if (!reader.IsEmptyElement) {
8888
ExtensionPath subPath = this.AddIn.GetExtensionPath(this.Name + "/" + newCodon.Id);
89-
subPath.DoSetUp(reader, elementName);
89+
subPath.DoSetUp(reader, elementName, addIn);
9090
}
9191
}
9292
break;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@ internal static List<Runtime> ReadSection(XmlReader reader, AddIn addIn, string
154154
case XmlNodeType.Element:
155155
switch (reader.LocalName) {
156156
case "Condition":
157-
conditionStack.Push(Condition.Read(reader));
157+
conditionStack.Push(Condition.Read(reader, addIn));
158158
break;
159159
case "ComplexCondition":
160-
conditionStack.Push(Condition.ReadComplexCondition(reader));
160+
conditionStack.Push(Condition.ReadComplexCondition(reader, addIn));
161161
break;
162162
case "Import":
163163
runtimes.Add(Runtime.Read(addIn, reader, hintPath, conditionStack));

0 commit comments

Comments
 (0)