using System.Linq; using System.Text.Json.Serialization; namespace Terminal.Gui; /// /// A with set to /// . Provides a container for other views. /// /// /// /// If any subview is a button and the property is set to true, the Enter key /// will invoke the command on that subview. /// /// public class Window : Toplevel { /// /// Initializes a new instance of the class using /// positioning. /// public Window () => SetInitialProperties (); /// /// Initializes a new instance of the class using /// positioning. /// public Window (Rect frame) : base (frame) => SetInitialProperties (); // TODO: enable this ///// ///// The default for 's border. The default is . ///// ///// ///// This property can be set in a Theme to change the default for all s. ///// /////[SerializableConfigurationProperty (Scope = typeof (ThemeScope)), JsonConverter (typeof (JsonStringEnumConverter))] ////public static ColorScheme DefaultColorScheme { get; set; } = Colors.Base; /// /// The default for 's border. The default is /// . /// /// /// This property can be set in a Theme to change the default for all /// s. /// [SerializableConfigurationProperty (Scope = typeof (ThemeScope))] [JsonConverter (typeof (JsonStringEnumConverter))] public static LineStyle DefaultBorderStyle { get; set; } = LineStyle.Single; void SetInitialProperties () { CanFocus = true; ColorScheme = Colors.Base; // TODO: make this a theme property BorderStyle = DefaultBorderStyle; // This enables the default button to be activated by the Enter key. AddCommand (Command.Accept, () => { // TODO: Perhaps all views should support the concept of being default? if (Subviews.FirstOrDefault (v => v is Button { IsDefault: true, Enabled: true }) is Button defaultBtn) { defaultBtn.InvokeCommand (Command.Accept); return true; } return false; }); KeyBindings.Add (Key.Enter, Command.Accept); } }