Browse Source

Fixes #557 - MessageBox should take ustrings

Charlie Kindel 5 years ago
parent
commit
db0ebfd04a

+ 1 - 0
Terminal.Gui/Terminal.Gui.csproj

@@ -77,6 +77,7 @@
       * Fixes the functions of the Edit->Copy-Cut-Paste menu for the TextField that was not working well. (Thanks @bdisp!)
       * More robust error handing in Pos/Dim. Fixes #355 stack overflow with Pos based on the size of windows at startup. Added a OnResized action to set the Pos after the terminal are resized. (Thanks @bdisp!)
       * Fixes #389 Window layouting breaks when resizing. (Thanks @bdisp!)
+      * Fixes #557 MessageBox needs to take ustrings (BREAKING CHANGE). (Thanks @tig!)
 
       0.81:
       * Fix ncurses engine for macOS/Linux, it works again

+ 11 - 10
Terminal.Gui/Windows/MessageBox.cs

@@ -1,4 +1,5 @@
-using System;
+using NStack;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 
@@ -7,7 +8,7 @@ namespace Terminal.Gui {
 	/// MessageBox displays a modal message to the user, with a title, a message and a series of options that the user can choose from.
 	/// </summary>
 	/// <para>
-	///   The difference between the <see cref="Query(string, string, string[])"/> and <see cref="ErrorQuery(string, string, string[])"/> 
+	///   The difference between the <see cref="Query(ustring, ustring, ustring[])"/> and <see cref="ErrorQuery(ustring, ustring, ustring[])"/> 
 	///   method is the default set of colors used for the message box.
 	/// </para>
 	/// <para>
@@ -34,9 +35,9 @@ namespace Terminal.Gui {
 		/// <param name="message">Message to display, might contain multiple lines..</param>
 		/// <param name="buttons">Array of buttons to add.</param>
 		/// <remarks>
-		/// Use <see cref="Query(string, string, string[])"/> instead; it automatically sizes the MessageBox based on the contents.
+		/// Use <see cref="Query(ustring, ustring, ustring[])"/> instead; it automatically sizes the MessageBox based on the contents.
 		/// </remarks>
-		public static int Query (int width, int height, string title, string message, params string [] buttons)
+		public static int Query (int width, int height, ustring title, ustring message, params ustring [] buttons)
 		{
 			return QueryFull (false, width, height, title, message, buttons);
 		}
@@ -52,7 +53,7 @@ namespace Terminal.Gui {
 		/// The message box will be vertically and horizontally centered in the container and the size will be automatically determined
 		/// from the size of the message and buttons.
 		/// </remarks>
-		public static int Query (string title, string message, params string [] buttons)
+		public static int Query (ustring title, ustring message, params ustring [] buttons)
 		{
 			return QueryFull (false, 0, 0, title, message, buttons);
 		}
@@ -67,9 +68,9 @@ namespace Terminal.Gui {
 		/// <param name="message">Message to display, might contain multiple lines.</param>
 		/// <param name="buttons">Array of buttons to add.</param>
 		/// <remarks>
-		/// Use <see cref="ErrorQuery(string, string, string[])"/> instead; it automatically sizes the MessageBox based on the contents.
+		/// Use <see cref="ErrorQuery(ustring, ustring, ustring[])"/> instead; it automatically sizes the MessageBox based on the contents.
 		/// </remarks>
-		public static int ErrorQuery (int width, int height, string title, string message, params string [] buttons)
+		public static int ErrorQuery (int width, int height, ustring title, ustring message, params ustring [] buttons)
 		{
 			return QueryFull (true, width, height, title, message, buttons);
 		}
@@ -85,17 +86,17 @@ namespace Terminal.Gui {
 		/// The message box will be vertically and horizontally centered in the container and the size will be automatically determined
 		/// from the size of the title, message. and buttons.
 		/// </remarks>
-		public static int ErrorQuery (string title, string message, params string [] buttons)
+		public static int ErrorQuery (ustring title, ustring message, params ustring [] buttons)
 		{
 			return QueryFull (true, 0, 0, title, message, buttons);
 		}
 
 
-		static int QueryFull (bool useErrorColors, int width, int height, string title, string message, params string [] buttons)
+		static int QueryFull (bool useErrorColors, int width, int height, ustring title, ustring message, params ustring [] buttons)
 		{
 			const int defaultWidth = 30;
 			int textWidth = Label.MaxWidth (message, width);
-			int textHeight = message.ToCharArray ().Count (c => c == '\n') + 1;
+			int textHeight = message.Count(ustring.Make('\n')) + 1;
 			int msgboxHeight = Math.Max (1, textHeight) + 4; // textHeight + (top + top padding + buttons + bottom)
 
 			// Create button array for Dialog

+ 3 - 2
UICatalog/Scenarios/MessageBoxes.cs

@@ -1,4 +1,5 @@
-using System;
+using NStack;
+using System;
 using System.Collections.Generic;
 using System.Text;
 using Terminal.Gui;
@@ -153,7 +154,7 @@ namespace UICatalog {
 						int height = int.Parse (heightEdit.Text.ToString ());
 						int numButtons = int.Parse (numButtonsEdit.Text.ToString ());
 
-						var btns = new List<string> ();
+						var btns = new List<ustring> ();
 						for (int i = 0; i < numButtons; i++) {
 							btns.Add(btnText[i % 10]);
 						}