Browse Source

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
shortcuts
Matt Ward 19 years ago
parent
commit
ea4786654b
  1. 16
      src/AddIns/Misc/UnitTesting/Src/TestTreeView.cs
  2. 4
      src/AddIns/Misc/UnitTesting/Src/UnitTestsPad.cs
  3. 54
      src/AddIns/Misc/UnitTesting/Test/Tree/TreeNodeContextMenuTestFixture.cs
  4. 6
      src/AddIns/Misc/UnitTesting/Test/UnitTesting.Tests.csproj
  5. 28
      src/AddIns/Misc/UnitTesting/Test/Utils/DerivedTestTreeView.cs

16
src/AddIns/Misc/UnitTesting/Src/TestTreeView.cs

@ -7,6 +7,7 @@ @@ -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 @@ -255,6 +256,21 @@ namespace ICSharpCode.UnitTesting
}
}
/// <summary>
/// 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.
/// </summary>
protected override void OnBeforeSelect(TreeViewCancelEventArgs e)
{
TreeNode node = e.Node;
if (node.ContextMenuStrip == null) {
node.ContextMenuStrip = ContextMenuStrip;
}
}
/// <summary>
/// Returns the project tree node that is associated with the
/// specified project.

4
src/AddIns/Misc/UnitTesting/Src/UnitTestsPad.cs

@ -187,7 +187,7 @@ namespace ICSharpCode.UnitTesting @@ -187,7 +187,7 @@ namespace ICSharpCode.UnitTesting
/// </summary>
protected virtual ToolStrip CreateToolStrip(string name)
{
return ToolbarService.CreateToolStrip(treeView, "/SharpDevelop/Pads/UnitTestsPad/Toolbar");
return ToolbarService.CreateToolStrip(treeView, name);
}
/// <summary>
@ -196,7 +196,7 @@ namespace ICSharpCode.UnitTesting @@ -196,7 +196,7 @@ namespace ICSharpCode.UnitTesting
/// </summary>
protected virtual ContextMenuStrip CreateContextMenu(string name)
{
return MenuService.CreateContextMenu(treeView, "/SharpDevelop/Pads/UnitTestsPad/ContextMenu");
return MenuService.CreateContextMenu(treeView, name);
}
/// <summary>

54
src/AddIns/Misc/UnitTesting/Test/Tree/TreeNodeContextMenuTestFixture.cs

@ -0,0 +1,54 @@ @@ -0,0 +1,54 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Windows.Forms;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Tree
{
/// <summary>
/// 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.
/// </summary>
[TestFixture]
public class TreeNodeContextMenuTestFixture
{
/// <summary>
/// Tests that the context menu strip for the tree node is
/// the same as that used with the tree view.
/// </summary>
[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));
}
}
}
}

6
src/AddIns/Misc/UnitTesting/Test/UnitTesting.Tests.csproj

@ -45,20 +45,22 @@ @@ -45,20 +45,22 @@
<HintPath>..\..\..\..\Tools\NUnit\nunit.core.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="nunit.framework">
<HintPath>..\..\..\..\Tools\NUnit\nunit.framework.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.cs" />
<Compile Include="NamespaceFilterTests.cs" />
<Compile Include="TestableConditionTests.cs" />
<Compile Include="Tree\TreeNodeContextMenuTestFixture.cs" />
<Compile Include="Tree\TreeNodeSortingTestFixture.cs" />
<Compile Include="Tree\OpenUnitTestsPadWithSolutionOpenTestFixture.cs" />
<Compile Include="Utils\DerivedTestTreeView.cs" />
<Compile Include="Utils\DerivedUnitTestsPad.cs" />
<Compile Include="Utils\MockTestCase.cs" />
<Compile Include="Utils\MockTestTreeView.cs" />

28
src/AddIns/Misc/UnitTesting/Test/Utils/DerivedTestTreeView.cs

@ -0,0 +1,28 @@ @@ -0,0 +1,28 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Windows.Forms;
using ICSharpCode.UnitTesting;
namespace UnitTesting.Tests.Utils
{
/// <summary>
/// Derives from the TestTreeView class and allows us to directly
/// call the OnBeforeSelect method.
/// </summary>
public class DerivedTestTreeView : TestTreeView
{
/// <summary>
/// Calls the base class's OnBeforeSelect method.
/// </summary>
public void CallOnBeforeSelect(TreeViewCancelEventArgs e)
{
base.OnBeforeSelect(e);
}
}
}
Loading…
Cancel
Save