PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/src/NUnit/UiException/Controls/StackTraceDisplay.cs

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