Procházet zdrojové kódy

Fix the border not respecting the user settings.

BDisp před 2 roky
rodič
revize
e486664ccc

+ 37 - 1
Terminal.Gui/Windows/Dialog.cs

@@ -62,7 +62,7 @@ namespace Terminal.Gui {
 		/// <remarks>
 		/// <remarks>
 		/// Use the constructor that does not take a <c>width</c> and <c>height</c> instead.
 		/// Use the constructor that does not take a <c>width</c> and <c>height</c> instead.
 		/// </remarks>
 		/// </remarks>
-		public Dialog (ustring title, int width, int height, params Button [] buttons) : base (title, padding: padding)
+		public Dialog (ustring title, int width, int height, params Button [] buttons) : base (title: title, padding: padding)
 		{
 		{
 			X = Pos.Center ();
 			X = Pos.Center ();
 			Y = Pos.Center ();
 			Y = Pos.Center ();
@@ -119,6 +119,42 @@ namespace Terminal.Gui {
 		/// </remarks>
 		/// </remarks>
 		public Dialog (ustring title, params Button [] buttons) : this (title: title, width: 0, height: 0, buttons: buttons) { }
 		public Dialog (ustring title, params Button [] buttons) : this (title: title, width: 0, height: 0, buttons: buttons) { }
 
 
+		/// <summary>
+		/// Initializes a new instance of the <see cref="Dialog"/> class using <see cref="LayoutStyle.Computed"/> positioning, 
+		/// with a <see cref="Border"/> and with an optional set of <see cref="Button"/>s to display
+		/// </summary>
+		/// <param name="title">Title for the dialog.</param>
+		/// <param name="border">The border.</param>
+		/// <param name="buttons">Optional buttons to lay out at the bottom of the dialog.</param>
+		public Dialog (ustring title, Border border, params Button [] buttons)
+			: this (title: title, width: 0, height: 0, buttons: buttons)
+		{
+			Initialize (title, border);
+		}
+
+		/// <summary>
+		/// Initializes a new instance of the <see cref="Dialog"/> class using <see cref="LayoutStyle.Computed"/> positioning, 
+		/// with a <see cref="Border"/> and with an optional set of <see cref="Button"/>s to display
+		/// </summary>
+		/// <param name="title">Title for the dialog.</param>
+		/// <param name="width">Width for the dialog.</param>
+		/// <param name="height">Height for the dialog.</param>
+		/// <param name="border">The border.</param>
+		/// <param name="buttons">Optional buttons to lay out at the bottom of the dialog.</param>
+		public Dialog (ustring title, int width, int height, Border border, params Button [] buttons)
+			: this (title: title, width: width, height: height, buttons: buttons)
+		{
+			Initialize (title, border);
+		}
+
+		void Initialize (ustring title, Border border)
+		{
+			if (border != null) {
+				Border = border;
+				Border.Title = title;
+			}
+		}
+
 		/// <summary>
 		/// <summary>
 		/// Adds a <see cref="Button"/> to the <see cref="Dialog"/>, its layout will be controlled by the <see cref="Dialog"/>
 		/// Adds a <see cref="Button"/> to the <see cref="Dialog"/>, its layout will be controlled by the <see cref="Dialog"/>
 		/// </summary>
 		/// </summary>

+ 2 - 6
Terminal.Gui/Windows/MessageBox.cs

@@ -281,15 +281,11 @@ namespace Terminal.Gui {
 			// Create Dialog (retain backwards compat by supporting specifying height/width)
 			// Create Dialog (retain backwards compat by supporting specifying height/width)
 			Dialog d;
 			Dialog d;
 			if (width == 0 & height == 0) {
 			if (width == 0 & height == 0) {
-				d = new Dialog (title, buttonList.ToArray ()) {
+				d = new Dialog (title, border, buttonList.ToArray ()) {
 					Height = msgboxHeight
 					Height = msgboxHeight
 				};
 				};
 			} else {
 			} else {
-				d = new Dialog (title, width, Math.Max (height, 4), buttonList.ToArray ());
-			}
-
-			if (border != null) {
-				d.Border = border;
+				d = new Dialog (title, width, Math.Max (height, 4), border, buttonList.ToArray ());
 			}
 			}
 
 
 			if (useErrorColors) {
 			if (useErrorColors) {

+ 18 - 4
UICatalog/Scenarios/MessageBoxes.cs

@@ -125,6 +125,11 @@ namespace UICatalog.Scenarios {
 			};
 			};
 			frame.Add (defaultButtonEdit);
 			frame.Add (defaultButtonEdit);
 
 
+			var border = new Border () {
+				Effect3D = true,
+				BorderStyle = BorderStyle.Single
+			};
+
 			label = new Label ("Style:") {
 			label = new Label ("Style:") {
 				X = 0,
 				X = 0,
 				Y = Pos.Bottom (label),
 				Y = Pos.Bottom (label),
@@ -133,16 +138,25 @@ namespace UICatalog.Scenarios {
 				TextAlignment = Terminal.Gui.TextAlignment.Right,
 				TextAlignment = Terminal.Gui.TextAlignment.Right,
 			};
 			};
 			frame.Add (label);
 			frame.Add (label);
+
 			var styleRadioGroup = new RadioGroup (new ustring [] { "_Query", "_Error" }) {
 			var styleRadioGroup = new RadioGroup (new ustring [] { "_Query", "_Error" }) {
 				X = Pos.Right (label) + 1,
 				X = Pos.Right (label) + 1,
 				Y = Pos.Top (label),
 				Y = Pos.Top (label),
 			};
 			};
+			styleRadioGroup.SelectedItemChanged += e => {
+				switch (e.SelectedItem) {
+				case 0:
+					border.BorderBrush = Colors.Dialog.Normal.Foreground;
+					border.Background = Colors.Dialog.Normal.Background;
+					break;
+				case 1:
+					border.BorderBrush = Colors.Error.Normal.Foreground;
+					border.Background = Colors.Error.Normal.Background;
+					break;
+				}
+			};
 			frame.Add (styleRadioGroup);
 			frame.Add (styleRadioGroup);
 
 
-			var border = new Border () {
-				Effect3D = true,
-				BorderStyle = BorderStyle.Single
-			};
 			var ckbEffect3D = new CheckBox ("Effect3D", true) {
 			var ckbEffect3D = new CheckBox ("Effect3D", true) {
 				X = Pos.Right (label) + 1,
 				X = Pos.Right (label) + 1,
 				Y = Pos.Top (label) + 2
 				Y = Pos.Top (label) + 2

+ 33 - 0
UnitTests/TopLevels/MessageBoxTests.cs

@@ -319,5 +319,38 @@ ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
 
 
 			Application.Run ();
 			Application.Run ();
 		}
 		}
+
+		[Theory, AutoInitShutdown]
+		[InlineData ("", true)]
+		[InlineData ("", false)]
+		[InlineData ("\n", true)]
+		[InlineData ("\n", false)]
+		public void MessageBox_With_A_Empty_Message_Or_A_NewLline_WrapMessagge_True_Or_False (string message, bool wrapMessage)
+		{
+			var iterations = -1;
+			Application.Begin (Application.Top);
+
+			Application.Iteration += () => {
+				iterations++;
+
+				if (iterations == 0) {
+					MessageBox.Query ("mywindow", message, 0, null, wrapMessage, "ok");
+
+					Application.RequestStop ();
+				} else if (iterations == 1) {
+					Application.Refresh ();
+					TestHelpers.AssertDriverContentsWithFrameAre (@"
+                ┌ mywindow ────────────────────────────────────┐
+                │                                              │
+                │                                              │
+                │                   [◦ ok ◦]                   │
+                └──────────────────────────────────────────────┘", output);
+
+					Application.RequestStop ();
+				}
+			};
+
+			Application.Run ();
+		}
 	}
 	}
 }
 }