~ubuntu-branches/debian/sid/nunit/sid

« back to all changes in this revision

Viewing changes to src/GuiException/UiException/Controls/ErrorBrowser.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2014-09-16 13:43:36 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20140916134336-kjxz48tty6lx2ja5
Tags: 2.6.3+dfsg-1
* [c7bd1b5] Imported Upstream version 2.6.3+dfsg
* [bcb4bf8] Move nunit-console-runner to GAC-installed libnunit2.6, 
  don't treat it as a private lib. This lib is signed, and treated 
  as a GAC lib by consumers such as MonoDevelop.
* [7f08e99] Bump version to 2.6.3 as required
* [84535eb] Refreshed patches
* [8479f61] Split package up into per-assembly packages. This makes 
  ABI tracking easier in the future, as we can meaningfully have GAC 
  policy for cases where ABI isn't truly bumped, and no policy for 
  cases where it is. For example, if nunit.framework bumps ABI but 
  nunit.core does not, previously we would need to rebuild everything 
  using NUnit, but under the new split packaging, that rebuild would 
  not be needed for apps only using nunit.core.
* [17a7dc7] Add missing nunit.mocks.dll to nunit.pc

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
// ****************************************************************
5
 
 
6
 
using System;
7
 
using System.Collections.Generic;
8
 
using System.Text;
9
 
using System.Windows.Forms;
10
 
 
11
 
namespace NUnit.UiException.Controls
12
 
{
13
 
    /// <summary>
14
 
    /// A control that encapsulates a collection of IErrorDisplay instances
15
 
    /// and which shows relevant information about failures & errors after
16
 
    /// a test suite run.
17
 
    ///     By default, ErrorBrowser is empty and should be populated with
18
 
    /// IErrorDisplay instances at loading time. The example below shows how
19
 
    /// to achieve this:
20
 
    /// <code>
21
 
    /// ErrorBrowser errorBrowser = new ErrorBrowser();
22
 
    /// 
23
 
    /// // configure and register a SourceCodeDisplay
24
 
    /// // that will display source code context on failure
25
 
    /// 
26
 
    /// SourceCodeDisplay sourceCode = new SourceCodeDisplay();
27
 
    /// sourceCode.AutoSelectFirstItem = true;
28
 
    /// sourceCode.ListOrderPolicy = ErrorListOrderPolicy.ReverseOrder;
29
 
    /// sourceCode.SplitOrientation = Orientation.Vertical;
30
 
    /// sourceCode.SplitterDistance = 0.3f;
31
 
    ///
32
 
    /// errorBrowser.RegisterDisplay(sourceCode);
33
 
    /// 
34
 
    /// // configure and register a StackTraceDisplay
35
 
    /// // that will display the stack trace details on failure
36
 
    /// 
37
 
    /// errorBrowser.RegisterDisplay(new StackTraceDisplay());
38
 
    /// [...]
39
 
    /// // set the stack trace information
40
 
    /// errorBrowser.StackTraceSource = [a stack trace here]
41
 
    /// </code>
42
 
    /// </summary>
43
 
    public class ErrorBrowser : UserControl
44
 
    {
45
 
        public event EventHandler StackTraceSourceChanged;
46
 
        public event EventHandler StackTraceDisplayChanged;
47
 
        private ErrorPanelLayout _layout;
48
 
 
49
 
        private string _stackStace;
50
 
 
51
 
        /// <summary>
52
 
        /// Builds a new instance of ErrorBrowser.
53
 
        /// </summary>
54
 
        public ErrorBrowser()
55
 
        {            
56
 
            _layout = new ErrorPanelLayout();
57
 
            _layout.Toolbar = new ErrorToolbar();            
58
 
            Toolbar.SelectedRendererChanged += new EventHandler(Toolbar_SelectedRendererChanged);
59
 
 
60
 
            Controls.Add(_layout);
61
 
            _layout.Left = 0;
62
 
            _layout.Top = 0;
63
 
            _layout.Width = Width;
64
 
            _layout.Height = Height;
65
 
 
66
 
            _layout.Anchor = AnchorStyles.Top |
67
 
                             AnchorStyles.Left |
68
 
                             AnchorStyles.Bottom |
69
 
                             AnchorStyles.Right;
70
 
 
71
 
            return;
72
 
        }        
73
 
 
74
 
        /// <summary>
75
 
        /// Use this property to get or set the new stack trace details.
76
 
        /// The changes are repercuted on the registered displays.
77
 
        /// </summary>
78
 
        public string StackTraceSource
79
 
        {
80
 
            get { return (_stackStace); }
81
 
            set {
82
 
                if (_stackStace == value)
83
 
                    return;
84
 
 
85
 
                _stackStace = value;
86
 
 
87
 
                foreach (IErrorDisplay item in Toolbar)
88
 
                    item.OnStackTraceChanged(value);
89
 
 
90
 
                if (StackTraceSourceChanged != null)
91
 
                    StackTraceSourceChanged(this, new EventArgs());
92
 
 
93
 
                return;
94
 
            }
95
 
        }
96
 
 
97
 
        /// <summary>
98
 
        /// Gets the selected display.
99
 
        /// </summary>
100
 
        public IErrorDisplay SelectedDisplay
101
 
        {
102
 
            get { return (Toolbar.SelectedDisplay); }
103
 
            set { Toolbar.SelectedDisplay = value; }
104
 
        }
105
 
 
106
 
        /// <summary>
107
 
        /// Populates ErrorBrowser with the new display passed in parameter.
108
 
        /// If ErrorBrowser is empty, the display becomes automatically the
109
 
        /// new selected display.
110
 
        /// </summary>
111
 
        /// <param name="display"></param>
112
 
        public void RegisterDisplay(IErrorDisplay display)
113
 
        {
114
 
            UiExceptionHelper.CheckNotNull(display, "display");
115
 
 
116
 
            Toolbar.Register(display);
117
 
            display.OnStackTraceChanged(_stackStace);
118
 
 
119
 
            if (Toolbar.SelectedDisplay == null)
120
 
                Toolbar.SelectedDisplay = display;
121
 
 
122
 
            return;
123
 
        }
124
 
 
125
 
        /// <summary>
126
 
        /// Removes all display from ErrorBrowser.
127
 
        /// </summary>
128
 
        public void ClearAll()
129
 
        {
130
 
            Toolbar.Clear();
131
 
 
132
 
            LayoutPanel.Option = null;
133
 
            LayoutPanel.Content = null;
134
 
 
135
 
            return;
136
 
        }
137
 
 
138
 
        void Toolbar_SelectedRendererChanged(object sender, EventArgs e)
139
 
        {
140
 
            LayoutPanel.Content = Toolbar.SelectedDisplay.Content;
141
 
 
142
 
            if (StackTraceDisplayChanged != null)
143
 
                StackTraceDisplayChanged(this, EventArgs.Empty);
144
 
 
145
 
            return;
146
 
        }
147
 
 
148
 
        protected ErrorPanelLayout LayoutPanel
149
 
        {
150
 
            get { return (_layout); }
151
 
        }
152
 
 
153
 
        protected ErrorToolbar Toolbar
154
 
        {
155
 
            get { return ((ErrorToolbar)_layout.Toolbar); }
156
 
        }
157
 
    }
158
 
}
 
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
// ****************************************************************
 
5
 
 
6
using System;
 
7
using System.Collections.Generic;
 
8
using System.Text;
 
9
using System.Windows.Forms;
 
10
 
 
11
namespace NUnit.UiException.Controls
 
12
{
 
13
    /// <summary>
 
14
    /// A control that encapsulates a collection of IErrorDisplay instances
 
15
    /// and which shows relevant information about failures & errors after
 
16
    /// a test suite run.
 
17
    ///     By default, ErrorBrowser is empty and should be populated with
 
18
    /// IErrorDisplay instances at loading time. The example below shows how
 
19
    /// to achieve this:
 
20
    /// <code>
 
21
    /// ErrorBrowser errorBrowser = new ErrorBrowser();
 
22
    /// 
 
23
    /// // configure and register a SourceCodeDisplay
 
24
    /// // that will display source code context on failure
 
25
    /// 
 
26
    /// SourceCodeDisplay sourceCode = new SourceCodeDisplay();
 
27
    /// sourceCode.AutoSelectFirstItem = true;
 
28
    /// sourceCode.ListOrderPolicy = ErrorListOrderPolicy.ReverseOrder;
 
29
    /// sourceCode.SplitOrientation = Orientation.Vertical;
 
30
    /// sourceCode.SplitterDistance = 0.3f;
 
31
    ///
 
32
    /// errorBrowser.RegisterDisplay(sourceCode);
 
33
    /// 
 
34
    /// // configure and register a StackTraceDisplay
 
35
    /// // that will display the stack trace details on failure
 
36
    /// 
 
37
    /// errorBrowser.RegisterDisplay(new StackTraceDisplay());
 
38
    /// [...]
 
39
    /// // set the stack trace information
 
40
    /// errorBrowser.StackTraceSource = [a stack trace here]
 
41
    /// </code>
 
42
    /// </summary>
 
43
    public class ErrorBrowser : UserControl
 
44
    {
 
45
        public event EventHandler StackTraceSourceChanged;
 
46
        public event EventHandler StackTraceDisplayChanged;
 
47
        private ErrorPanelLayout _layout;
 
48
 
 
49
        private string _stackStace;
 
50
 
 
51
        /// <summary>
 
52
        /// Builds a new instance of ErrorBrowser.
 
53
        /// </summary>
 
54
        public ErrorBrowser()
 
55
        {            
 
56
            _layout = new ErrorPanelLayout();
 
57
            _layout.Toolbar = new ErrorToolbar();            
 
58
            Toolbar.SelectedRendererChanged += new EventHandler(Toolbar_SelectedRendererChanged);
 
59
 
 
60
            Controls.Add(_layout);
 
61
            _layout.Left = 0;
 
62
            _layout.Top = 0;
 
63
            _layout.Width = Width;
 
64
            _layout.Height = Height;
 
65
 
 
66
            _layout.Anchor = AnchorStyles.Top |
 
67
                             AnchorStyles.Left |
 
68
                             AnchorStyles.Bottom |
 
69
                             AnchorStyles.Right;
 
70
 
 
71
            return;
 
72
        }        
 
73
 
 
74
        /// <summary>
 
75
        /// Use this property to get or set the new stack trace details.
 
76
        /// The changes are repercuted on the registered displays.
 
77
        /// </summary>
 
78
        public string StackTraceSource
 
79
        {
 
80
            get { return (_stackStace); }
 
81
            set {
 
82
                if (_stackStace == value)
 
83
                    return;
 
84
 
 
85
                _stackStace = value;
 
86
 
 
87
                foreach (IErrorDisplay item in Toolbar)
 
88
                    item.OnStackTraceChanged(value);
 
89
 
 
90
                if (StackTraceSourceChanged != null)
 
91
                    StackTraceSourceChanged(this, new EventArgs());
 
92
 
 
93
                return;
 
94
            }
 
95
        }
 
96
 
 
97
        /// <summary>
 
98
        /// Gets the selected display.
 
99
        /// </summary>
 
100
        public IErrorDisplay SelectedDisplay
 
101
        {
 
102
            get { return (Toolbar.SelectedDisplay); }
 
103
            set { Toolbar.SelectedDisplay = value; }
 
104
        }
 
105
 
 
106
        /// <summary>
 
107
        /// Populates ErrorBrowser with the new display passed in parameter.
 
108
        /// If ErrorBrowser is empty, the display becomes automatically the
 
109
        /// new selected display.
 
110
        /// </summary>
 
111
        /// <param name="display"></param>
 
112
        public void RegisterDisplay(IErrorDisplay display)
 
113
        {
 
114
            UiExceptionHelper.CheckNotNull(display, "display");
 
115
 
 
116
            Toolbar.Register(display);
 
117
            display.OnStackTraceChanged(_stackStace);
 
118
 
 
119
            if (Toolbar.SelectedDisplay == null)
 
120
                Toolbar.SelectedDisplay = display;
 
121
 
 
122
            return;
 
123
        }
 
124
 
 
125
        /// <summary>
 
126
        /// Removes all display from ErrorBrowser.
 
127
        /// </summary>
 
128
        public void ClearAll()
 
129
        {
 
130
            Toolbar.Clear();
 
131
 
 
132
            LayoutPanel.Option = null;
 
133
            LayoutPanel.Content = null;
 
134
 
 
135
            return;
 
136
        }
 
137
 
 
138
        void Toolbar_SelectedRendererChanged(object sender, EventArgs e)
 
139
        {
 
140
            LayoutPanel.Content = Toolbar.SelectedDisplay.Content;
 
141
 
 
142
            if (StackTraceDisplayChanged != null)
 
143
                StackTraceDisplayChanged(this, EventArgs.Empty);
 
144
 
 
145
            return;
 
146
        }
 
147
 
 
148
        protected ErrorPanelLayout LayoutPanel
 
149
        {
 
150
            get { return (_layout); }
 
151
        }
 
152
 
 
153
        protected ErrorToolbar Toolbar
 
154
        {
 
155
            get { return ((ErrorToolbar)_layout.Toolbar); }
 
156
        }
 
157
    }
 
158
}