📄 testtree.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using NUnit.Util;
namespace NUnit.UiKit
{
public delegate void SelectedTestsChangedEventHandler(object sender, SelectedTestsChangedEventArgs e);
/// <summary>
/// Summary description for TestTree.
/// </summary>
public class TestTree : System.Windows.Forms.UserControl
{
// Contains all available categories, whether
// selected or not. Unselected members of this
// list are displayed in selectedList
private IList availableCategories;
private System.Windows.Forms.TabControl tabs;
private System.Windows.Forms.TabPage testPage;
private System.Windows.Forms.TabPage categoryPage;
private System.Windows.Forms.Panel testPanel;
private System.Windows.Forms.Panel categoryPanel;
private System.Windows.Forms.Panel treePanel;
private System.Windows.Forms.Panel buttonPanel;
public NUnit.UiKit.TestSuiteTreeView tests;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.ListBox availableList;
private System.Windows.Forms.GroupBox selectedCategories;
private System.Windows.Forms.ListBox selectedList;
private System.Windows.Forms.Panel categoryButtonPanel;
private System.Windows.Forms.Button addCategory;
private System.Windows.Forms.Button removeCategory;
private System.Windows.Forms.Button clearAllButton;
private System.Windows.Forms.Button checkFailedButton;
private System.Windows.Forms.MenuItem viewMenu;
private System.Windows.Forms.MenuItem expandMenuItem;
private System.Windows.Forms.MenuItem collapseMenuItem;
private System.Windows.Forms.MenuItem viewMenuSeparatorItem1;
private System.Windows.Forms.MenuItem expandAllMenuItem;
private System.Windows.Forms.MenuItem collapseAllMenuItem;
private System.Windows.Forms.MenuItem viewMenuSeparatorItem2;
private System.Windows.Forms.MenuItem expandFixturesMenuItem;
private System.Windows.Forms.MenuItem collapseFixturesMenuItem;
private System.Windows.Forms.MenuItem viewMenuSeparatorItem3;
private System.Windows.Forms.MenuItem propertiesMenuItem;
private System.Windows.Forms.MenuItem checkBoxesMenuItem;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.CheckBox excludeCheckbox;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public MenuItem ViewMenu
{
get { return viewMenu; }
}
public string[] SelectedCategories
{
get
{
int n = this.selectedList.Items.Count;
string[] categories = new string[n];
for( int i = 0; i < n; i++ )
categories[i] = this.selectedList.Items[i].ToString();
return categories;
}
}
#region Construction and Initialization
public TestTree()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
viewMenu = new MenuItem();
this.expandMenuItem = new System.Windows.Forms.MenuItem();
this.collapseMenuItem = new System.Windows.Forms.MenuItem();
this.viewMenuSeparatorItem1 = new System.Windows.Forms.MenuItem();
this.expandAllMenuItem = new System.Windows.Forms.MenuItem();
this.collapseAllMenuItem = new System.Windows.Forms.MenuItem();
this.viewMenuSeparatorItem2 = new System.Windows.Forms.MenuItem();
this.expandFixturesMenuItem = new System.Windows.Forms.MenuItem();
this.collapseFixturesMenuItem = new System.Windows.Forms.MenuItem();
this.viewMenuSeparatorItem3 = new System.Windows.Forms.MenuItem();
this.propertiesMenuItem = new System.Windows.Forms.MenuItem();
this.checkBoxesMenuItem = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
//
// viewMenu
//
this.viewMenu.MergeType = MenuMerge.Add;
this.viewMenu.MergeOrder = 1;
this.viewMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.expandMenuItem,
this.collapseMenuItem,
this.viewMenuSeparatorItem1,
this.expandAllMenuItem,
this.collapseAllMenuItem,
this.viewMenuSeparatorItem2,
this.expandFixturesMenuItem,
this.collapseFixturesMenuItem,
this.viewMenuSeparatorItem3,
this.propertiesMenuItem,
this.checkBoxesMenuItem,
this.menuItem2});
this.viewMenu.Text = "&View";
this.viewMenu.Visible = false;
this.viewMenu.Popup += new System.EventHandler(this.viewMenu_Popup);
//
// expandMenuItem
//
this.expandMenuItem.Index = 0;
this.expandMenuItem.Text = "&Expand";
this.expandMenuItem.Click += new System.EventHandler(this.expandMenuItem_Click);
//
// collapseMenuItem
//
this.collapseMenuItem.Index = 1;
this.collapseMenuItem.Text = "&Collapse";
this.collapseMenuItem.Click += new System.EventHandler(this.collapseMenuItem_Click);
//
// viewMenuSeparatorItem1
//
this.viewMenuSeparatorItem1.Index = 2;
this.viewMenuSeparatorItem1.Text = "-";
//
// expandAllMenuItem
//
this.expandAllMenuItem.Index = 3;
this.expandAllMenuItem.Text = "Expand All";
this.expandAllMenuItem.Click += new System.EventHandler(this.expandAllMenuItem_Click);
//
// collapseAllMenuItem
//
this.collapseAllMenuItem.Index = 4;
this.collapseAllMenuItem.Text = "Collapse All";
this.collapseAllMenuItem.Click += new System.EventHandler(this.collapseAllMenuItem_Click);
//
// viewMenuSeparatorItem2
//
this.viewMenuSeparatorItem2.Index = 5;
this.viewMenuSeparatorItem2.Text = "-";
//
// expandFixturesMenuItem
//
this.expandFixturesMenuItem.Index = 6;
this.expandFixturesMenuItem.Text = "Expand Fixtures";
this.expandFixturesMenuItem.Click += new System.EventHandler(this.expandFixturesMenuItem_Click);
//
// collapseFixturesMenuItem
//
this.collapseFixturesMenuItem.Index = 7;
this.collapseFixturesMenuItem.Text = "Collapse Fixtures";
this.collapseFixturesMenuItem.Click += new System.EventHandler(this.collapseFixturesMenuItem_Click);
//
// viewMenuSeparatorItem3
//
this.viewMenuSeparatorItem3.Index = 8;
this.viewMenuSeparatorItem3.Text = "-";
//
// propertiesMenuItem
//
this.propertiesMenuItem.Index = 9;
this.propertiesMenuItem.Text = "&Properties";
this.propertiesMenuItem.Click += new System.EventHandler(this.propertiesMenuItem_Click);
//
// checkBoxesMenuItem
//
this.checkBoxesMenuItem.Index = 0;
this.checkBoxesMenuItem.Text = "Check&Boxes";
this.checkBoxesMenuItem.Click += new System.EventHandler(this.checkBoxesMenuItem_Click);
//
// menuItem2
//
this.menuItem2.Index = 1;
this.menuItem2.Text = "-";
tests.SelectedTestChanged += new SelectedTestChangedHandler(tests_SelectedTestChanged);
tests.CheckedTestChanged += new CheckedTestChangedHandler(tests_CheckedTestChanged);
ShowCheckBoxes( UserSettings.Options.ShowCheckBoxes );
this.excludeCheckbox.Enabled = this.SelectedCategories.Length > 0;
}
public void Initialize(TestLoader loader)
{
this.tests.Initialize(loader, loader.Events);
loader.Events.TestLoaded += new NUnit.Core.TestEventHandler(events_TestLoaded);
loader.Events.TestReloaded += new NUnit.Core.TestEventHandler(events_TestReloaded);
loader.Events.TestUnloaded += new NUnit.Core.TestEventHandler(Events_TestUnloaded);
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#endregion
#region View Menu Handlers
private void viewMenu_Popup(object sender, System.EventArgs e)
{
TreeNode selectedNode = tests.SelectedNode;
if ( selectedNode != null && selectedNode.Nodes.Count > 0 )
{
bool isExpanded = selectedNode.IsExpanded;
collapseMenuItem.Enabled = isExpanded;
expandMenuItem.Enabled = !isExpanded;
}
else
{
collapseMenuItem.Enabled = expandMenuItem.Enabled = false;
}
}
private void collapseMenuItem_Click(object sender, System.EventArgs e)
{
tests.SelectedNode.Collapse();
}
private void expandMenuItem_Click(object sender, System.EventArgs e)
{
tests.SelectedNode.Expand();
}
private void collapseAllMenuItem_Click(object sender, System.EventArgs e)
{
tests.CollapseAll();
// Compensate for a bug in the underlying control
if ( tests.Nodes.Count > 0 )
tests.SelectedNode = tests.Nodes[0];
}
private void expandAllMenuItem_Click(object sender, System.EventArgs e)
{
tests.ExpandAll();
}
private void collapseFixturesMenuItem_Click(object sender, System.EventArgs e)
{
tests.CollapseFixtures();
}
private void expandFixturesMenuItem_Click(object sender, System.EventArgs e)
{
tests.ExpandFixtures();
}
private void propertiesMenuItem_Click(object sender, System.EventArgs e)
{
if ( tests.SelectedTest != null )
tests.ShowPropertiesDialog( tests.SelectedTest );
}
#endregion
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.tabs = new System.Windows.Forms.TabControl();
this.testPage = new System.Windows.Forms.TabPage();
this.testPanel = new System.Windows.Forms.Panel();
this.treePanel = new System.Windows.Forms.Panel();
this.tests = new NUnit.UiKit.TestSuiteTreeView();
this.buttonPanel = new System.Windows.Forms.Panel();
this.checkFailedButton = new System.Windows.Forms.Button();
this.clearAllButton = new System.Windows.Forms.Button();
this.categoryPage = new System.Windows.Forms.TabPage();
this.categoryPanel = new System.Windows.Forms.Panel();
this.categoryButtonPanel = new System.Windows.Forms.Panel();
this.removeCategory = new System.Windows.Forms.Button();
this.addCategory = new System.Windows.Forms.Button();
this.selectedCategories = new System.Windows.Forms.GroupBox();
this.selectedList = new System.Windows.Forms.ListBox();
this.excludeCheckbox = new System.Windows.Forms.CheckBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.availableList = new System.Windows.Forms.ListBox();
this.tabs.SuspendLayout();
this.testPage.SuspendLayout();
this.testPanel.SuspendLayout();
this.treePanel.SuspendLayout();
this.buttonPanel.SuspendLayout();
this.categoryPage.SuspendLayout();
this.categoryPanel.SuspendLayout();
this.categoryButtonPanel.SuspendLayout();
this.selectedCategories.SuspendLayout();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// tabs
//
this.tabs.Controls.Add(this.testPage);
this.tabs.Controls.Add(this.categoryPage);
this.tabs.Dock = System.Windows.Forms.DockStyle.Fill;
this.tabs.Location = new System.Drawing.Point(0, 0);
this.tabs.Name = "tabs";
this.tabs.SelectedIndex = 0;
this.tabs.Size = new System.Drawing.Size(248, 496);
this.tabs.TabIndex = 0;
//
// testPage
//
this.testPage.Controls.Add(this.testPanel);
this.testPage.Location = new System.Drawing.Point(4, 22);
this.testPage.Name = "testPage";
this.testPage.Size = new System.Drawing.Size(240, 470);
this.testPage.TabIndex = 0;
this.testPage.Text = "Tests";
//
// testPanel
//
this.testPanel.Controls.Add(this.treePanel);
this.testPanel.Controls.Add(this.buttonPanel);
this.testPanel.Dock = System.Windows.Forms.DockStyle.Fill;
this.testPanel.Location = new System.Drawing.Point(0, 0);
this.testPanel.Name = "testPanel";
this.testPanel.Size = new System.Drawing.Size(240, 470);
this.testPanel.TabIndex = 0;
//
// treePanel
//
this.treePanel.Controls.Add(this.tests);
this.treePanel.Dock = System.Windows.Forms.DockStyle.Fill;
this.treePanel.Location = new System.Drawing.Point(0, 0);
this.treePanel.Name = "treePanel";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -