Window.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. /// Initializes a new instance of the <see cref="Window"/> class.
  17. /// </summary>
  18. public Window ()
  19. {
  20. CanFocus = true;
  21. ColorScheme = Colors.ColorSchemes ["Base"]; // TODO: make this a theme property
  22. BorderStyle = DefaultBorderStyle;
  23. // This enables the default button to be activated by the Enter key.
  24. AddCommand (
  25. Command.Accept,
  26. () =>
  27. {
  28. // TODO: Perhaps all views should support the concept of being default?
  29. // ReSharper disable once InvertIf
  30. if (Subviews.FirstOrDefault (v => v is Button { IsDefault: true, Enabled: true }) is Button
  31. defaultBtn)
  32. {
  33. defaultBtn.InvokeCommand (Command.Accept);
  34. return true;
  35. }
  36. return OnAccept ();
  37. }
  38. );
  39. KeyBindings.Add (Key.Enter, Command.Accept);
  40. }
  41. // TODO: enable this
  42. ///// <summary>
  43. ///// The default <see cref="LineStyle"/> for <see cref="Window"/>'s border. The default is <see cref="LineStyle.Single"/>.
  44. ///// </summary>
  45. ///// <remarks>
  46. ///// This property can be set in a Theme to change the default <see cref="LineStyle"/> for all <see cref="Window"/>s.
  47. ///// </remarks>
  48. /////[SerializableConfigurationProperty (Scope = typeof (ThemeScope)), JsonConverter (typeof (JsonStringEnumConverter))]
  49. ////public static ColorScheme DefaultColorScheme { get; set; } = Colors.ColorSchemes ["Base"];
  50. /// <summary>
  51. /// The default <see cref="LineStyle"/> for <see cref="Window"/>'s border. The default is
  52. /// <see cref="LineStyle.Single"/>.
  53. /// </summary>
  54. /// <remarks>
  55. /// This property can be set in a Theme to change the default <see cref="LineStyle"/> for all <see cref="Window"/>
  56. /// s.
  57. /// </remarks>
  58. [SerializableConfigurationProperty (Scope = typeof (ThemeScope))]
  59. [JsonConverter (typeof (JsonStringEnumConverter))]
  60. public static LineStyle DefaultBorderStyle { get; set; } = LineStyle.Single;
  61. }