diff --git a/src/AddIns/Misc/UnitTesting/Src/TestTreeView.cs b/src/AddIns/Misc/UnitTesting/Src/TestTreeView.cs
index 9e195c1ea6..ff3688522e 100644
--- a/src/AddIns/Misc/UnitTesting/Src/TestTreeView.cs
+++ b/src/AddIns/Misc/UnitTesting/Src/TestTreeView.cs
@@ -7,6 +7,7 @@
using System;
using System.Collections.Generic;
+using System.Windows.Forms;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
@@ -255,6 +256,21 @@ namespace ICSharpCode.UnitTesting
}
}
+ ///
+ /// A tree node has been selected. Here we make sure the tree node
+ /// uses the context menu strip that the tree view is using. This
+ /// ensures that if the user brings up the context menu using a keyboard
+ /// shortcut (Shift+F10) then it appears over the node rather than in
+ /// the middle of the Unit Tests window.
+ ///
+ protected override void OnBeforeSelect(TreeViewCancelEventArgs e)
+ {
+ TreeNode node = e.Node;
+ if (node.ContextMenuStrip == null) {
+ node.ContextMenuStrip = ContextMenuStrip;
+ }
+ }
+
///
/// Returns the project tree node that is associated with the
/// specified project.
diff --git a/src/AddIns/Misc/UnitTesting/Src/UnitTestsPad.cs b/src/AddIns/Misc/UnitTesting/Src/UnitTestsPad.cs
index 386ab2fc00..aaadb42bca 100644
--- a/src/AddIns/Misc/UnitTesting/Src/UnitTestsPad.cs
+++ b/src/AddIns/Misc/UnitTesting/Src/UnitTestsPad.cs
@@ -187,7 +187,7 @@ namespace ICSharpCode.UnitTesting
///
protected virtual ToolStrip CreateToolStrip(string name)
{
- return ToolbarService.CreateToolStrip(treeView, "/SharpDevelop/Pads/UnitTestsPad/Toolbar");
+ return ToolbarService.CreateToolStrip(treeView, name);
}
///
@@ -196,7 +196,7 @@ namespace ICSharpCode.UnitTesting
///
protected virtual ContextMenuStrip CreateContextMenu(string name)
{
- return MenuService.CreateContextMenu(treeView, "/SharpDevelop/Pads/UnitTestsPad/ContextMenu");
+ return MenuService.CreateContextMenu(treeView, name);
}
///
diff --git a/src/AddIns/Misc/UnitTesting/Test/Tree/TreeNodeContextMenuTestFixture.cs b/src/AddIns/Misc/UnitTesting/Test/Tree/TreeNodeContextMenuTestFixture.cs
new file mode 100644
index 0000000000..9beb413944
--- /dev/null
+++ b/src/AddIns/Misc/UnitTesting/Test/Tree/TreeNodeContextMenuTestFixture.cs
@@ -0,0 +1,54 @@
+//
+//
+//
+//
+// $Revision$
+//
+
+using System;
+using System.Windows.Forms;
+using ICSharpCode.SharpDevelop.Gui;
+using ICSharpCode.UnitTesting;
+using NUnit.Framework;
+using UnitTesting.Tests.Utils;
+
+namespace UnitTesting.Tests.Tree
+{
+ ///
+ /// Tests that the TestTreeNode's ContextMenuStrip is set so
+ /// that if the user uses the shortcut Shift+F10 the menu appears
+ /// at the node rather than in the middle of the Unit Tests window.
+ ///
+ [TestFixture]
+ public class TreeNodeContextMenuTestFixture
+ {
+ ///
+ /// Tests that the context menu strip for the tree node is
+ /// the same as that used with the tree view.
+ ///
+ [Test]
+ public void TreeNodeContextMenuMatches()
+ {
+ using (DerivedTestTreeView treeView = new DerivedTestTreeView()) {
+ ContextMenuStrip menuStrip = new ContextMenuStrip();
+ treeView.ContextMenuStrip = menuStrip;
+
+ // Add a root node to the tree.
+ TestProject project = new TestProject(new MockCSharpProject(), new MockProjectContent());
+ TestProjectTreeNode node = new TestProjectTreeNode(project);
+ node.AddTo(treeView);
+
+ // Select the tree node.
+ treeView.SelectedNode = node;
+
+ // Call the treeView's OnBeforeSelect so the context menu
+ // is connected to the tree node.
+ treeView.CallOnBeforeSelect(new TreeViewCancelEventArgs(node, false, TreeViewAction.ByMouse));
+
+ // Context menu strip on tree node should match
+ // the tree view's context menu strip.
+ Assert.IsTrue(Object.ReferenceEquals(menuStrip, node.ContextMenuStrip));
+ }
+ }
+ }
+}
diff --git a/src/AddIns/Misc/UnitTesting/Test/UnitTesting.Tests.csproj b/src/AddIns/Misc/UnitTesting/Test/UnitTesting.Tests.csproj
index 72ed8a1afd..50b9f5a006 100644
--- a/src/AddIns/Misc/UnitTesting/Test/UnitTesting.Tests.csproj
+++ b/src/AddIns/Misc/UnitTesting/Test/UnitTesting.Tests.csproj
@@ -45,20 +45,22 @@
..\..\..\..\Tools\NUnit\nunit.core.dll
False
-
-
..\..\..\..\Tools\NUnit\nunit.framework.dll
False
+
+
+
+
diff --git a/src/AddIns/Misc/UnitTesting/Test/Utils/DerivedTestTreeView.cs b/src/AddIns/Misc/UnitTesting/Test/Utils/DerivedTestTreeView.cs
new file mode 100644
index 0000000000..767bdb125f
--- /dev/null
+++ b/src/AddIns/Misc/UnitTesting/Test/Utils/DerivedTestTreeView.cs
@@ -0,0 +1,28 @@
+//
+//
+//
+//
+// $Revision$
+//
+
+using System;
+using System.Windows.Forms;
+using ICSharpCode.UnitTesting;
+
+namespace UnitTesting.Tests.Utils
+{
+ ///
+ /// Derives from the TestTreeView class and allows us to directly
+ /// call the OnBeforeSelect method.
+ ///
+ public class DerivedTestTreeView : TestTreeView
+ {
+ ///
+ /// Calls the base class's OnBeforeSelect method.
+ ///
+ public void CallOnBeforeSelect(TreeViewCancelEventArgs e)
+ {
+ base.OnBeforeSelect(e);
+ }
+ }
+}