From ea4786654b0c49d014e88179da31414d755c3167 Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Sun, 21 Jan 2007 19:16:09 +0000 Subject: [PATCH] Fixed SD2-768 for the Unit Tests tree. The context menu is set for each test tree node so it will open near the node and not in the middle of the window when using the keyboard shortcut Shift+F10. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.1@2312 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Misc/UnitTesting/Src/TestTreeView.cs | 16 ++++++ .../Misc/UnitTesting/Src/UnitTestsPad.cs | 4 +- .../Tree/TreeNodeContextMenuTestFixture.cs | 54 +++++++++++++++++++ .../UnitTesting/Test/UnitTesting.Tests.csproj | 6 ++- .../Test/Utils/DerivedTestTreeView.cs | 28 ++++++++++ 5 files changed, 104 insertions(+), 4 deletions(-) create mode 100644 src/AddIns/Misc/UnitTesting/Test/Tree/TreeNodeContextMenuTestFixture.cs create mode 100644 src/AddIns/Misc/UnitTesting/Test/Utils/DerivedTestTreeView.cs 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); + } + } +}