You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.8 KiB

15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
  1. // Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy of this
  4. // software and associated documentation files (the "Software"), to deal in the Software
  5. // without restriction, including without limitation the rights to use, copy, modify, merge,
  6. // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
  7. // to whom the Software is furnished to do so, subject to the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be included in all copies or
  10. // substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  13. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  14. // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  15. // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  16. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  17. // DEALINGS IN THE SOFTWARE.
  18. using System;
  19. using System.Windows;
  20. using System.Windows.Controls;
  21. using System.Windows.Input;
  22. using System.Windows.Media;
  23. using ICSharpCode.AvalonEdit.Highlighting;
  24. using ICSharpCode.Decompiler;
  25. using ICSharpCode.ILSpy.Themes;
  26. namespace ICSharpCode.ILSpy
  27. {
  28. /// <summary>
  29. /// Adds additional WPF-specific output features to <see cref="ITextOutput"/>.
  30. /// </summary>
  31. public interface ISmartTextOutput : ITextOutput
  32. {
  33. /// <summary>
  34. /// Inserts an interactive UI element at the current position in the text output.
  35. /// </summary>
  36. void AddUIElement(Func<UIElement> element);
  37. void BeginSpan(HighlightingColor highlightingColor);
  38. void EndSpan();
  39. /// <summary>
  40. /// Gets/sets the title displayed in the document tab's header.
  41. /// </summary>
  42. string Title { get; set; }
  43. }
  44. public static class SmartTextOutputExtensions
  45. {
  46. /// <summary>
  47. /// Creates a button.
  48. /// </summary>
  49. public static void AddButton(this ISmartTextOutput output, ImageSource icon, string text, RoutedEventHandler click)
  50. {
  51. output.AddUIElement(
  52. delegate {
  53. Button button = ThemeManager.Current.CreateButton();
  54. button.Cursor = Cursors.Arrow;
  55. button.Margin = new Thickness(2);
  56. button.Padding = new Thickness(9, 1, 9, 1);
  57. button.MinWidth = 73;
  58. if (icon != null)
  59. {
  60. button.Content = new StackPanel {
  61. Orientation = Orientation.Horizontal,
  62. Children = {
  63. new Image { Width = 16, Height = 16, Source = icon, Margin = new Thickness(0, 0, 4, 0) },
  64. new TextBlock { Text = text }
  65. }
  66. };
  67. }
  68. else
  69. {
  70. button.Content = text;
  71. }
  72. button.Click += click;
  73. return button;
  74. });
  75. }
  76. }
  77. }