Window.cs 3.1 KB

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