From 9a2a7a4685e22382de6e8791f3d2828e3e2ebabb Mon Sep 17 00:00:00 2001 From: Tig Date: Fri, 4 Apr 2025 09:50:12 -0600 Subject: [PATCH] Fixed a bunch of CM issues --- Terminal.Gui/Application/Application.Run.cs | 4 + Terminal.Gui/Resources/config.json | 526 ++++++++++---------- Terminal.Gui/View/View.Adornments.cs | 37 +- Terminal.Gui/Views/Bar.cs | 14 - Terminal.Gui/Views/Menu/MenuBarv2.cs | 31 ++ Terminal.Gui/Views/Menu/Menuv2.cs | 25 +- Terminal.Gui/Views/StatusBar.cs | 45 +- UICatalog/Scenario.cs | 2 - UICatalog/UICatalog.cs | 4 - UICatalog/UICatalogTop.cs | 13 +- 10 files changed, 358 insertions(+), 343 deletions(-) diff --git a/Terminal.Gui/Application/Application.Run.cs b/Terminal.Gui/Application/Application.Run.cs index f4a4cf44e..d1c7d9b79 100644 --- a/Terminal.Gui/Application/Application.Run.cs +++ b/Terminal.Gui/Application/Application.Run.cs @@ -193,6 +193,10 @@ public static partial class Application // Run (Begin, Run, End, Stop) toplevel.EndInit (); // Calls Layout } + // Call ConfigurationManager Apply here to ensure all subscribers to ConfigurationManager.Applied + // can update their state appropriately. + Apply (); + // Try to set initial focus to any TabStop if (!toplevel.HasFocus) { diff --git a/Terminal.Gui/Resources/config.json b/Terminal.Gui/Resources/config.json index 9d125c27b..a97d40c38 100644 --- a/Terminal.Gui/Resources/config.json +++ b/Terminal.Gui/Resources/config.json @@ -53,270 +53,272 @@ "MessageBox.DefaultBorderStyle": "Heavy", "Button.DefaultShadow": "Opaque", "Menuv2.DefaultBorderStyle": "Single", - "ColorSchemes": [ - { - "TopLevel": { - "Normal": { - "Foreground": "BrightGreen", - "Background": "#505050" // DarkerGray - }, - "Focus": { - "Foreground": "White", - "Background": "#696969" // DimGray - }, - "HotNormal": { - "Foreground": "Yellow", - "Background": "#505050" // DarkerGray - }, - "HotFocus": { - "Foreground": "Yellow", - "Background": "#696969" // DimGray - }, - "Disabled": { - "Foreground": "DarkGray", - "Background": "#505050" // DarkerGray - } - } - }, - { - "Base": { - "Normal": { - "Foreground": "White", - "Background": "Blue" - }, - "Focus": { - "Foreground": "DarkBlue", - "Background": "LightGray" - }, - "HotNormal": { - "Foreground": "BrightCyan", - "Background": "Blue" - }, - "HotFocus": { - "Foreground": "BrightBlue", - "Background": "LightGray" - }, - "Disabled": { - "Foreground": "DarkGray", - "Background": "Blue" - } - } - }, - { - "Dialog": { - "Normal": { - "Foreground": "Black", - "Background": "LightGray" - }, - "Focus": { - "Foreground": "DarkGray", - "Background": "LightGray" - }, - "HotNormal": { - "Foreground": "Blue", - "Background": "LightGray" - }, - "HotFocus": { - "Foreground": "BrightBlue", - "Background": "LightGray" - }, - "Disabled": { - "Foreground": "Gray", - "Background": "DarkGray" - } - } - }, - { - "Menu": { - "Normal": { - "Foreground": "White", - "Background": "DarkBlue" - }, - "Focus": { - "Foreground": "White", - "Background": "Blue" - }, - "HotNormal": { - "Foreground": "Yellow", - "Background": "DarkBlue" - }, - "HotFocus": { - "Foreground": "Yellow", - "Background": "Blue" - }, - "Disabled": { - "Foreground": "Gray", - "Background": "DarkGray" - } - } - }, - { - "Error": { - "Normal": { - "Foreground": "Red", - "Background": "Pink" - }, - "Focus": { - "Foreground": "White", - "Background": "BrightRed" - }, - "HotNormal": { - "Foreground": "Black", - "Background": "Pink" - }, - "HotFocus": { - "Foreground": "Pink", - "Background": "BrightRed" - }, - "Disabled": { - "Foreground": "DarkGray", - "Background": "White" - } + "MenuBarv2.DefaultBorderStyle": "None", + "StatusBar.DefaultSeparatorLineStyle": "Single", + "ColorSchemes": [ + { + "TopLevel": { + "Normal": { + "Foreground": "BrightGreen", + "Background": "#505050" // DarkerGray + }, + "Focus": { + "Foreground": "White", + "Background": "#696969" // DimGray + }, + "HotNormal": { + "Foreground": "Yellow", + "Background": "#505050" // DarkerGray + }, + "HotFocus": { + "Foreground": "Yellow", + "Background": "#696969" // DimGray + }, + "Disabled": { + "Foreground": "DarkGray", + "Background": "#505050" // DarkerGray } } - ], - "Glyphs.Apple": "\uD83C\uDF4E", - "Glyphs.AppleBMP": "❦", - "Glyphs.BlackCircle": "●", - "Glyphs.BlocksMeterSegment": "▌", - "Glyphs.BottomSideLineLtHv": "╽", - "Glyphs.BottomTee": "┴", - "Glyphs.BottomTeeDbl": "╩", - "Glyphs.BottomTeeDblH": "╧", - "Glyphs.BottomTeeDblV": "╨", - "Glyphs.BottomTeeHvDblH": "┻", - "Glyphs.BottomTeeHvH": "┷", - "Glyphs.BottomTeeHvV": "┸", - "Glyphs.CheckStateChecked": "☑", - "Glyphs.CheckStateNone": "☒", - "Glyphs.CheckStateUnChecked": "☐", - "Glyphs.Close": "✘", - "Glyphs.Collapse": "-", - "Glyphs.ContinuousMeterSegment": "█", - "Glyphs.Cross": "┼", - "Glyphs.CrossDbl": "╬", - "Glyphs.CrossDblH": "╪", - "Glyphs.CrossDblV": "╫", - "Glyphs.CrossHv": "╋", - "Glyphs.CrossHvH": "┿", - "Glyphs.CrossHvV": "╂", - "Glyphs.Diamond": "◊", - "Glyphs.Dot": "∙", - "Glyphs.DottedSquare": "⬚", - "Glyphs.DownArrow": "▼", - "Glyphs.Expand": "+", - "Glyphs.File": "☰", - "Glyphs.Folder": "꤉", - "Glyphs.HalfBottomLine": "╷", - "Glyphs.HalfBottomLineLt": "╻", - "Glyphs.HalfLeftLine": "╴", - "Glyphs.HalfLeftLineHv": "╸", - "Glyphs.HalfRightLine": "╶", - "Glyphs.HalfRightLineHv": "╺", - "Glyphs.HalfTopLine": "╵", - "Glyphs.HalfTopLineHv": "╹", - "Glyphs.HLine": "─", - "Glyphs.HLineDa2": "╌", - "Glyphs.HLineDa3": "┄", - "Glyphs.HLineDa4": "┈", - "Glyphs.HLineDbl": "═", - "Glyphs.HLineHv": "━", - "Glyphs.HLineHvDa2": "╍", - "Glyphs.HLineHvDa3": "┅", - "Glyphs.HLineHvDa4": "┉", - "Glyphs.HorizontalEllipsis": "…", - "Glyphs.IdenticalTo": "≡", - "Glyphs.LeftArrow": "◄", - "Glyphs.LeftBracket": "⟦", - "Glyphs.LeftDefaultIndicator": "►", - "Glyphs.LeftSideLineHvLt": "╾", - "Glyphs.LeftTee": "├", - "Glyphs.LeftTeeDbl": "╠", - "Glyphs.LeftTeeDblH": "╞", - "Glyphs.LeftTeeDblV": "╟", - "Glyphs.LeftTeeHvDblH": "┣", - "Glyphs.LeftTeeHvH": "┝", - "Glyphs.LeftTeeHvV": "┠", - "Glyphs.LLCorner": "└", - "Glyphs.LLCornerDbl": "╚", - "Glyphs.LLCornerDblSingle": "╙", - "Glyphs.LLCornerHv": "┗", - "Glyphs.LLCornerHvLt": "┖", - "Glyphs.LLCornerLtHv": "┕", - "Glyphs.LLCornerR": "╰", - "Glyphs.LLCornerSingleDbl": "╘", - "Glyphs.LRCorner": "┘", - "Glyphs.LRCornerDbl": "╝", - "Glyphs.LRCornerDblSingle": "╜", - "Glyphs.LRCornerHv": "┛", - "Glyphs.LRCornerHvLt": "┚", - "Glyphs.LRCornerLtHv": "┙", - "Glyphs.LRCornerR": "╯", - "Glyphs.LRCornerSingleDbl": "╛", - "Glyphs.Maximize": "✽", - "Glyphs.Minimize": "❏", - "Glyphs.Move": "◊", - "Glyphs.RightArrow": "►", - "Glyphs.RightBracket": "⟧", - "Glyphs.RightDefaultIndicator": "◄", - "Glyphs.RightSideLineLtHv": "╼", - "Glyphs.RightTee": "┤", - "Glyphs.RightTeeDbl": "╣", - "Glyphs.RightTeeDblH": "╡", - "Glyphs.RightTeeDblV": "╢", - "Glyphs.RightTeeHvDblH": "┫", - "Glyphs.RightTeeHvH": "┥", - "Glyphs.RightTeeHvV": "┨", - "Glyphs.Selected": "◉", - "Glyphs.ShadowHorizontal": "▀", - "Glyphs.ShadowHorizontalEnd": "▘", - "Glyphs.ShadowHorizontalStart": "▝", - "Glyphs.ShadowVertical": "▌", - "Glyphs.ShadowVerticalStart": "▖", - "Glyphs.SizeBottomLeft": "↙", - "Glyphs.SizeBottomRight": "↘", - "Glyphs.SizeHorizontal": "↔", - "Glyphs.SizeTopLeft": "↖", - "Glyphs.SizeTopRight": "↗", - "Glyphs.SizeVertical": "↕", - "Glyphs.Stipple": "░", - "Glyphs.TopSideLineHvLt": "╿", - "Glyphs.TopTee": "┬", - "Glyphs.TopTeeDbl": "╦", - "Glyphs.TopTeeDblH": "╤", - "Glyphs.TopTeeDblV": "╥", - "Glyphs.TopTeeHvDblH": "┳", - "Glyphs.TopTeeHvH": "┯", - "Glyphs.TopTeeHvV": "┰", - "Glyphs.ULCorner": "┌", - "Glyphs.ULCornerDbl": "╔", - "Glyphs.ULCornerDblSingle": "╓", - "Glyphs.ULCornerHv": "┏", - "Glyphs.ULCornerHvLt": "┎", - "Glyphs.ULCornerLtHv": "┍", - "Glyphs.ULCornerR": "╭", - "Glyphs.ULCornerSingleDbl": "╒", - "Glyphs.UnSelected": "○", - "Glyphs.UpArrow": "▲", - "Glyphs.URCorner": "┐", - "Glyphs.URCornerDbl": "╗", - "Glyphs.URCornerDblSingle": "╖", - "Glyphs.URCornerHv": "┓", - "Glyphs.URCornerHvLt": "┑", - "Glyphs.URCornerLtHv": "┒", - "Glyphs.URCornerR": "╮", - "Glyphs.URCornerSingleDbl": "╕", - "Glyphs.VerticalFourDots": "⁞", - "Glyphs.VLine": "│", - "Glyphs.VLineDa2": "╎", - "Glyphs.VLineDa3": "┆", - "Glyphs.VLineDa4": "┊", - "Glyphs.VLineDbl": "║", - "Glyphs.VLineHv": "┃", - "Glyphs.VLineHvDa2": "╏", - "Glyphs.VLineHvDa3": "┇", - "Glyphs.VLineHvDa4": "┋" - } + }, + { + "Base": { + "Normal": { + "Foreground": "White", + "Background": "Blue" + }, + "Focus": { + "Foreground": "DarkBlue", + "Background": "LightGray" + }, + "HotNormal": { + "Foreground": "BrightCyan", + "Background": "Blue" + }, + "HotFocus": { + "Foreground": "BrightBlue", + "Background": "LightGray" + }, + "Disabled": { + "Foreground": "DarkGray", + "Background": "Blue" + } + } + }, + { + "Dialog": { + "Normal": { + "Foreground": "Black", + "Background": "LightGray" + }, + "Focus": { + "Foreground": "DarkGray", + "Background": "LightGray" + }, + "HotNormal": { + "Foreground": "Blue", + "Background": "LightGray" + }, + "HotFocus": { + "Foreground": "BrightBlue", + "Background": "LightGray" + }, + "Disabled": { + "Foreground": "Gray", + "Background": "DarkGray" + } + } + }, + { + "Menu": { + "Normal": { + "Foreground": "White", + "Background": "DarkBlue" + }, + "Focus": { + "Foreground": "White", + "Background": "Blue" + }, + "HotNormal": { + "Foreground": "Yellow", + "Background": "DarkBlue" + }, + "HotFocus": { + "Foreground": "Yellow", + "Background": "Blue" + }, + "Disabled": { + "Foreground": "Gray", + "Background": "DarkGray" + } + } + }, + { + "Error": { + "Normal": { + "Foreground": "Red", + "Background": "Pink" + }, + "Focus": { + "Foreground": "White", + "Background": "BrightRed" + }, + "HotNormal": { + "Foreground": "Black", + "Background": "Pink" + }, + "HotFocus": { + "Foreground": "Pink", + "Background": "BrightRed" + }, + "Disabled": { + "Foreground": "DarkGray", + "Background": "White" + } + } + } + ], + "Glyphs.Apple": "\uD83C\uDF4E", + "Glyphs.AppleBMP": "❦", + "Glyphs.BlackCircle": "●", + "Glyphs.BlocksMeterSegment": "▌", + "Glyphs.BottomSideLineLtHv": "╽", + "Glyphs.BottomTee": "┴", + "Glyphs.BottomTeeDbl": "╩", + "Glyphs.BottomTeeDblH": "╧", + "Glyphs.BottomTeeDblV": "╨", + "Glyphs.BottomTeeHvDblH": "┻", + "Glyphs.BottomTeeHvH": "┷", + "Glyphs.BottomTeeHvV": "┸", + "Glyphs.CheckStateChecked": "☑", + "Glyphs.CheckStateNone": "☒", + "Glyphs.CheckStateUnChecked": "☐", + "Glyphs.Close": "✘", + "Glyphs.Collapse": "-", + "Glyphs.ContinuousMeterSegment": "█", + "Glyphs.Cross": "┼", + "Glyphs.CrossDbl": "╬", + "Glyphs.CrossDblH": "╪", + "Glyphs.CrossDblV": "╫", + "Glyphs.CrossHv": "╋", + "Glyphs.CrossHvH": "┿", + "Glyphs.CrossHvV": "╂", + "Glyphs.Diamond": "◊", + "Glyphs.Dot": "∙", + "Glyphs.DottedSquare": "⬚", + "Glyphs.DownArrow": "▼", + "Glyphs.Expand": "+", + "Glyphs.File": "☰", + "Glyphs.Folder": "꤉", + "Glyphs.HalfBottomLine": "╷", + "Glyphs.HalfBottomLineLt": "╻", + "Glyphs.HalfLeftLine": "╴", + "Glyphs.HalfLeftLineHv": "╸", + "Glyphs.HalfRightLine": "╶", + "Glyphs.HalfRightLineHv": "╺", + "Glyphs.HalfTopLine": "╵", + "Glyphs.HalfTopLineHv": "╹", + "Glyphs.HLine": "─", + "Glyphs.HLineDa2": "╌", + "Glyphs.HLineDa3": "┄", + "Glyphs.HLineDa4": "┈", + "Glyphs.HLineDbl": "═", + "Glyphs.HLineHv": "━", + "Glyphs.HLineHvDa2": "╍", + "Glyphs.HLineHvDa3": "┅", + "Glyphs.HLineHvDa4": "┉", + "Glyphs.HorizontalEllipsis": "…", + "Glyphs.IdenticalTo": "≡", + "Glyphs.LeftArrow": "◄", + "Glyphs.LeftBracket": "⟦", + "Glyphs.LeftDefaultIndicator": "►", + "Glyphs.LeftSideLineHvLt": "╾", + "Glyphs.LeftTee": "├", + "Glyphs.LeftTeeDbl": "╠", + "Glyphs.LeftTeeDblH": "╞", + "Glyphs.LeftTeeDblV": "╟", + "Glyphs.LeftTeeHvDblH": "┣", + "Glyphs.LeftTeeHvH": "┝", + "Glyphs.LeftTeeHvV": "┠", + "Glyphs.LLCorner": "└", + "Glyphs.LLCornerDbl": "╚", + "Glyphs.LLCornerDblSingle": "╙", + "Glyphs.LLCornerHv": "┗", + "Glyphs.LLCornerHvLt": "┖", + "Glyphs.LLCornerLtHv": "┕", + "Glyphs.LLCornerR": "╰", + "Glyphs.LLCornerSingleDbl": "╘", + "Glyphs.LRCorner": "┘", + "Glyphs.LRCornerDbl": "╝", + "Glyphs.LRCornerDblSingle": "╜", + "Glyphs.LRCornerHv": "┛", + "Glyphs.LRCornerHvLt": "┚", + "Glyphs.LRCornerLtHv": "┙", + "Glyphs.LRCornerR": "╯", + "Glyphs.LRCornerSingleDbl": "╛", + "Glyphs.Maximize": "✽", + "Glyphs.Minimize": "❏", + "Glyphs.Move": "◊", + "Glyphs.RightArrow": "►", + "Glyphs.RightBracket": "⟧", + "Glyphs.RightDefaultIndicator": "◄", + "Glyphs.RightSideLineLtHv": "╼", + "Glyphs.RightTee": "┤", + "Glyphs.RightTeeDbl": "╣", + "Glyphs.RightTeeDblH": "╡", + "Glyphs.RightTeeDblV": "╢", + "Glyphs.RightTeeHvDblH": "┫", + "Glyphs.RightTeeHvH": "┥", + "Glyphs.RightTeeHvV": "┨", + "Glyphs.Selected": "◉", + "Glyphs.ShadowHorizontal": "▀", + "Glyphs.ShadowHorizontalEnd": "▘", + "Glyphs.ShadowHorizontalStart": "▝", + "Glyphs.ShadowVertical": "▌", + "Glyphs.ShadowVerticalStart": "▖", + "Glyphs.SizeBottomLeft": "↙", + "Glyphs.SizeBottomRight": "↘", + "Glyphs.SizeHorizontal": "↔", + "Glyphs.SizeTopLeft": "↖", + "Glyphs.SizeTopRight": "↗", + "Glyphs.SizeVertical": "↕", + "Glyphs.Stipple": "░", + "Glyphs.TopSideLineHvLt": "╿", + "Glyphs.TopTee": "┬", + "Glyphs.TopTeeDbl": "╦", + "Glyphs.TopTeeDblH": "╤", + "Glyphs.TopTeeDblV": "╥", + "Glyphs.TopTeeHvDblH": "┳", + "Glyphs.TopTeeHvH": "┯", + "Glyphs.TopTeeHvV": "┰", + "Glyphs.ULCorner": "┌", + "Glyphs.ULCornerDbl": "╔", + "Glyphs.ULCornerDblSingle": "╓", + "Glyphs.ULCornerHv": "┏", + "Glyphs.ULCornerHvLt": "┎", + "Glyphs.ULCornerLtHv": "┍", + "Glyphs.ULCornerR": "╭", + "Glyphs.ULCornerSingleDbl": "╒", + "Glyphs.UnSelected": "○", + "Glyphs.UpArrow": "▲", + "Glyphs.URCorner": "┐", + "Glyphs.URCornerDbl": "╗", + "Glyphs.URCornerDblSingle": "╖", + "Glyphs.URCornerHv": "┓", + "Glyphs.URCornerHvLt": "┑", + "Glyphs.URCornerLtHv": "┒", + "Glyphs.URCornerR": "╮", + "Glyphs.URCornerSingleDbl": "╕", + "Glyphs.VerticalFourDots": "⁞", + "Glyphs.VLine": "│", + "Glyphs.VLineDa2": "╎", + "Glyphs.VLineDa3": "┆", + "Glyphs.VLineDa4": "┊", + "Glyphs.VLineDbl": "║", + "Glyphs.VLineHv": "┃", + "Glyphs.VLineHvDa2": "╏", + "Glyphs.VLineHvDa3": "┇", + "Glyphs.VLineHvDa4": "┋" + } }, { "Dark": { diff --git a/Terminal.Gui/View/View.Adornments.cs b/Terminal.Gui/View/View.Adornments.cs index c9c874cc1..126745955 100644 --- a/Terminal.Gui/View/View.Adornments.cs +++ b/Terminal.Gui/View/View.Adornments.cs @@ -148,45 +148,12 @@ public partial class View // Adornments return; } - LineStyle old = Border?.LineStyle ?? LineStyle.None; - - // It's tempting to try to optimize this by checking that old != value and returning. - // Do not. - - CancelEventArgs e = new (ref old, ref value); - - if (OnBorderStyleChanging (e) || e.Cancel) - { - return; - } - - BorderStyleChanging?.Invoke (this, e); - - if (e.Cancel) - { - return; - } - - SetBorderStyle (e.NewValue); + SetBorderStyle (value); OnBorderStyleChanged (); BorderStyleChanged?.Invoke(this, EventArgs.Empty); } } - - /// - /// Called when the is changing. - /// - /// - /// Set e.Cancel to true to prevent the from changing. - /// - /// - protected virtual bool OnBorderStyleChanging (CancelEventArgs e) { return false; } - - /// - /// Fired when the is changing. Allows the event to be cancelled. - /// - public event EventHandler>? BorderStyleChanging; - + /// /// Called when the has changed. /// diff --git a/Terminal.Gui/Views/Bar.cs b/Terminal.Gui/Views/Bar.cs index 20929b79d..246d9faa6 100644 --- a/Terminal.Gui/Views/Bar.cs +++ b/Terminal.Gui/Views/Bar.cs @@ -74,20 +74,6 @@ public class Bar : View, IOrientation, IDesignable } } - /// - protected override bool OnBorderStyleChanging (CancelEventArgs e) - { - if (Border is { }) - { - // The default changes the thickness. We don't want that. We just set the style. - Border.LineStyle = e.NewValue; - - return true; // Cancel - } - - return base.OnBorderStyleChanging (e); - } - #region IOrientation members /// diff --git a/Terminal.Gui/Views/Menu/MenuBarv2.cs b/Terminal.Gui/Views/Menu/MenuBarv2.cs index 90e0ab9d4..d40fd949c 100644 --- a/Terminal.Gui/Views/Menu/MenuBarv2.cs +++ b/Terminal.Gui/Views/Menu/MenuBarv2.cs @@ -23,6 +23,7 @@ public class MenuBarv2 : Menuv2, IDesignable TabStop = TabBehavior.TabGroup; Y = 0; Width = Dim.Fill (); + Height = Dim.Auto (); Orientation = Orientation.Horizontal; Key = DefaultKey; @@ -82,6 +83,10 @@ public class MenuBarv2 : Menuv2, IDesignable AddCommand (Command.Left, MoveLeft); KeyBindings.Add (Key.CursorLeft, Command.Left); + BorderStyle = DefaultBorderStyle; + + Applied += OnConfigurationManagerApplied; + return; bool? MoveLeft (ICommandContext? ctx) { return AdvanceFocus (NavigationDirection.Backward, TabBehavior.TabStop); } @@ -89,6 +94,24 @@ public class MenuBarv2 : Menuv2, IDesignable bool? MoveRight (ICommandContext? ctx) { return AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop); } } + private void OnConfigurationManagerApplied (object? sender, ConfigurationManagerEventArgs e) + { + BorderStyle = DefaultBorderStyle; + } + + /// + protected override bool OnBorderStyleChanged () + { + HideActiveItem (); + return base.OnBorderStyleChanged (); + } + + /// + /// Gets or sets the default Border Style for the MenuBar. The default is . + /// + [SerializableConfigurationProperty (Scope = typeof (ThemeScope))] + public new static LineStyle DefaultBorderStyle { get; set; } = LineStyle.None; + private Key _key = DefaultKey; /// Specifies the key that will activate the context menu. @@ -427,4 +450,12 @@ public class MenuBarv2 : Menuv2, IDesignable } } } + + /// + protected override void Dispose (bool disposing) + { + base.Dispose (disposing); + + Applied -= OnConfigurationManagerApplied; + } } diff --git a/Terminal.Gui/Views/Menu/Menuv2.cs b/Terminal.Gui/Views/Menu/Menuv2.cs index 75e532019..0782b1ce6 100644 --- a/Terminal.Gui/Views/Menu/Menuv2.cs +++ b/Terminal.Gui/Views/Menu/Menuv2.cs @@ -21,23 +21,21 @@ public class Menuv2 : Bar base.ColorScheme = Colors.ColorSchemes ["Menu"]; BorderStyle = DefaultBorderStyle; + + Applied += OnConfigurationManagerApplied; + } + + private void OnConfigurationManagerApplied (object? sender, ConfigurationManagerEventArgs e) + { + BorderStyle = DefaultBorderStyle; } - // BUGBUG: For some reason this config property is not working! /// - /// Gets or sets the default Highlight Style. + /// Gets or sets the default Border Style for Menus. The default is . /// [SerializableConfigurationProperty (Scope = typeof (ThemeScope))] public static LineStyle DefaultBorderStyle { get; set; } = LineStyle.Single; - /// - protected override bool OnBorderStyleChanging (CancelEventArgs e) - { - // Bar (our base) overrides this to prevent automatic changing of thickness. - // We don't want that so we override as well. - return false; - } - /// /// Gets or sets the menu item that opened this menu as a sub-menu. /// @@ -182,4 +180,11 @@ public class Menuv2 : Bar /// public event EventHandler? SelectedMenuItemChanged; + /// + protected override void Dispose (bool disposing) + { + base.Dispose (disposing); + + Applied -= OnConfigurationManagerApplied; + } } \ No newline at end of file diff --git a/Terminal.Gui/Views/StatusBar.cs b/Terminal.Gui/Views/StatusBar.cs index 3baf415e1..b209f6d1a 100644 --- a/Terminal.Gui/Views/StatusBar.cs +++ b/Terminal.Gui/Views/StatusBar.cs @@ -23,16 +23,33 @@ public class StatusBar : Bar, IDesignable Y = Pos.AnchorEnd (); Width = Dim.Fill (); Height = Dim.Auto (DimAutoStyle.Content, 1); - BorderStyle = LineStyle.Dashed; + + if (Border is { }) + { + Border.LineStyle = DefaultSeparatorLineStyle; + } + base.ColorScheme = Colors.ColorSchemes ["Menu"]; - SubViewLayout += StatusBar_LayoutStarted; + Applied += OnConfigurationManagerApplied; } - // StatusBar arranges the items horizontally. - // The first item has no left border, the last item has no right border. - // The Shortcuts are configured with the command, help, and key views aligned in reverse order (EndToStart). - private void StatusBar_LayoutStarted (object sender, LayoutEventArgs e) + private void OnConfigurationManagerApplied (object? sender, ConfigurationManagerEventArgs e) + { + if (Border is { }) + { + Border.LineStyle = DefaultSeparatorLineStyle; + } + } + + /// + /// Gets or sets the default Line Style for the separators between the shortcuts of the StatusBar. + /// + [SerializableConfigurationProperty (Scope = typeof (ThemeScope))] + public static LineStyle DefaultSeparatorLineStyle { get; set; } = LineStyle.Dashed; + + /// + protected override void OnSubViewLayout (LayoutEventArgs args) { for (int index = 0; index < SubViews.Count; index++) { @@ -40,13 +57,9 @@ public class StatusBar : Bar, IDesignable barItem.BorderStyle = BorderStyle; - if (index == SubViews.Count - 1) + if (barItem.Border is { }) { - barItem.Border.Thickness = new Thickness (0, 0, 0, 0); - } - else - { - barItem.Border.Thickness = new Thickness (0, 0, 1, 0); + barItem.Border.Thickness = index == SubViews.Count - 1 ? new Thickness (0, 0, 0, 0) : new Thickness (0, 0, 1, 0); } if (barItem is Shortcut shortcut) @@ -54,6 +67,7 @@ public class StatusBar : Bar, IDesignable shortcut.Orientation = Orientation.Horizontal; } } + base.OnSubViewLayout (args); } /// @@ -138,4 +152,11 @@ public class StatusBar : Bar, IDesignable void Button_Clicked (object sender, EventArgs e) { MessageBox.Query ("Hi", $"You clicked {sender}"); } } + /// + protected override void Dispose (bool disposing) + { + base.Dispose (disposing); + + Applied -= OnConfigurationManagerApplied; + } } diff --git a/UICatalog/Scenario.cs b/UICatalog/Scenario.cs index cb25d9734..5cef80218 100644 --- a/UICatalog/Scenario.cs +++ b/UICatalog/Scenario.cs @@ -84,8 +84,6 @@ namespace UICatalog; public class Scenario : IDisposable { private static int _maxScenarioNameLen = 30; - public string TopLevelColorScheme { get; set; } = "Base"; - public BenchmarkResults BenchmarkResults { get { return _benchmarkResults; } diff --git a/UICatalog/UICatalog.cs b/UICatalog/UICatalog.cs index 4006bd980..a57346164 100644 --- a/UICatalog/UICatalog.cs +++ b/UICatalog/UICatalog.cs @@ -360,9 +360,6 @@ public class UICatalog while (RunUICatalogTopLevel () is { } scenario) { VerifyObjectsWereDisposed (); - Themes!.Theme = UICatalogTop.CachedTheme!; - Apply (); - scenario.TopLevelColorScheme = UICatalogTop.CachedTopLevelColorScheme!; #if DEBUG_IDISPOSABLE View.DebugIDisposable = true; @@ -412,7 +409,6 @@ public class UICatalog } Application.Init (driverName: _forceDriver); - scenario.TopLevelColorScheme = UICatalogTop.CachedTopLevelColorScheme!; if (benchmark) { diff --git a/UICatalog/UICatalogTop.cs b/UICatalog/UICatalogTop.cs index a8c19b18b..233fb4a1e 100644 --- a/UICatalog/UICatalogTop.cs +++ b/UICatalog/UICatalogTop.cs @@ -27,6 +27,9 @@ public class UICatalogTop : Toplevel // Theme Management public static string? CachedTheme { get; set; } + // Note, we used to pass this to scenarios that run, but it just added complexity + // So that was removed. But we still have this here to demonstrate how changing + // the scheme works. public static string? CachedTopLevelColorScheme { get; set; } // Diagnostics @@ -58,8 +61,6 @@ public class UICatalogTop : Toplevel private void LoadedHandler (object? sender, EventArgs? args) { - ConfigChanged (); - if (_disableMouseCb is { }) { _disableMouseCb.CheckedState = Application.IsMouseDisabled ? CheckState.Checked : CheckState.UnChecked; @@ -648,7 +649,11 @@ public class UICatalogTop : Toplevel #endregion StatusBar #region Configuration Manager - public void ConfigChanged () + + /// + /// Called when CM has applied changes. + /// + private void ConfigApplied () { CachedTheme = Themes?.Theme; @@ -672,7 +677,7 @@ public class UICatalogTop : Toplevel Application.Top?.SetNeedsDraw (); } - private void ConfigAppliedHandler (object? sender, ConfigurationManagerEventArgs? a) { ConfigChanged (); } + private void ConfigAppliedHandler (object? sender, ConfigurationManagerEventArgs? a) { ConfigApplied (); } #endregion Configuration Manager