From db0ebfd04aacc8de48d38b5dab977487db208bad Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Sun, 31 May 2020 21:24:18 -0600 Subject: [PATCH] Fixes #557 - MessageBox should take ustrings --- Terminal.Gui/Terminal.Gui.csproj | 1 + Terminal.Gui/Windows/MessageBox.cs | 21 +++++++++++---------- UICatalog/Scenarios/MessageBoxes.cs | 5 +++-- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Terminal.Gui/Terminal.Gui.csproj b/Terminal.Gui/Terminal.Gui.csproj index ba54482db..77c3a2342 100644 --- a/Terminal.Gui/Terminal.Gui.csproj +++ b/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 diff --git a/Terminal.Gui/Windows/MessageBox.cs b/Terminal.Gui/Windows/MessageBox.cs index 01dabfc36..a95b9c3ee 100644 --- a/Terminal.Gui/Windows/MessageBox.cs +++ b/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. /// /// - /// The difference between the and + /// The difference between the and /// method is the default set of colors used for the message box. /// /// @@ -34,9 +35,9 @@ namespace Terminal.Gui { /// Message to display, might contain multiple lines.. /// Array of buttons to add. /// - /// Use instead; it automatically sizes the MessageBox based on the contents. + /// Use instead; it automatically sizes the MessageBox based on the contents. /// - 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. /// - 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 { /// Message to display, might contain multiple lines. /// Array of buttons to add. /// - /// Use instead; it automatically sizes the MessageBox based on the contents. + /// Use instead; it automatically sizes the MessageBox based on the contents. /// - 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. /// - 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 diff --git a/UICatalog/Scenarios/MessageBoxes.cs b/UICatalog/Scenarios/MessageBoxes.cs index 066943232..24dafb292 100644 --- a/UICatalog/Scenarios/MessageBoxes.cs +++ b/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 (); + var btns = new List (); for (int i = 0; i < numButtons; i++) { btns.Add(btnText[i % 10]); }