1
// ****************************************************************
2
// This is free software licensed under the NUnit license. You may
3
// obtain a copy of the license at http://nunit.org
4
// ****************************************************************
7
using System.Collections.Generic;
9
using System.Windows.Forms;
11
namespace NUnit.UiException.Controls
14
/// A control that encapsulates a collection of IErrorDisplay instances
15
/// and which shows relevant information about failures & errors after
17
/// By default, ErrorBrowser is empty and should be populated with
18
/// IErrorDisplay instances at loading time. The example below shows how
21
/// ErrorBrowser errorBrowser = new ErrorBrowser();
23
/// // configure and register a SourceCodeDisplay
24
/// // that will display source code context on failure
26
/// SourceCodeDisplay sourceCode = new SourceCodeDisplay();
27
/// sourceCode.AutoSelectFirstItem = true;
28
/// sourceCode.ListOrderPolicy = ErrorListOrderPolicy.ReverseOrder;
29
/// sourceCode.SplitOrientation = Orientation.Vertical;
30
/// sourceCode.SplitterDistance = 0.3f;
32
/// errorBrowser.RegisterDisplay(sourceCode);
34
/// // configure and register a StackTraceDisplay
35
/// // that will display the stack trace details on failure
37
/// errorBrowser.RegisterDisplay(new StackTraceDisplay());
39
/// // set the stack trace information
40
/// errorBrowser.StackTraceSource = [a stack trace here]
43
public class ErrorBrowser : UserControl
45
public event EventHandler StackTraceSourceChanged;
46
public event EventHandler StackTraceDisplayChanged;
47
private ErrorPanelLayout _layout;
49
private string _stackStace;
52
/// Builds a new instance of ErrorBrowser.
56
_layout = new ErrorPanelLayout();
57
_layout.Toolbar = new ErrorToolbar();
58
Toolbar.SelectedRendererChanged += new EventHandler(Toolbar_SelectedRendererChanged);
60
Controls.Add(_layout);
63
_layout.Width = Width;
64
_layout.Height = Height;
66
_layout.Anchor = AnchorStyles.Top |
75
/// Use this property to get or set the new stack trace details.
76
/// The changes are repercuted on the registered displays.
78
public string StackTraceSource
80
get { return (_stackStace); }
82
if (_stackStace == value)
87
foreach (IErrorDisplay item in Toolbar)
88
item.OnStackTraceChanged(value);
90
if (StackTraceSourceChanged != null)
91
StackTraceSourceChanged(this, new EventArgs());
98
/// Gets the selected display.
100
public IErrorDisplay SelectedDisplay
102
get { return (Toolbar.SelectedDisplay); }
103
set { Toolbar.SelectedDisplay = value; }
107
/// Populates ErrorBrowser with the new display passed in parameter.
108
/// If ErrorBrowser is empty, the display becomes automatically the
109
/// new selected display.
111
/// <param name="display"></param>
112
public void RegisterDisplay(IErrorDisplay display)
114
UiExceptionHelper.CheckNotNull(display, "display");
116
Toolbar.Register(display);
117
display.OnStackTraceChanged(_stackStace);
119
if (Toolbar.SelectedDisplay == null)
120
Toolbar.SelectedDisplay = display;
126
/// Removes all display from ErrorBrowser.
128
public void ClearAll()
132
LayoutPanel.Option = null;
133
LayoutPanel.Content = null;
138
void Toolbar_SelectedRendererChanged(object sender, EventArgs e)
140
LayoutPanel.Content = Toolbar.SelectedDisplay.Content;
142
if (StackTraceDisplayChanged != null)
143
StackTraceDisplayChanged(this, EventArgs.Empty);
148
protected ErrorPanelLayout LayoutPanel
150
get { return (_layout); }
153
protected ErrorToolbar Toolbar
155
get { return ((ErrorToolbar)_layout.Toolbar); }
1
// ****************************************************************
2
// This is free software licensed under the NUnit license. You may
3
// obtain a copy of the license at http://nunit.org
4
// ****************************************************************
7
using System.Collections.Generic;
9
using System.Windows.Forms;
11
namespace NUnit.UiException.Controls
14
/// A control that encapsulates a collection of IErrorDisplay instances
15
/// and which shows relevant information about failures & errors after
17
/// By default, ErrorBrowser is empty and should be populated with
18
/// IErrorDisplay instances at loading time. The example below shows how
21
/// ErrorBrowser errorBrowser = new ErrorBrowser();
23
/// // configure and register a SourceCodeDisplay
24
/// // that will display source code context on failure
26
/// SourceCodeDisplay sourceCode = new SourceCodeDisplay();
27
/// sourceCode.AutoSelectFirstItem = true;
28
/// sourceCode.ListOrderPolicy = ErrorListOrderPolicy.ReverseOrder;
29
/// sourceCode.SplitOrientation = Orientation.Vertical;
30
/// sourceCode.SplitterDistance = 0.3f;
32
/// errorBrowser.RegisterDisplay(sourceCode);
34
/// // configure and register a StackTraceDisplay
35
/// // that will display the stack trace details on failure
37
/// errorBrowser.RegisterDisplay(new StackTraceDisplay());
39
/// // set the stack trace information
40
/// errorBrowser.StackTraceSource = [a stack trace here]
43
public class ErrorBrowser : UserControl
45
public event EventHandler StackTraceSourceChanged;
46
public event EventHandler StackTraceDisplayChanged;
47
private ErrorPanelLayout _layout;
49
private string _stackStace;
52
/// Builds a new instance of ErrorBrowser.
56
_layout = new ErrorPanelLayout();
57
_layout.Toolbar = new ErrorToolbar();
58
Toolbar.SelectedRendererChanged += new EventHandler(Toolbar_SelectedRendererChanged);
60
Controls.Add(_layout);
63
_layout.Width = Width;
64
_layout.Height = Height;
66
_layout.Anchor = AnchorStyles.Top |
75
/// Use this property to get or set the new stack trace details.
76
/// The changes are repercuted on the registered displays.
78
public string StackTraceSource
80
get { return (_stackStace); }
82
if (_stackStace == value)
87
foreach (IErrorDisplay item in Toolbar)
88
item.OnStackTraceChanged(value);
90
if (StackTraceSourceChanged != null)
91
StackTraceSourceChanged(this, new EventArgs());
98
/// Gets the selected display.
100
public IErrorDisplay SelectedDisplay
102
get { return (Toolbar.SelectedDisplay); }
103
set { Toolbar.SelectedDisplay = value; }
107
/// Populates ErrorBrowser with the new display passed in parameter.
108
/// If ErrorBrowser is empty, the display becomes automatically the
109
/// new selected display.
111
/// <param name="display"></param>
112
public void RegisterDisplay(IErrorDisplay display)
114
UiExceptionHelper.CheckNotNull(display, "display");
116
Toolbar.Register(display);
117
display.OnStackTraceChanged(_stackStace);
119
if (Toolbar.SelectedDisplay == null)
120
Toolbar.SelectedDisplay = display;
126
/// Removes all display from ErrorBrowser.
128
public void ClearAll()
132
LayoutPanel.Option = null;
133
LayoutPanel.Content = null;
138
void Toolbar_SelectedRendererChanged(object sender, EventArgs e)
140
LayoutPanel.Content = Toolbar.SelectedDisplay.Content;
142
if (StackTraceDisplayChanged != null)
143
StackTraceDisplayChanged(this, EventArgs.Empty);
148
protected ErrorPanelLayout LayoutPanel
150
get { return (_layout); }
153
protected ErrorToolbar Toolbar
155
get { return ((ErrorToolbar)_layout.Toolbar); }