Adds a popup ContextMenu feature. Implements ContextMenu for TextField. (#1615)

* Implementing ContextMenu feature to being popup by keyboard or mouse.

* Implements ContextMenu into TextField.

* Ensures the context menu's right and bottom frame from being greater than the container.

* Added Host property. Improving scenario and unit tests.

* Only draw the RightTee if it is at the end of the menu.

* Implements cursor visibility on TextField.

* Fixes the sub-menu not showing.

* Avoids draw the menu help and shortcut if there no available space.

* Remove reference for the MenuClosing event.

* UpdateCursor must only run after the ScreenBuffer is initialized to use the cursor visibility.

* Implements Resized event on Toplevel class.

* Prevents writing overlay on the menu.

* Covering more unit tests.

* Changing from Views to Core namespace.

* Implementing MenuClosingEventArgs and MenuAllClosed event.

* Only close the menu if it's open.

* Implementing localization for en-US and pt-PT to the FileDialog.

* Implementing localization for en-US and pt-PT on the TextField context menu.

* Fixes a bug where DeleteSelectedText is updating the Text before operation completion.

* Added a method to get all the supported cultures from the Terminal.Gui.

* Improving context menu and adding more unit tests.
This commit is contained in:
BDisp
2022-03-07 06:01:51 +00:00
committed by GitHub
parent da0ea09bed
commit a822e1afa9
15 changed files with 1546 additions and 131 deletions

View File

@@ -1092,15 +1092,20 @@ namespace Terminal.Gui.Views {
tf.CursorPosition = tf.Text.Length;
Assert.True (tf.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ())));
Assert.Equal ("to jump between text ", tf.Text);
Assert.True (tf.ProcessKey (new KeyEvent (Key.T | Key.CtrlMask, new KeyModifiers ())));
Assert.Equal ("to jump between text ", tf.SelectedText);
Assert.True (tf.ProcessKey (new KeyEvent (Key.D | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ())));
Assert.Equal ("", tf.Text);
}
[Fact]
[AutoInitShutdown]
public void Adjust_First ()
{
TextField tf = new TextField ();
tf.Width = Dim.Fill ();
tf.Text = "This is a test.";
TextField tf = new TextField () {
Width = Dim.Fill (),
Text = "This is a test."
};
Application.Top.Add (tf);
Application.Begin (Application.Top);
@@ -1115,5 +1120,63 @@ namespace Terminal.Gui.Views {
return item;
}
}
[Fact, AutoInitShutdown]
public void DeleteSelectedText_InsertText_DeleteCharLeft_DeleteCharRight_Cut ()
{
var newText = "";
var oldText = "";
var tf = new TextField () { Width = 10, Text = "-1" };
tf.TextChanging += (e) => newText = e.NewText.ToString ();
tf.TextChanged += (e) => oldText = e.ToString ();
Application.Top.Add (tf);
Application.Begin (Application.Top);
Assert.Equal ("-1", tf.Text);
// InsertText
tf.SelectedStart = 1;
tf.CursorPosition = 2;
Assert.Equal (1, tf.SelectedLength);
Assert.Equal ("1", tf.SelectedText);
Assert.True (tf.ProcessKey (new KeyEvent (Key.D2, new KeyModifiers ())));
Assert.Equal ("-2", newText);
Assert.Equal ("-1", oldText);
Assert.Equal ("-2", tf.Text);
// DeleteCharLeft
tf.SelectedStart = 1;
tf.CursorPosition = 2;
Assert.Equal (1, tf.SelectedLength);
Assert.Equal ("2", tf.SelectedText);
Assert.True (tf.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
Assert.Equal ("-", newText);
Assert.Equal ("-2", oldText);
Assert.Equal ("-", tf.Text);
// DeleteCharRight
tf.Text = "-1";
tf.SelectedStart = 1;
tf.CursorPosition = 2;
Assert.Equal (1, tf.SelectedLength);
Assert.Equal ("1", tf.SelectedText);
Assert.True (tf.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ())));
Assert.Equal ("-", newText);
Assert.Equal ("-1", oldText);
Assert.Equal ("-", tf.Text);
// Cut
tf.Text = "-1";
tf.SelectedStart = 1;
tf.CursorPosition = 2;
Assert.Equal (1, tf.SelectedLength);
Assert.Equal ("1", tf.SelectedText);
Assert.True (tf.ProcessKey (new KeyEvent (Key.X | Key.CtrlMask, new KeyModifiers ())));
Assert.Equal ("-", newText);
Assert.Equal ("-1", oldText);
Assert.Equal ("-", tf.Text);
}
}
}