From ae46bba182f320cc089dbc588945eeed36537b0c Mon Sep 17 00:00:00 2001 From: Tig Date: Sun, 4 Aug 2024 12:01:35 -0600 Subject: [PATCH 1/4] MessageBox now centered by default. Dialog & MB now Thick linestyle by default. --- Terminal.Gui/Resources/config.json | 5 +++-- Terminal.Gui/Views/Dialog.cs | 6 +++--- Terminal.Gui/Views/MessageBox.cs | 12 +++++++++--- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Terminal.Gui/Resources/config.json b/Terminal.Gui/Resources/config.json index e3c1ac3dd..e4806af9b 100644 --- a/Terminal.Gui/Resources/config.json +++ b/Terminal.Gui/Resources/config.json @@ -29,8 +29,9 @@ "Dialog.DefaultButtonAlignmentModes": "AddSpaceBetweenItems", "FrameView.DefaultBorderStyle": "Single", "Window.DefaultBorderStyle": "Single", - "Dialog.DefaultBorderStyle": "Single", - "MessageBox.DefaultBorderStyle": "Double", + "Dialog.DefaultBorderStyle": "Heavy", + "MessageBox.DefaultButtonAlignment": "Center", + "MessageBox.DefaultBorderStyle": "Heavy", "Button.DefaultShadow": "None", "ColorSchemes": [ { diff --git a/Terminal.Gui/Views/Dialog.cs b/Terminal.Gui/Views/Dialog.cs index 7b4da9355..c1f18e8fb 100644 --- a/Terminal.Gui/Views/Dialog.cs +++ b/Terminal.Gui/Views/Dialog.cs @@ -20,7 +20,7 @@ public class Dialog : Window /// This property can be set in a Theme. [SerializableConfigurationProperty (Scope = typeof (ThemeScope))] [JsonConverter (typeof (JsonStringEnumConverter))] - public static Alignment DefaultButtonAlignment { get; set; } = Alignment.End; + public static Alignment DefaultButtonAlignment { get; set; } = Alignment.End; // Default is set in config.json /// The default for . /// This property can be set in a Theme. @@ -48,7 +48,7 @@ public class Dialog : Window /// [SerializableConfigurationProperty (Scope = typeof (ThemeScope))] [JsonConverter (typeof (JsonStringEnumConverter))] - public new static ShadowStyle DefaultShadow { get; set; } = ShadowStyle.None; + public new static ShadowStyle DefaultShadow { get; set; } = ShadowStyle.None; // Default is set in config.json /// /// Defines the default border styling for . Can be configured via @@ -57,7 +57,7 @@ public class Dialog : Window [SerializableConfigurationProperty (Scope = typeof (ThemeScope))] [JsonConverter (typeof (JsonStringEnumConverter))] - public new static LineStyle DefaultBorderStyle { get; set; } = LineStyle.Single; + public new static LineStyle DefaultBorderStyle { get; set; } = LineStyle.Single; // Default is set in config.json private readonly List [SerializableConfigurationProperty (Scope = typeof (ThemeScope))] [JsonConverter (typeof (JsonStringEnumConverter))] - public static LineStyle DefaultBorderStyle { get; set; } = LineStyle.Single; + public static LineStyle DefaultBorderStyle { get; set; } = LineStyle.Single; // Default is set in config.json + + /// The default for . + /// This property can be set in a Theme. + [SerializableConfigurationProperty (Scope = typeof (ThemeScope))] + [JsonConverter (typeof (JsonStringEnumConverter))] + public static Alignment DefaultButtonAlignment { get; set; } = Alignment.Center; // Default is set in config.json /// /// Defines the default minimum MessageBox width, as a percentage of the screen width. Can be configured via @@ -365,10 +371,10 @@ public static class MessageBox var d = new Dialog { Title = title, - Buttons = buttonList.ToArray (), - ButtonAlignment = Alignment.Center, + ButtonAlignment = MessageBox.DefaultButtonAlignment, ButtonAlignmentModes = AlignmentModes.StartToEnd | AlignmentModes.AddSpaceBetweenItems, BorderStyle = MessageBox.DefaultBorderStyle, + Buttons = buttonList.ToArray (), }; d.Width = Dim.Auto (DimAutoStyle.Auto, From 271a73cba1db6fa669c3bcc9a5130503bcc219dd Mon Sep 17 00:00:00 2001 From: Tig Date: Sun, 4 Aug 2024 12:14:13 -0600 Subject: [PATCH 2/4] Made unit tests more resiliant to config changes --- UnitTests/Dialogs/DialogTests.cs | 31 +++++++++++++++++++++++++++- UnitTests/Dialogs/MessageBoxTests.cs | 12 +++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/UnitTests/Dialogs/DialogTests.cs b/UnitTests/Dialogs/DialogTests.cs index d07b627ee..582cf659a 100644 --- a/UnitTests/Dialogs/DialogTests.cs +++ b/UnitTests/Dialogs/DialogTests.cs @@ -26,6 +26,10 @@ public class DialogTests int width = $@"{CM.Glyphs.VLine} {btn1} {btn2} {CM.Glyphs.VLine}".Length; d.SetBufferSize (width, 1); + // Override CM + Dialog.DefaultButtonAlignment = Alignment.Center; + Dialog.DefaultBorderStyle = LineStyle.Single; + // Default (center) var dlg = new Dialog { @@ -151,6 +155,7 @@ public class DialogTests int width = buttonRow.Length; d.SetBufferSize (buttonRow.Length, 3); + // Default - Center (runstate, Dialog dlg) = RunButtonTestDialog ( title, @@ -874,6 +879,11 @@ public class DialogTests { ((FakeDriver)Driver).SetBufferSize (20, 5); + // Override CM + Window.DefaultBorderStyle = LineStyle.Single; + Dialog.DefaultButtonAlignment = Alignment.Center; + Dialog.DefaultBorderStyle = LineStyle.Single; + var win = new Window (); var iterations = 0; @@ -889,7 +899,6 @@ public class DialogTests win.Loaded += (s, a) => { - Dialog.DefaultButtonAlignment = Alignment.Center; var dlg = new Dialog { Width = 18, Height = 3, Buttons = [new () { Text = "Ok" }] }; dlg.Loaded += (s, a) => @@ -975,7 +984,10 @@ public class DialogTests var win = new Window (); int iterations = -1; + + // Override CM Dialog.DefaultButtonAlignment = Alignment.Center; + Dialog.DefaultBorderStyle = LineStyle.Single; Iteration += (s, a) => { @@ -1012,7 +1024,10 @@ public class DialogTests public void Dialog_Opened_From_Another_Dialog () { ((FakeDriver)Driver).SetBufferSize (30, 10); + + // Override CM Dialog.DefaultButtonAlignment = Alignment.Center; + Dialog.DefaultBorderStyle = LineStyle.Single; var btn1 = new Button { Text = "press me 1" }; Button btn2 = null; @@ -1159,6 +1174,11 @@ public class DialogTests [AutoInitShutdown] public void Location_When_Application_Top_Not_Default () { + // Override CM + Window.DefaultBorderStyle = LineStyle.Single; + Dialog.DefaultButtonAlignment = Alignment.Center; + Dialog.DefaultBorderStyle = LineStyle.Single; + var expected = 5; var d = new Dialog { X = expected, Y = expected, Height = 5, Width = 5 }; Begin (d); @@ -1188,6 +1208,11 @@ public class DialogTests int iterations = -1; + // Override CM + Window.DefaultBorderStyle = LineStyle.Single; + Dialog.DefaultButtonAlignment = Alignment.Center; + Dialog.DefaultBorderStyle = LineStyle.Single; + Iteration += (s, a) => { iterations++; @@ -1361,6 +1386,10 @@ public class DialogTests params Button [] btns ) { + // Override CM + Dialog.DefaultButtonAlignment = Alignment.Center; + Dialog.DefaultBorderStyle = LineStyle.Single; + var dlg = new Dialog { Title = title, diff --git a/UnitTests/Dialogs/MessageBoxTests.cs b/UnitTests/Dialogs/MessageBoxTests.cs index 986894efa..566c31270 100644 --- a/UnitTests/Dialogs/MessageBoxTests.cs +++ b/UnitTests/Dialogs/MessageBoxTests.cs @@ -174,6 +174,10 @@ public class MessageBoxTests var btn = $"{CM.Glyphs.LeftBracket}{CM.Glyphs.LeftDefaultIndicator} btn {CM.Glyphs.RightDefaultIndicator}{CM.Glyphs.RightBracket}"; + // Override CM + MessageBox.DefaultButtonAlignment = Alignment.End; + MessageBox.DefaultBorderStyle = LineStyle.Double; + Application.Iteration += (s, a) => { iterations++; @@ -239,6 +243,10 @@ public class MessageBoxTests var btn = $"{CM.Glyphs.LeftBracket}{CM.Glyphs.LeftDefaultIndicator} btn {CM.Glyphs.RightDefaultIndicator}{CM.Glyphs.RightBracket}"; + // Override CM + MessageBox.DefaultButtonAlignment = Alignment.End; + MessageBox.DefaultBorderStyle = LineStyle.Double; + Application.Iteration += (s, a) => { iterations++; @@ -415,6 +423,10 @@ public class MessageBoxTests int iterations = -1; ((FakeDriver)Application.Driver).SetBufferSize (70, 15); + // Override CM + MessageBox.DefaultButtonAlignment = Alignment.End; + MessageBox.DefaultBorderStyle = LineStyle.Double; + Application.Iteration += (s, a) => { iterations++; From f5b1984db781a1bf99b0cf6ca6a7d3e2d44bac14 Mon Sep 17 00:00:00 2001 From: Tig Date: Sun, 4 Aug 2024 15:08:18 -0600 Subject: [PATCH 3/4] Made unit tests more resiliant to config changes --- UnitTests/FileServices/FileDialogTests.cs | 5 +++++ UnitTests/Views/MenuBarTests.cs | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/UnitTests/FileServices/FileDialogTests.cs b/UnitTests/FileServices/FileDialogTests.cs index 1395543ee..ec72a7add 100644 --- a/UnitTests/FileServices/FileDialogTests.cs +++ b/UnitTests/FileServices/FileDialogTests.cs @@ -622,6 +622,11 @@ public class FileDialogTests (ITestOutputHelper output) private FileDialog GetWindowsDialog () { + // Override CM + Window.DefaultBorderStyle = LineStyle.Single; + Dialog.DefaultButtonAlignment = Alignment.Center; + Dialog.DefaultBorderStyle = LineStyle.Single; + // Arrange var fileSystem = new MockFileSystem (new Dictionary (), @"c:\"); fileSystem.MockTime (() => new (2010, 01, 01, 11, 12, 43)); diff --git a/UnitTests/Views/MenuBarTests.cs b/UnitTests/Views/MenuBarTests.cs index f7804dd42..330f8bacf 100644 --- a/UnitTests/Views/MenuBarTests.cs +++ b/UnitTests/Views/MenuBarTests.cs @@ -362,6 +362,11 @@ public class MenuBarTests (ITestOutputHelper output) [AutoInitShutdown] public void Draw_A_Menu_Over_A_Dialog () { + // Override CM + Window.DefaultBorderStyle = LineStyle.Single; + Dialog.DefaultButtonAlignment = Alignment.Center; + Dialog.DefaultBorderStyle = LineStyle.Single; + Toplevel top = new (); var win = new Window (); top.Add (win); @@ -590,6 +595,11 @@ public class MenuBarTests (ITestOutputHelper output) [AutoInitShutdown] public void Draw_A_Menu_Over_A_Top_Dialog () { + // Override CM + Window.DefaultBorderStyle = LineStyle.Single; + Dialog.DefaultButtonAlignment = Alignment.Center; + Dialog.DefaultBorderStyle = LineStyle.Single; + ((FakeDriver)Application.Driver).SetBufferSize (40, 15); Assert.Equal (new (0, 0, 40, 15), Application.Driver.Clip); From a9f63ad138fa04b7a1e6a7b954287850991c5f4a Mon Sep 17 00:00:00 2001 From: Tig Date: Sun, 4 Aug 2024 15:27:56 -0600 Subject: [PATCH 4/4] Made unit tests more resiliant to config changes --- UnitTests/FileServices/FileDialogTests.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/UnitTests/FileServices/FileDialogTests.cs b/UnitTests/FileServices/FileDialogTests.cs index ec72a7add..c50bb986b 100644 --- a/UnitTests/FileServices/FileDialogTests.cs +++ b/UnitTests/FileServices/FileDialogTests.cs @@ -571,6 +571,11 @@ public class FileDialogTests (ITestOutputHelper output) private FileDialog GetInitializedFileDialog () { + + Window.DefaultBorderStyle = LineStyle.Single; + Dialog.DefaultButtonAlignment = Alignment.Center; + Dialog.DefaultBorderStyle = LineStyle.Single; + var dlg = new FileDialog (); Begin (dlg); @@ -579,6 +584,10 @@ public class FileDialogTests (ITestOutputHelper output) private FileDialog GetLinuxDialog () { + Window.DefaultBorderStyle = LineStyle.Single; + Dialog.DefaultButtonAlignment = Alignment.Center; + Dialog.DefaultBorderStyle = LineStyle.Single; + // Arrange var fileSystem = new MockFileSystem (new Dictionary (), "/"); fileSystem.MockTime (() => new (2010, 01, 01, 11, 12, 43));