Browse Source

Resizing the MessageBox width to accommodate all message text (#299)

* Fixed key events traversal for modal dialogs

The key must be propagated initially to the first chain element
before evaluating if we should stop because of the handled or
the Modal condition. Otherwise the modal dialog
won't get any process key notification.

This fixes https://github.com/migueldeicaza/gui.cs/commit/c072e29a684068af50e1b9e284213b3839dad804

* Resizing the MessageBox width to accommodate all message text

Co-authored-by: Adrian Alonso <[email protected]>
BDisp 5 years ago
parent
commit
832ff75973
2 changed files with 5 additions and 5 deletions
  1. 1 1
      Example/demo.cs
  2. 4 4
      Terminal.Gui/Dialogs/MessageBox.cs

+ 1 - 1
Example/demo.cs

@@ -223,7 +223,7 @@ static class Demo {
 		var d = new OpenDialog ("Open", "Open a file");
 		Application.Run (d);
 
-		MessageBox.Query (50, 7, "Selected File", string.Join (", ", d.FilePaths), "ok");
+		MessageBox.Query (50, 7, "Selected File", string.Join (", ", d.FilePaths), "Ok");
 	}
 
 	public static void ShowHex (Toplevel top)

+ 4 - 4
Terminal.Gui/Dialogs/MessageBox.cs

@@ -43,7 +43,7 @@ namespace Terminal.Gui {
 		/// <param name="width">Width for the window.</param>
 		/// <param name="height">Height for the window.</param>
 		/// <param name="title">Title for the query.</param>
-		/// <param name="message">Message to display, might contain multiple lines..</param>
+		/// <param name="message">Message to display, might contain multiple lines.</param>
 		/// <param name="buttons">Array of buttons to add.</param>
 		public static int ErrorQuery (int width, int height, string title, string message, params string [] buttons)
 		{
@@ -55,10 +55,10 @@ namespace Terminal.Gui {
 			int textWidth = Label.MaxWidth (message, width);
 			int clicked = -1, count = 0;
 
-			var d = new Dialog (title, width, height);
+			var d = new Dialog (title, Math.Max(width, textWidth) + 4, height);
 			if (useErrorColors)
 				d.ColorScheme = Colors.Error;
-			
+
 			foreach (var s in buttons) {
 				int n = count++;
 				var b = new Button (s);
@@ -69,7 +69,7 @@ namespace Terminal.Gui {
 				d.AddButton (b);
 			}
 			if (message != null) {
-				var l = new Label ((width - 4 - textWidth) / 2, 0, message);
+				var l = new Label (textWidth > width ? 0 : (width - 4 - textWidth) / 2, 0, message);
 				d.Add (l);
 			}