|
@@ -1,6 +1,8 @@
|
|
|
using NStack;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using Terminal.Gui.Configuration;
|
|
|
+using static Terminal.Gui.Configuration.ConfigurationManager;
|
|
|
|
|
|
namespace Terminal.Gui {
|
|
|
/// <summary>
|
|
@@ -38,7 +40,7 @@ namespace Terminal.Gui {
|
|
|
/// </remarks>
|
|
|
public static int Query (int width, int height, ustring title, ustring message, params ustring [] buttons)
|
|
|
{
|
|
|
- return QueryFull (false, width, height, title, message, 0, null, buttons);
|
|
|
+ return QueryFull (false, width, height, title, message, 0, null, true, buttons);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -54,7 +56,7 @@ namespace Terminal.Gui {
|
|
|
/// </remarks>
|
|
|
public static int Query (ustring title, ustring message, params ustring [] buttons)
|
|
|
{
|
|
|
- return QueryFull (false, 0, 0, title, message, 0, null, buttons);
|
|
|
+ return QueryFull (false, 0, 0, title, message, 0, null, true, buttons);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -71,7 +73,7 @@ namespace Terminal.Gui {
|
|
|
/// </remarks>
|
|
|
public static int ErrorQuery (int width, int height, ustring title, ustring message, params ustring [] buttons)
|
|
|
{
|
|
|
- return QueryFull (true, width, height, title, message, 0, null, buttons);
|
|
|
+ return QueryFull (true, width, height, title, message, 0, null, true, buttons);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -87,7 +89,7 @@ namespace Terminal.Gui {
|
|
|
/// </remarks>
|
|
|
public static int ErrorQuery (ustring title, ustring message, params ustring [] buttons)
|
|
|
{
|
|
|
- return QueryFull (true, 0, 0, title, message, 0, null, buttons);
|
|
|
+ return QueryFull (true, 0, 0, title, message, 0, null, true, buttons);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -105,7 +107,7 @@ namespace Terminal.Gui {
|
|
|
/// </remarks>
|
|
|
public static int Query (int width, int height, ustring title, ustring message, int defaultButton = 0, params ustring [] buttons)
|
|
|
{
|
|
|
- return QueryFull (false, width, height, title, message, defaultButton, null, buttons);
|
|
|
+ return QueryFull (false, width, height, title, message, defaultButton, null, true, buttons);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -122,7 +124,7 @@ namespace Terminal.Gui {
|
|
|
/// </remarks>
|
|
|
public static int Query (ustring title, ustring message, int defaultButton = 0, params ustring [] buttons)
|
|
|
{
|
|
|
- return QueryFull (false, 0, 0, title, message, defaultButton, null, buttons);
|
|
|
+ return QueryFull (false, 0, 0, title, message, defaultButton, null, true, buttons);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -135,13 +137,14 @@ namespace Terminal.Gui {
|
|
|
/// <param name="message">Message to display, might contain multiple lines.</param>
|
|
|
/// <param name="defaultButton">Index of the default button.</param>
|
|
|
/// <param name="border">The border settings.</param>
|
|
|
+ /// <param name="wrapMessagge">If wrap the message or not.</param>
|
|
|
/// <param name="buttons">Array of buttons to add.</param>
|
|
|
/// <remarks>
|
|
|
/// 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, ustring title, ustring message, int defaultButton = 0, Border border = null, params ustring [] buttons)
|
|
|
+ public static int Query (int width, int height, ustring title, ustring message, int defaultButton = 0, Border border = null, bool wrapMessagge = true, params ustring [] buttons)
|
|
|
{
|
|
|
- return QueryFull (false, width, height, title, message, defaultButton, border, buttons);
|
|
|
+ return QueryFull (false, width, height, title, message, defaultButton, border, wrapMessagge, buttons);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -152,14 +155,15 @@ namespace Terminal.Gui {
|
|
|
/// <param name="message">Message to display, might contain multiple lines.</param>
|
|
|
/// <param name="defaultButton">Index of the default button.</param>
|
|
|
/// <param name="border">The border settings.</param>
|
|
|
+ /// <param name="wrapMessagge">If wrap the message or not.</param>
|
|
|
/// <param name="buttons">Array of buttons to add.</param>
|
|
|
/// <remarks>
|
|
|
/// 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 (ustring title, ustring message, int defaultButton = 0, Border border = null, params ustring [] buttons)
|
|
|
+ public static int Query (ustring title, ustring message, int defaultButton = 0, Border border = null, bool wrapMessagge = true, params ustring [] buttons)
|
|
|
{
|
|
|
- return QueryFull (false, 0, 0, title, message, defaultButton, border, buttons);
|
|
|
+ return QueryFull (false, 0, 0, title, message, defaultButton, border, wrapMessagge, buttons);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -178,7 +182,7 @@ namespace Terminal.Gui {
|
|
|
/// </remarks>
|
|
|
public static int ErrorQuery (int width, int height, ustring title, ustring message, int defaultButton = 0, params ustring [] buttons)
|
|
|
{
|
|
|
- return QueryFull (true, width, height, title, message, defaultButton, null, buttons);
|
|
|
+ return QueryFull (true, width, height, title, message, defaultButton, null, true, buttons);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -195,7 +199,7 @@ namespace Terminal.Gui {
|
|
|
/// </remarks>
|
|
|
public static int ErrorQuery (ustring title, ustring message, int defaultButton = 0, params ustring [] buttons)
|
|
|
{
|
|
|
- return QueryFull (true, 0, 0, title, message, defaultButton, null, buttons);
|
|
|
+ return QueryFull (true, 0, 0, title, message, defaultButton, null, true, buttons);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -208,13 +212,14 @@ namespace Terminal.Gui {
|
|
|
/// <param name="message">Message to display, might contain multiple lines.</param>
|
|
|
/// <param name="defaultButton">Index of the default button.</param>
|
|
|
/// <param name="border">The border settings.</param>
|
|
|
+ /// <param name="wrapMessagge">If wrap the message or not.</param>
|
|
|
/// <param name="buttons">Array of buttons to add.</param>
|
|
|
/// <remarks>
|
|
|
/// 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, ustring title, ustring message, int defaultButton = 0, Border border = null, params ustring [] buttons)
|
|
|
+ public static int ErrorQuery (int width, int height, ustring title, ustring message, int defaultButton = 0, Border border = null, bool wrapMessagge = true, params ustring [] buttons)
|
|
|
{
|
|
|
- return QueryFull (true, width, height, title, message, defaultButton, border, buttons);
|
|
|
+ return QueryFull (true, width, height, title, message, defaultButton, border, wrapMessagge, buttons);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -225,25 +230,37 @@ namespace Terminal.Gui {
|
|
|
/// <param name="message">Message to display, might contain multiple lines.</param>
|
|
|
/// <param name="defaultButton">Index of the default button.</param>
|
|
|
/// <param name="border">The border settings.</param>
|
|
|
+ /// <param name="wrapMessagge">If wrap the message or not.</param>
|
|
|
/// <param name="buttons">Array of buttons to add.</param>
|
|
|
/// <remarks>
|
|
|
/// 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 (ustring title, ustring message, int defaultButton = 0, Border border = null, params ustring [] buttons)
|
|
|
+ public static int ErrorQuery (ustring title, ustring message, int defaultButton = 0, Border border = null, bool wrapMessagge = true, params ustring [] buttons)
|
|
|
{
|
|
|
- return QueryFull (true, 0, 0, title, message, defaultButton, border, buttons);
|
|
|
+ return QueryFull (true, 0, 0, title, message, defaultButton, border, wrapMessagge, buttons);
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Defines the default border styling for <see cref="Dialog"/>. Can be configured via <see cref="ConfigurationManager"/>.
|
|
|
+ /// </summary>
|
|
|
+ [SerializableConfigurationProperty (Scope = typeof (ThemeScope))]
|
|
|
+ public static Border DefaultBorder { get; set; } = new Border () {
|
|
|
+ BorderStyle = BorderStyle.Single,
|
|
|
+ DrawMarginFrame = false,
|
|
|
+ Effect3D = true,
|
|
|
+ Effect3DOffset = new Point (1, 1),
|
|
|
+ };
|
|
|
+
|
|
|
static int QueryFull (bool useErrorColors, int width, int height, ustring title, ustring message,
|
|
|
- int defaultButton = 0, Border border = null, params ustring [] buttons)
|
|
|
+ int defaultButton = 0, Border border = null, bool wrapMessagge = true, params ustring [] buttons)
|
|
|
{
|
|
|
int defaultWidth = 50;
|
|
|
if (defaultWidth > Application.Driver.Cols / 2) {
|
|
|
defaultWidth = (int)(Application.Driver.Cols * 0.60f);
|
|
|
}
|
|
|
int maxWidthLine = TextFormatter.MaxWidthLine (message);
|
|
|
- if (maxWidthLine > Application.Driver.Cols) {
|
|
|
+ if (wrapMessagge && maxWidthLine > Application.Driver.Cols) {
|
|
|
maxWidthLine = Application.Driver.Cols;
|
|
|
}
|
|
|
if (width == 0) {
|
|
@@ -251,10 +268,14 @@ namespace Terminal.Gui {
|
|
|
} else {
|
|
|
maxWidthLine = width;
|
|
|
}
|
|
|
- int textWidth = Math.Min (TextFormatter.MaxWidth (message, maxWidthLine), Application.Driver.Cols);
|
|
|
+ int textWidth = TextFormatter.MaxWidth (message, maxWidthLine);
|
|
|
int textHeight = TextFormatter.MaxLines (message, textWidth); // message.Count (ustring.Make ('\n')) + 1;
|
|
|
- int msgboxHeight = Math.Min (Math.Max (1, textHeight) + 4, Application.Driver.Rows); // textHeight + (top + top padding + buttons + bottom)
|
|
|
+ int msgboxHeight = Math.Max (1, textHeight) + 4; // textHeight + (top + top padding + buttons + bottom)
|
|
|
|
|
|
+ if (wrapMessagge) {
|
|
|
+ textWidth = Math.Min (textWidth, Application.Driver.Cols);
|
|
|
+ msgboxHeight = Math.Min (msgboxHeight, Application.Driver.Rows);
|
|
|
+ }
|
|
|
// Create button array for Dialog
|
|
|
int count = 0;
|
|
|
List<Button> buttonList = new List<Button> ();
|
|
@@ -269,26 +290,31 @@ namespace Terminal.Gui {
|
|
|
buttonList.Add (b);
|
|
|
count++;
|
|
|
}
|
|
|
-
|
|
|
+ if (border == null) {
|
|
|
+ border = DefaultBorder;
|
|
|
+ border.Title = title;
|
|
|
+ }
|
|
|
// Create Dialog (retain backwards compat by supporting specifying height/width)
|
|
|
Dialog d;
|
|
|
if (width == 0 & height == 0) {
|
|
|
- d = new Dialog (title, buttonList.ToArray ()) {
|
|
|
+ d = new Dialog (title, border, buttonList.ToArray ()) {
|
|
|
Height = msgboxHeight
|
|
|
};
|
|
|
} 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) {
|
|
|
d.ColorScheme = Colors.Error;
|
|
|
+ d.Border.BorderBrush = Colors.Error.Normal.Foreground;
|
|
|
+ d.Border.Background = Colors.Error.Normal.Background;
|
|
|
+ } else {
|
|
|
+ d.ColorScheme = Colors.Dialog;
|
|
|
+ d.Border.BorderBrush = Colors.Dialog.Normal.Foreground;
|
|
|
+ d.Border.Background = Colors.Dialog.Normal.Background;
|
|
|
}
|
|
|
|
|
|
- if (message != null) {
|
|
|
+ if (!ustring.IsNullOrEmpty (message)) {
|
|
|
var l = new Label (message) {
|
|
|
LayoutStyle = LayoutStyle.Computed,
|
|
|
TextAlignment = TextAlignment.Centered,
|
|
@@ -303,7 +329,12 @@ namespace Terminal.Gui {
|
|
|
|
|
|
if (width == 0 & height == 0) {
|
|
|
// Dynamically size Width
|
|
|
- d.Width = Math.Min (Math.Max (maxWidthLine, Math.Max (title.ConsoleWidth, Math.Max (textWidth + 2, d.GetButtonsWidth () + d.buttons.Count + 2))), Application.Driver.Cols); // textWidth + (left + padding + padding + right)
|
|
|
+ var dWidth = Math.Max (maxWidthLine, Math.Max (title.ConsoleWidth, Math.Max (textWidth + 2, d.GetButtonsWidth () + d.buttons.Count + 2))); // textWidth + (left + padding + padding + right)
|
|
|
+ if (wrapMessagge) {
|
|
|
+ d.Width = Math.Min (dWidth, Application.Driver.Cols);
|
|
|
+ } else {
|
|
|
+ d.Width = dWidth;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// Setup actions
|
|
@@ -311,7 +342,7 @@ namespace Terminal.Gui {
|
|
|
for (int n = 0; n < buttonList.Count; n++) {
|
|
|
int buttonId = n;
|
|
|
var b = buttonList [n];
|
|
|
- b.Clicked += () => {
|
|
|
+ b.Clicked += (s, e) => {
|
|
|
Clicked = buttonId;
|
|
|
Application.RequestStop ();
|
|
|
};
|