mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-02 01:03:29 +01:00
* Fixes #1133. Flaw in LayoutSubviews/TopologicalSort. * Toplevel can't be used on Pos/Dim but only his subviews. Was not caught before because the LayoutSubviews method never gone so deep before. * Fixed the error that is triggered when the Pos/Dim is the current Application.Top. * Application.Top is the only exception in the TopologicalSort method check. * Fixes #1179. TextView does not copy to the clipboard on deleting. * Added Button DoubleClick and fixed WordForward/WordBackward issues. * Prevents a negative height. * Fixes the enter key line feed. * Fixes #1187. Prevents WordBackward throwing an exception if point is greater than the text length. * Fixes #1189. Prevents negative index. * Fixes #1193. A non auto size default Button now preserves his width and thus the text alignment now work. * Fixing the Width and Height checks of the Dim class with AutoSize dependence. * Fixes #1197. Prevents width negative value if added directly to the Application.Top * Fixes #1199. Normalize views constructors and did some typo fixing. * Fixing the Application.Top Pos/Dim settings. * Always uses inverted color for selected text to avoid same colors. * Prevents throw an exception if the clipboard content is null. * Added Find and Replace (next/previous). Replace All and Select All. A non modal dialog box. * Keeps tracking the selected replaced text. * Fixes #1202. CheckBox now deals with a functional '_' underscore hotkey. * The selected text should be maintained when losing focus. * Fixes an extra line on page down. * Fixes the WordBackward if it text has more than one whitespaces or when has only one digit or letter. * Fixes WordForward/WordBackward on text with more than one whitespace or with only one digit or letter. * Forgot to replace the hacking. * Added unit tests for the TextField view. Fixed some more bugs. * Redraw should only show the selected text if it is focused. * Fixes cursor position on double click and ensures the setting of the selected text. * Added match whole word checking. * Added missing parameters documentation. * Ensures the SelectedLength property to be always with positive value. * Fixes the WordBackward when at the end of the text has a character between two whitespace. * Added unit tests to the TextView, Used property and fixed some more bugs. * Fixed Used to only show if it has focus. * Fixed ReplaceAll and prevents Debug.Assert from showing.
178 lines
4.7 KiB
C#
178 lines
4.7 KiB
C#
using NStack;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Terminal.Gui;
|
|
|
|
namespace UICatalog {
|
|
[ScenarioMetadata (Name: "Dialogs", Description: "Demonstrates how to the Dialog class")]
|
|
[ScenarioCategory ("Controls")]
|
|
[ScenarioCategory ("Dialogs")]
|
|
class Dialogs : Scenario {
|
|
public override void Setup ()
|
|
{
|
|
var frame = new FrameView ("Dialog Options") {
|
|
X = Pos.Center(),
|
|
Y = 1,
|
|
Width = Dim.Percent(75),
|
|
Height = 10
|
|
};
|
|
Win.Add (frame);
|
|
|
|
var label = new Label ("width:") {
|
|
X = 0,
|
|
Y = 0,
|
|
Width = 15,
|
|
Height = 1,
|
|
TextAlignment = Terminal.Gui.TextAlignment.Right,
|
|
};
|
|
frame.Add (label);
|
|
var widthEdit = new TextField ("0") {
|
|
X = Pos.Right (label) + 1,
|
|
Y = Pos.Top (label),
|
|
Width = 5,
|
|
Height = 1
|
|
};
|
|
frame.Add (widthEdit);
|
|
|
|
label = new Label ("height:") {
|
|
X = 0,
|
|
Y = Pos.Bottom (label),
|
|
Width = Dim.Width (label),
|
|
Height = 1,
|
|
TextAlignment = Terminal.Gui.TextAlignment.Right,
|
|
};
|
|
frame.Add (label);
|
|
var heightEdit = new TextField ("0") {
|
|
X = Pos.Right (label) + 1,
|
|
Y = Pos.Top (label),
|
|
Width = 5,
|
|
Height = 1
|
|
};
|
|
frame.Add (heightEdit);
|
|
|
|
frame.Add (new Label ("If height & width are both 0,") {
|
|
X = Pos.Right (widthEdit) + 2,
|
|
Y = Pos.Top (widthEdit),
|
|
});
|
|
frame.Add (new Label ("the Dialog will size to 80% of container.") {
|
|
X = Pos.Right (heightEdit) + 2,
|
|
Y = Pos.Top (heightEdit),
|
|
});
|
|
|
|
label = new Label ("Title:") {
|
|
X = 0,
|
|
Y = Pos.Bottom (label),
|
|
Width = Dim.Width (label),
|
|
Height = 1,
|
|
TextAlignment = Terminal.Gui.TextAlignment.Right,
|
|
};
|
|
frame.Add (label);
|
|
var titleEdit = new TextField ("Title") {
|
|
X = Pos.Right (label) + 1,
|
|
Y = Pos.Top (label),
|
|
Width = Dim.Fill(),
|
|
Height = 1
|
|
};
|
|
frame.Add (titleEdit);
|
|
|
|
label = new Label ("Num Buttons:") {
|
|
X = 0,
|
|
Y = Pos.Bottom (titleEdit),
|
|
Width = Dim.Width (label),
|
|
Height = 1,
|
|
TextAlignment = Terminal.Gui.TextAlignment.Right,
|
|
};
|
|
frame.Add (label);
|
|
var numButtonsEdit = new TextField ("3") {
|
|
X = Pos.Right (label) + 1,
|
|
Y = Pos.Top (label),
|
|
Width = 5,
|
|
Height = 1
|
|
};
|
|
frame.Add (numButtonsEdit);
|
|
|
|
frame.Height = Dim.Height (widthEdit) + Dim.Height (heightEdit) + Dim.Height (titleEdit)
|
|
+ Dim.Height (numButtonsEdit) + 2;
|
|
|
|
label = new Label ("Button Pressed:") {
|
|
X = Pos.Center (),
|
|
Y = Pos.Bottom (frame) + 4,
|
|
Height = 1,
|
|
TextAlignment = Terminal.Gui.TextAlignment.Right,
|
|
};
|
|
Win.Add (label);
|
|
var buttonPressedLabel = new Label (" ") {
|
|
X = Pos.Center (),
|
|
Y = Pos.Bottom (frame) + 5,
|
|
Width = 25,
|
|
Height = 1,
|
|
ColorScheme = Colors.Error,
|
|
};
|
|
|
|
//var btnText = new [] { "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine" };
|
|
var showDialogButton = new Button ("Show Dialog") {
|
|
X = Pos.Center(),
|
|
Y = Pos.Bottom (frame) + 2,
|
|
IsDefault = true,
|
|
};
|
|
showDialogButton.Clicked += () => {
|
|
try {
|
|
int width = int.Parse (widthEdit.Text.ToString ());
|
|
int height = int.Parse (heightEdit.Text.ToString ());
|
|
int numButtons = int.Parse (numButtonsEdit.Text.ToString ());
|
|
|
|
var buttons = new List<Button> ();
|
|
var clicked = -1;
|
|
for (int i = 0; i < numButtons; i++) {
|
|
var buttonId = i;
|
|
//var button = new Button (btnText [buttonId % 10],
|
|
// is_default: buttonId == 0);
|
|
var button = new Button (NumberToWords.Convert(buttonId),
|
|
is_default: buttonId == 0);
|
|
button.Clicked += () => {
|
|
clicked = buttonId;
|
|
Application.RequestStop ();
|
|
};
|
|
buttons.Add (button);
|
|
}
|
|
|
|
// This tests dynamically adding buttons; ensuring the dialog resizes if needed and
|
|
// the buttons are laid out correctly
|
|
var dialog = new Dialog (titleEdit.Text, width, height,
|
|
buttons.ToArray ());
|
|
var add = new Button ("Add a button") {
|
|
X = Pos.Center (),
|
|
Y = Pos.Center ()
|
|
};
|
|
add.Clicked += () => {
|
|
var buttonId = buttons.Count;
|
|
//var button = new Button (btnText [buttonId % 10],
|
|
// is_default: buttonId == 0);
|
|
var button = new Button (NumberToWords.Convert (buttonId),
|
|
is_default: buttonId == 0);
|
|
button.Clicked += () => {
|
|
clicked = buttonId;
|
|
Application.RequestStop ();
|
|
};
|
|
buttons.Add (button);
|
|
dialog.AddButton (button);
|
|
button.TabIndex = buttons [buttons.Count - 2].TabIndex + 1;
|
|
};
|
|
dialog.Add (add);
|
|
|
|
Application.Run (dialog);
|
|
buttonPressedLabel.Text = $"{clicked}";
|
|
|
|
} catch (FormatException) {
|
|
buttonPressedLabel.Text = "Invalid Options";
|
|
}
|
|
};
|
|
Win.Add (showDialogButton);
|
|
|
|
Win.Add (buttonPressedLabel);
|
|
}
|
|
}
|
|
}
|