Window.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using System.Text.Json.Serialization;
  2. namespace Terminal.Gui;
  3. /// <summary>
  4. /// A <see cref="Toplevel"/> <see cref="View"/> with <see cref="View.BorderStyle"/> set to
  5. /// <see cref="LineStyle.Single"/>. Provides a container for other views.
  6. /// </summary>
  7. /// <remarks>
  8. /// <para>
  9. /// If any subview is a button and the <see cref="Button.IsDefault"/> property is set to true, the Enter key will
  10. /// invoke the <see cref="Command.Accept"/> command on that subview.
  11. /// </para>
  12. /// </remarks>
  13. public class Window : Toplevel
  14. {
  15. /// <summary>
  16. /// Gets or sets whether all <see cref="Window"/>s are shown with a shadow effect by default.
  17. /// </summary>
  18. [SerializableConfigurationProperty (Scope = typeof (ThemeScope))]
  19. public static ShadowStyle DefaultShadow { get; set; } = ShadowStyle.None;
  20. /// <summary>
  21. /// Initializes a new instance of the <see cref="Window"/> class.
  22. /// </summary>
  23. public Window ()
  24. {
  25. CanFocus = true;
  26. ColorScheme = Colors.ColorSchemes ["Base"]; // TODO: make this a theme property
  27. BorderStyle = DefaultBorderStyle;
  28. ShadowStyle = DefaultShadow;
  29. // This enables the default button to be activated by the Enter key.
  30. AddCommand (
  31. Command.Accept,
  32. () =>
  33. {
  34. // TODO: Perhaps all views should support the concept of being default?
  35. // ReSharper disable once InvertIf
  36. if (Subviews.FirstOrDefault (v => v is Button { IsDefault: true, Enabled: true }) is Button
  37. defaultBtn)
  38. {
  39. defaultBtn.InvokeCommand (Command.Accept);
  40. return true;
  41. }
  42. return OnAccept ();
  43. }
  44. );
  45. KeyBindings.Add (Key.Enter, Command.Accept);
  46. }
  47. // TODO: enable this
  48. ///// <summary>
  49. ///// The default <see cref="LineStyle"/> for <see cref="Window"/>'s border. The default is <see cref="LineStyle.Single"/>.
  50. ///// </summary>
  51. ///// <remarks>
  52. ///// This property can be set in a Theme to change the default <see cref="LineStyle"/> for all <see cref="Window"/>s.
  53. ///// </remarks>
  54. /////[SerializableConfigurationProperty (Scope = typeof (ThemeScope)), JsonConverter (typeof (JsonStringEnumConverter))]
  55. ////public static ColorScheme DefaultColorScheme { get; set; } = Colors.ColorSchemes ["Base"];
  56. /// <summary>
  57. /// The default <see cref="LineStyle"/> for <see cref="Window"/>'s border. The default is
  58. /// <see cref="LineStyle.Single"/>.
  59. /// </summary>
  60. /// <remarks>
  61. /// This property can be set in a Theme to change the default <see cref="LineStyle"/> for all <see cref="Window"/>
  62. /// s.
  63. /// </remarks>
  64. [SerializableConfigurationProperty (Scope = typeof (ThemeScope))]
  65. [JsonConverter (typeof (JsonStringEnumConverter<LineStyle>))]
  66. public static LineStyle DefaultBorderStyle { get; set; } = LineStyle.Single;
  67. }