mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-31 02:08:03 +01:00
Fixes #2430. Launching a Dialog from a Dialog causes errors in v2_develop.
This commit is contained in:
@@ -240,9 +240,12 @@ namespace Terminal.Gui {
|
||||
contentView.Frame = cFrame;
|
||||
}
|
||||
}
|
||||
if (Subviews?.Count == 0)
|
||||
if (Subviews?.Count == 0) {
|
||||
base.Add (contentView);
|
||||
Border.Child = contentView;
|
||||
}
|
||||
if (Border.Child != contentView) {
|
||||
Border.Child = contentView;
|
||||
}
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
@@ -273,7 +276,13 @@ namespace Terminal.Gui {
|
||||
}
|
||||
|
||||
SetNeedsDisplay ();
|
||||
contentView.Remove (view);
|
||||
if (view == contentView) {
|
||||
base.Remove (view);
|
||||
contentView.Dispose ();
|
||||
return;
|
||||
} else {
|
||||
contentView.Remove (view);
|
||||
}
|
||||
|
||||
if (contentView.InternalSubviews.Count < 1) {
|
||||
CanFocus = false;
|
||||
|
||||
@@ -78,8 +78,10 @@ namespace Terminal.Gui {
|
||||
ColorScheme = Colors.Dialog;
|
||||
Modal = true;
|
||||
ButtonAlignment = DefaultButtonAlignment;
|
||||
Border = DefaultBorder;
|
||||
Border.Title = title;
|
||||
if (Border == null) {
|
||||
Border = DefaultBorder;
|
||||
Border.Title = title;
|
||||
}
|
||||
|
||||
if (buttons != null) {
|
||||
foreach (var b in buttons) {
|
||||
|
||||
@@ -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>
|
||||
@@ -239,6 +241,17 @@ namespace Terminal.Gui {
|
||||
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, bool wrapMessagge = true, params ustring [] buttons)
|
||||
{
|
||||
@@ -277,7 +290,10 @@ 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) {
|
||||
@@ -326,7 +342,7 @@ namespace Terminal.Gui {
|
||||
for (int n = 0; n < buttonList.Count; n++) {
|
||||
int buttonId = n;
|
||||
var b = buttonList [n];
|
||||
b.Clicked += (s,e) => {
|
||||
b.Clicked += (s, e) => {
|
||||
Clicked = buttonId;
|
||||
Application.RequestStop ();
|
||||
};
|
||||
|
||||
@@ -582,9 +582,99 @@ namespace Terminal.Gui.TopLevelTests {
|
||||
{
|
||||
for (int i = 0; i < 8; i++) {
|
||||
var fd = new FileDialog ();
|
||||
fd.Ready += (s,e) => Application.RequestStop ();
|
||||
fd.Ready += (s, e) => Application.RequestStop ();
|
||||
Application.Run (fd);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void Dialog_Opened_From_Another_Dialog ()
|
||||
{
|
||||
var btn1 = new Button ("press me 1");
|
||||
Button btn2 = null;
|
||||
Button btn3 = null;
|
||||
string expected = null;
|
||||
btn1.Clicked += (s, e) => {
|
||||
btn2 = new Button ("Show Sub");
|
||||
btn3 = new Button ("Close");
|
||||
btn3.Clicked += (s, e) => Application.RequestStop ();
|
||||
btn2.Clicked += (s, e) => { MessageBox.Query ("hey", "ya", "ok"); };
|
||||
var dlg = new Dialog ("Hey", btn2, btn3);
|
||||
|
||||
Application.Run (dlg);
|
||||
};
|
||||
|
||||
var iterations = -1;
|
||||
Application.Iteration += () => {
|
||||
iterations++;
|
||||
if (iterations == 0) {
|
||||
Assert.True (btn1.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
|
||||
} else if (iterations == 1) {
|
||||
expected = @"
|
||||
┌ Hey ─────────────────────────────────────────────────────────────┐
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ [ Show Sub ] [ Close ] │
|
||||
└──────────────────────────────────────────────────────────────────┘";
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
|
||||
|
||||
Assert.True (btn2.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
|
||||
} else if (iterations == 2) {
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
┌ Hey ─────────────────────────────────────────────────────────────┐
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ ┌ hey ─────────────────────────────────────────┐ │
|
||||
│ │ ya │ │
|
||||
│ │ │ │
|
||||
│ │ [◦ ok ◦] │ │
|
||||
│ └──────────────────────────────────────────────┘ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ [ Show Sub ] [ Close ] │
|
||||
└──────────────────────────────────────────────────────────────────┘", output);
|
||||
|
||||
Assert.True (Application.Current.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
|
||||
} else if (iterations == 3) {
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
|
||||
|
||||
Assert.True (btn3.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
|
||||
} else if (iterations == 4) {
|
||||
TestHelpers.AssertDriverContentsWithFrameAre ("", output);
|
||||
|
||||
Application.RequestStop ();
|
||||
}
|
||||
};
|
||||
|
||||
Application.Run ();
|
||||
Application.Shutdown ();
|
||||
|
||||
Assert.Equal (4, iterations);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user