/src/NUnit/UiException/Controls/StackTraceDisplay.cs
C# | 94 lines | 64 code | 17 blank | 13 comment | 1 complexity | bbd68404b4d00a796e45698a7e68aee0 MD5 | raw file
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 6using System; 7using System.Collections.Generic; 8using System.Text; 9using System.Windows.Forms; 10using System.Drawing; 11using NUnit.UiException.Properties; 12 13namespace NUnit.UiException.Controls 14{ 15 /// <summary> 16 /// Implements IErrorDisplay to show the actual stack trace in a TextBox control. 17 /// </summary> 18 public class StackTraceDisplay : 19 UserControl, 20 IErrorDisplay 21 { 22 private TextBox _textContent; 23 private ToolStripButton _btnPlugin; 24 private ToolStripButton _btnCopy; 25 26 /// <summary> 27 /// Builds a new instance of StackTraceDisplay. 28 /// </summary> 29 public StackTraceDisplay() 30 { 31 _btnPlugin = ErrorToolbar.NewStripButton(true, "Display actual stack trace", Resources.ImageStackTraceDisplay, null); 32 _btnCopy = ErrorToolbar.NewStripButton(false, "Copy stack trace to clipboard", Resources.ImageCopyToClipboard, OnClick); 33 34 _textContent = new TextBox(); 35 _textContent.ReadOnly = true; 36 _textContent.Multiline = true; 37 _textContent.ScrollBars = ScrollBars.Both; 38 39 return; 40 } 41 42 protected override void OnFontChanged(EventArgs e) 43 { 44 _textContent.Font = this.Font; 45 46 base.OnFontChanged(e); 47 } 48 49 /// <summary> 50 /// Copies the actual stack trace to the clipboard. 51 /// </summary> 52 public void CopyToClipBoard() 53 { 54 if (String.IsNullOrEmpty(_textContent.Text)) 55 { 56 Clipboard.Clear(); 57 return; 58 } 59 60 Clipboard.SetText(_textContent.Text); 61 62 return; 63 } 64 65 #region IErrorDisplay Membres 66 67 public ToolStripButton PluginItem 68 { 69 get { return (_btnPlugin); } 70 } 71 72 public ToolStripItem[] OptionItems 73 { 74 get { return (new ToolStripItem[] { _btnCopy }); } 75 } 76 77 public Control Content 78 { 79 get { return (_textContent); } 80 } 81 82 public void OnStackTraceChanged(string stackTrace) 83 { 84 _textContent.Text = stackTrace; 85 } 86 87 #endregion 88 89 private void OnClick(object sender, EventArgs args) 90 { 91 CopyToClipBoard(); 92 } 93 } 94}