Browse Source

check ActiveViewContent.Services as well, when evaluating WindowActive-Condition

pull/59/merge
Siegfried Pammer 12 years ago
parent
commit
1e10eb47fc
  1. 28
      src/Main/Base/Project/Src/Internal/ConditionEvaluators/WindowActiveEvaluator.cs

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

@ -10,16 +10,16 @@ namespace ICSharpCode.SharpDevelop
/// <summary> /// <summary>
/// Tests if the current workbench window is a specified type or implements an interface. /// Tests if the current workbench window is a specified type or implements an interface.
/// </summary> /// </summary>
/// <attribute name="activewindow"> /// <attribute name="activeWindow">
/// The fully qualified name of the type the active window should be or the /// The fully qualified name of the type the active window should be or the
/// interface name it should implement. /// interface name it should implement.
/// "*" to test if any window is active. /// "*" to test if any window is active.
/// </attribute> /// </attribute>
/// <example title="Test if the current window is a text editor"> /// <example title="Test if the current window is a text editor">
/// &lt;Condition name="WindowActive" activewindow="ICSharpCode.SharpDevelop.Editor.ITextEditorProvider"&gt; /// &lt;Condition name="WindowActive" activeWindow="ICSharpCode.SharpDevelop.Editor.ITextEditor"&gt;
/// </example> /// </example>
/// <example title="Test if any window is active"> /// <example title="Test if any window is active">
/// &lt;Condition name="WindowActive" activewindow="*"&gt; /// &lt;Condition name="WindowActive" activeWindow="*"&gt;
/// </example> /// </example>
public class WindowActiveConditionEvaluator : IConditionEvaluator public class WindowActiveConditionEvaluator : IConditionEvaluator
{ {
@ -29,25 +29,33 @@ namespace ICSharpCode.SharpDevelop
return false; 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;
} }
if (SD.Workbench.ActiveWorkbenchWindow == null || SD.Workbench.ActiveWorkbenchWindow.ActiveViewContent == null) { Type activeWindowType = Type.GetType(activeWindow, false);
if (activeWindowType == null) {
SD.Log.WarnFormatted("WindowActiveCondition: cannot find Type {0}", activeWindow);
return false; return false;
} }
if (SD.GetActiveViewContentService(activeWindowType) != null)
return true;
if (SD.Workbench.ActiveWorkbenchWindow == null
|| SD.Workbench.ActiveWorkbenchWindow.ActiveViewContent == null)
return false;
Type currentType = SD.Workbench.ActiveWorkbenchWindow.ActiveViewContent.GetType(); Type currentType = SD.Workbench.ActiveWorkbenchWindow.ActiveViewContent.GetType();
if (currentType.FullName == activewindow) if (currentType.FullName == activeWindow)
return true; return true;
foreach (Type interf in currentType.GetInterfaces()) { foreach (Type interf in currentType.GetInterfaces()) {
if (interf.FullName == activewindow) if (interf.FullName == activeWindow)
return true; return true;
} }
while ((currentType = currentType.BaseType) != null) { while ((currentType = currentType.BaseType) != null) {
if (currentType.FullName == activewindow) if (currentType.FullName == activeWindow)
return true; return true;
} }
return false; return false;

Loading…
Cancel
Save