Files
Terminal.Gui/UnitTests/UICatalog/ScenarioTests.cs
Tig dcb3b359ad Fixes #2926 - Refactor KeyEvent and KeyEventEventArgs to simplify (#2927)
* Adds basic MainLoop unit tests

* Remove WinChange action from Curses

* Remove WinChange action from Curses

* Remove ProcessInput action from Windows MainLoop

* Simplified MainLoop/ConsoleDriver by making MainLoop internal and moving impt fns to Application

* Modernized Terminal resize events

* Modernized Terminal resize events

* Removed un used property

* for _isWindowsTerminal devenv->wininit; not sure what changed

* Modernized mouse/keyboard events (Action->EventHandler)

* Updated OnMouseEvent API docs

* Using WT_SESSION to detect WT

* removes hacky GetParentProcess

* Updates to fix #2634 (clear last line)

* removes hacky GetParentProcess2

* Addressed mac resize issue

* Addressed mac resize issue

* Removes ConsoleDriver.PrepareToRun, has Init return MainLoop

* Removes unneeded Attribute methods

* Removed GetProcesssName

* Removed GetProcesssName

* Refactored KeyEvent and KeyEventEventArgs into a single class

* Revert "Refactored KeyEvent and KeyEventEventArgs into a single class"

This reverts commit 88a00658db.

* Fixed key repeat issue; reverted stupidity on 1049/1047 confusion

* Updated CSI API Docs

* merge

* Rearranged Event.cs to Keyboard.cs and Mouse.cs

* Renamed KeyEventEventArgs KeyEventArgs

* temp renamed KeyEvent OldKeyEvent

* Merged KeyEvent into KeyEventArgs

* Renamed Application.ProcessKey members

* Renamed Application.ProcessKey members

* Renamed Application.ProcessKey members

* Added Responder.KeyPressed

* Removed unused references

* Fixed arg naming

* InvokeKeybindings->InvokeKeyBindings

* InvokeKeybindings->InvokeKeyBindings

* Fixed unit tests fail

* More progress on refactoring key input; still broken and probably wrong

* Moved OnKeyPressed out of Responder and made ProcessKeyPrssed non-virtual

* Updated API docs

* Moved key handling from Responder to View

* Updated API docs

* Updated HotKey API docs

* Updated shortcut API docs

* Fixed responder unit tests

* Removed Shortcut from View as it is not used

* Removed unneeded OnHotKey override from Button

* Fixed BackTab logic

* Button now uses Key Bindings exclusively

* Button now uses Key Bindings exclusively

* Updated keyboard.md docs

* Fixed unit tests to account for Toplevel handling default button

* Added View.InvokeCommand API

* Modernized RadioGroup

* Removed ColdKey

* Modernized (partially) StatusBar

* Worked around FileDialog issue with Ctrl-F

* Fixed driver unit test; view must be focused to reciev key pressed

* Application code cleanup

* Start on updaing menu

* Menu now mostly works

* Menu Select refinement

* Fixed known menu bugs!

* Enabled HotKey to cause focus- experimental

* Fixes #3022 & adds unit test to prove it

* Actually Fixes #3022 & adds unit test to prove it

* Working through hotkey issues

* Misc fixes

* removed hot/cold key stuff from Keys scenario

* Fixed scenarios

* Simplified shortcut string handling

* Modernized Checkbox

* Modernized TileView

* Updated API docs

* Updated API docs

* attempting to publish v2 docs

* Revert "attempting to publish v2 docs"

This reverts commit 59dcec111b.

* Playing with api docs

* Removed Key.BackTab

* Removed Caps/Scroll/Numlock

* Partial removal of keymodifiers - unit tests pass

* Partial removal of keymodifiers - broke netdriver somewhere

* WindowsDriver & added KeyEventArgsTests

* Fixing menu shortcut/hotkeys - broke Menu.cs into separate files

* Fixed MenuBar!

* Finished modernizing Menu/MenuBar

* Removed Key.a-z. Broke lots of stuff

* checkout@v4

* progress on key mapping and formatting

* VK tests are still failing

* Fixed some unit tests

* Added Hotkey and Keybinding unit tests

* fixed unit test

* All unit tests pass again...

* Fixed broken unit tests

* KeyEventArgs.KeyValue -> AsRune

* Fixed bugs. Still some broken

* Added KeyEventArgs.IsAlpha. Added KeyEventArgs.cast ops. Fixed bugs. Unit tests pass

* Fixed WindowsDriver

* Oops.

* Refactoring based on bdisp's help. Not complete!

* removed calling into subviews from OnKeyBindings

* removed calling into subviews from OnKeyBindings

* Improved View KeyEvent unit tests

* More hotkey unit tests

* BIg change - Got rid of KeyPress w/in Application/Drivers

* Unit tests now pass again

* Refreshed API docs

* Better HotKey logic. More progress. Getting close.

* Fixed handling of shifted chars like ö

* Minor code cleanup

* Minor code cleanup2

* Why is build Action failing?

* Why is build Action failing??

* upgraded to .net8 to try to fix weird CI/CD build errors

* upgraded to .net8 to try to fix weird CI/CD build errors2

* Disabling TextViewTests to diagnose build errors

* reenable TextViewTests to diagnose build errors

* Arrrrrrg

* Merged v2_develop

* Fixed uppercase accented keys in WindowsDriver

* Fixed key binding api docs

* Experimental impl of CommandScope.SubViews for MenuBar

* Removed dead code from application.cs

* Removed dead code from application.cs

* Removed dead code from ConsoleDriver.cs

* Cleaned up some key binding stuff

* Disabled Alt to activate menu for now

* Updated label commands

* Fixed menu bugs. Upgraded menu unit tests

* Fixed unit tests

* Working on NetDriver

* fixed netdriver

* Fixed issues called out by @bdisp CR

* fixed CursesDriver

* added todo to netdriver

* Cherry picked treeview test fix 1b415e5

* Fix NetDriver.

* CommandScope->KeyBindingScope

* Address some tznind feedback

* Refactored KeyBindings big time!

* Added key consts to KeyEventArgs and renamed Key to ConsoleDriverKey

* Fixed some API docs

* Moved ConsoleDriverKey to ConsoleDriver.cs

* Renamed Key->ConsoleDriverKey

* Renamed Key->ConsoleDriverKey

* Renamed Key->ConsoleDriverKey

* renamed file I forgot to rename before

* Updated name and API docs of KeyEventArgs.isAlpha

* Fixed issues with OnKeyUp not doing the right thing.

* Fixed MainLoop.Running never being used

* Fixed MainLoop.Running never being used - unit tests

* Claned up BUGBUG comments

* Disabled a unit test to see why ci/cd tests are failing

* Removed defunct commented code

* Removed more defunct commented code

* Re-eanbled unit test; jsut removing one test case...

* Disabled more...

* Renambed Global->Applicaton and updated scope API docs

* Disabled more unit tests...

* Removed dead code

* Disabled more unit tests...2

* Disabled more unit tests...3

* Renambed Global->Applicaton and updated scope API docs 2

* Added more KeyBinding scope tests

* Added more KeyBinding scope tests2

* ConsoleDriverKey too long. Key too ambiguous. Settled on KeyCode. (Partialy because eventually I want to intro a class named Key).

* KeyEventArgs improvements. cast to Rune must be explicit as it's lossy

* Fixed warnings

* Renamed KeyEventArgs to Key... progress on fixing broken stuff that resulted

* Fix ConsoleKeyMapping bugs.

* Fix NetDriver issue from converting a lower case to a upper case.

* Started migration to Key from KeyCode - e.g. made HotKeys all consistent.

* Fixed build warnings

* Added key defns to Key

* KeyBindings now uses Key vs. KeyCode

* Verified by tweaking UICatalog

* Fixed treeview test ... again

* Renamed ProcessKeyDown/Up to NewKeyDown/Up and OnKeyPressed to OnProcessKeyDown to make things more clear

* Added test AllViews_KeyDown_All_EventsFire unit tests and fixed a few Views that were wrong

* fixed stupid KeyUp event bug

* If key not handled, return false for datefield

* dotnet test --no-restore --verbosity diag

* dotnet test --blame

* run tests on windows

* Fix TestVKPacket unit test and move it to ConsoleKeyMappingTests.cs file.

* Remove unnecessary commented code.

* Tweaked unit tests and removed Key.BareKey

* Fixed little details and updated api docs

* updated api docs

* AddKeyBindingsForHotKey: KeyCode->Key

* Cleaned up more old KeyCode usages. Added TODOs

---------

Co-authored-by: BDisp <bd.bdisp@gmail.com>
2023-12-16 12:04:23 -07:00

595 lines
17 KiB
C#

using System.Text;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using Terminal.Gui;
using UICatalog;
using UICatalog.Scenarios;
using Xunit;
using Xunit.Abstractions;
// Alias Console to MockConsole so we don't accidentally use Console
using Console = Terminal.Gui.FakeConsole;
namespace UICatalog.Tests {
public class ScenarioTests {
readonly ITestOutputHelper output;
public ScenarioTests (ITestOutputHelper output)
{
#if DEBUG_IDISPOSABLE
Responder.Instances.Clear ();
#endif
this.output = output;
}
int CreateInput (string input)
{
FakeConsole.MockKeyPresses.Clear ();
// Put a QuitKey in at the end
FakeConsole.PushMockKeyPress ((KeyCode)Application.QuitKey);
foreach (var c in input.Reverse ()) {
KeyCode key = KeyCode.Unknown;
if (char.IsLetter (c)) {
key = (KeyCode)char.ToUpper (c) | (char.IsUpper (c) ? KeyCode.ShiftMask : (KeyCode)0);
} else {
key = (KeyCode)c;
}
FakeConsole.PushMockKeyPress (key);
}
return FakeConsole.MockKeyPresses.Count;
}
/// <summary>
/// <para>
/// This runs through all Scenarios defined in UI Catalog, calling Init, Setup, and Run.
/// </para>
/// <para>
/// Should find any Scenarios which crash on load or do not respond to <see cref="Application.RequestStop()"/>.
/// </para>
/// </summary>
[Fact]
public void Run_All_Scenarios ()
{
List<Scenario> scenarios = Scenario.GetScenarios ();
Assert.NotEmpty (scenarios);
foreach (var scenario in scenarios) {
output.WriteLine ($"Running Scenario '{scenario.GetName ()}'");
Application.Init (new FakeDriver ());
// Press QuitKey
Assert.Empty (FakeConsole.MockKeyPresses);
// BUGBUG: (#2474) For some reason ReadKey is not returning the QuitKey for some Scenarios
// by adding this Space it seems to work.
//FakeConsole.PushMockKeyPress (Key.Space);
FakeConsole.PushMockKeyPress ((KeyCode)Application.QuitKey);
// The only key we care about is the QuitKey
Application.Top.KeyDown += (object sender, Key args) => {
output.WriteLine ($" Keypress: {args.KeyCode}");
// BUGBUG: (#2474) For some reason ReadKey is not returning the QuitKey for some Scenarios
// by adding this Space it seems to work.
// See #2474 for why this is commented out
Assert.Equal (Application.QuitKey.KeyCode, args.KeyCode);
};
uint abortTime = 500;
// If the scenario doesn't close within 500ms, this will force it to quit
Func<bool> forceCloseCallback = () => {
if (Application.Top.Running && FakeConsole.MockKeyPresses.Count == 0) {
Application.RequestStop ();
// See #2474 for why this is commented out
Assert.Fail ($"'{scenario.GetName ()}' failed to Quit with {Application.QuitKey} after {abortTime}ms. Force quit.");
}
return false;
};
//output.WriteLine ($" Add timeout to force quit after {abortTime}ms");
_ = Application.AddTimeout (TimeSpan.FromMilliseconds (abortTime), forceCloseCallback);
Application.Iteration += (s, a) => {
//output.WriteLine ($" iteration {++iterations}");
if (Application.Top.Running && FakeConsole.MockKeyPresses.Count == 0) {
Application.RequestStop ();
Assert.Fail ($"'{scenario.GetName ()}' failed to Quit with {Application.QuitKey}. Force quit.");
}
};
scenario.Init ();
scenario.Setup ();
scenario.Run ();
scenario.Dispose ();
Application.Shutdown ();
#if DEBUG_IDISPOSABLE
Assert.Empty (Responder.Instances);
#endif
}
#if DEBUG_IDISPOSABLE
Assert.Empty (Responder.Instances);
#endif
}
[Fact]
public void Run_Generic ()
{
List<Scenario> scenarios = Scenario.GetScenarios ();
Assert.NotEmpty (scenarios);
var item = scenarios.FindIndex (s => s.GetName ().Equals ("Generic", StringComparison.OrdinalIgnoreCase));
var generic = scenarios [item];
Application.Init (new FakeDriver ());
// BUGBUG: (#2474) For some reason ReadKey is not returning the QuitKey for some Scenarios
// by adding this Space it seems to work.
FakeConsole.PushMockKeyPress ((KeyCode)Application.QuitKey);
var ms = 100;
var abortCount = 0;
Func<bool> abortCallback = () => {
abortCount++;
output.WriteLine ($"'Generic' abortCount {abortCount}");
Application.RequestStop ();
return false;
};
int iterations = 0;
object token = null;
Application.Iteration += (s, a) => {
if (token == null) {
// Timeout only must start at first iteration
token = Application.MainLoop.AddTimeout (TimeSpan.FromMilliseconds (ms), abortCallback);
}
iterations++;
output.WriteLine ($"'Generic' iteration {iterations}");
// Stop if we run out of control...
if (iterations == 10) {
output.WriteLine ($"'Generic' had to be force quit!");
Application.RequestStop ();
}
};
Application.Top.KeyDown += (object sender, Key args) => {
// See #2474 for why this is commented out
Assert.Equal (KeyCode.CtrlMask | KeyCode.Q, args.KeyCode);
};
generic.Init ();
generic.Setup ();
generic.Run ();
Assert.Equal (0, abortCount);
// # of key up events should match # of iterations
Assert.Equal (1, iterations);
generic.Dispose ();
// Shutdown must be called to safely clean up Application if Init has been called
Application.Shutdown ();
#if DEBUG_IDISPOSABLE
Assert.Empty (Responder.Instances);
#endif
}
[Fact]
public void Run_All_Views_Tester_Scenario ()
{
Window _leftPane;
ListView _classListView;
FrameView _hostPane;
Dictionary<string, Type> _viewClasses;
View _curView = null;
// Settings
FrameView _settingsPane;
CheckBox _computedCheckBox;
FrameView _locationFrame;
RadioGroup _xRadioGroup;
TextField _xText;
int _xVal = 0;
RadioGroup _yRadioGroup;
TextField _yText;
int _yVal = 0;
FrameView _sizeFrame;
RadioGroup _wRadioGroup;
TextField _wText;
int _wVal = 0;
RadioGroup _hRadioGroup;
TextField _hText;
int _hVal = 0;
List<string> posNames = new List<String> { "Factor", "AnchorEnd", "Center", "Absolute" };
List<string> dimNames = new List<String> { "Factor", "Fill", "Absolute" };
Application.Init (new FakeDriver ());
var Top = Application.Top;
_viewClasses = GetAllViewClassesCollection ()
.OrderBy (t => t.Name)
.Select (t => new KeyValuePair<string, Type> (t.Name, t))
.ToDictionary (t => t.Key, t => t.Value);
_leftPane = new Window () {
Title = "Classes",
X = 0,
Y = 0,
Width = 15,
Height = Dim.Fill (1), // for status bar
CanFocus = false,
ColorScheme = Colors.TopLevel,
};
_classListView = new ListView (_viewClasses.Keys.ToList ()) {
X = 0,
Y = 0,
Width = Dim.Fill (0),
Height = Dim.Fill (0),
AllowsMarking = false,
ColorScheme = Colors.TopLevel,
};
_leftPane.Add (_classListView);
_settingsPane = new FrameView ("Settings") {
X = Pos.Right (_leftPane),
Y = 0, // for menu
Width = Dim.Fill (),
Height = 10,
CanFocus = false,
ColorScheme = Colors.TopLevel,
};
_computedCheckBox = new CheckBox ("Computed Layout", true) { X = 0, Y = 0 };
_settingsPane.Add (_computedCheckBox);
var radioItems = new string [] { "Percent(x)", "AnchorEnd(x)", "Center", "At(x)" };
_locationFrame = new FrameView ("Location (Pos)") {
X = Pos.Left (_computedCheckBox),
Y = Pos.Bottom (_computedCheckBox),
Height = 3 + radioItems.Length,
Width = 36,
};
_settingsPane.Add (_locationFrame);
var label = new Label ("x:") { X = 0, Y = 0 };
_locationFrame.Add (label);
_xRadioGroup = new RadioGroup (radioItems) {
X = 0,
Y = Pos.Bottom (label),
};
_xText = new TextField ($"{_xVal}") { X = Pos.Right (label) + 1, Y = 0, Width = 4 };
_locationFrame.Add (_xText);
_locationFrame.Add (_xRadioGroup);
radioItems = new string [] { "Percent(y)", "AnchorEnd(y)", "Center", "At(y)" };
label = new Label ("y:") { X = Pos.Right (_xRadioGroup) + 1, Y = 0 };
_locationFrame.Add (label);
_yText = new TextField ($"{_yVal}") { X = Pos.Right (label) + 1, Y = 0, Width = 4 };
_locationFrame.Add (_yText);
_yRadioGroup = new RadioGroup (radioItems) {
X = Pos.X (label),
Y = Pos.Bottom (label),
};
_locationFrame.Add (_yRadioGroup);
_sizeFrame = new FrameView ("Size (Dim)") {
X = Pos.Right (_locationFrame),
Y = Pos.Y (_locationFrame),
Height = 3 + radioItems.Length,
Width = 40,
};
radioItems = new string [] { "Percent(width)", "Fill(width)", "Sized(width)" };
label = new Label ("width:") { X = 0, Y = 0 };
_sizeFrame.Add (label);
_wRadioGroup = new RadioGroup (radioItems) {
X = 0,
Y = Pos.Bottom (label),
};
_wText = new TextField ($"{_wVal}") { X = Pos.Right (label) + 1, Y = 0, Width = 4 };
_sizeFrame.Add (_wText);
_sizeFrame.Add (_wRadioGroup);
radioItems = new string [] { "Percent(height)", "Fill(height)", "Sized(height)" };
label = new Label ("height:") { X = Pos.Right (_wRadioGroup) + 1, Y = 0 };
_sizeFrame.Add (label);
_hText = new TextField ($"{_hVal}") { X = Pos.Right (label) + 1, Y = 0, Width = 4 };
_sizeFrame.Add (_hText);
_hRadioGroup = new RadioGroup (radioItems) {
X = Pos.X (label),
Y = Pos.Bottom (label),
};
_sizeFrame.Add (_hRadioGroup);
_settingsPane.Add (_sizeFrame);
_hostPane = new FrameView ("") {
X = Pos.Right (_leftPane),
Y = Pos.Bottom (_settingsPane),
Width = Dim.Fill (),
Height = Dim.Fill (1), // + 1 for status bar
ColorScheme = Colors.Dialog,
};
_classListView.OpenSelectedItem += (s, a) => {
_settingsPane.SetFocus ();
};
_classListView.SelectedItemChanged += (s, args) => {
// Remove existing class, if any
if (_curView != null) {
_curView.LayoutComplete -= LayoutCompleteHandler;
_hostPane.Remove (_curView);
_curView.Dispose ();
_curView = null;
_hostPane.Clear ();
}
_curView = CreateClass (_viewClasses.Values.ToArray () [_classListView.SelectedItem]);
};
_computedCheckBox.Toggled += (s, e) => {
if (_curView != null) {
_curView.LayoutStyle = e.OldValue == true ? LayoutStyle.Absolute : LayoutStyle.Computed;
_hostPane.LayoutSubviews ();
}
};
_xRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (_curView);
_xText.TextChanged += (s, args) => {
try {
_xVal = int.Parse (_xText.Text);
DimPosChanged (_curView);
} catch {
}
};
_yText.TextChanged += (s, e) => {
try {
_yVal = int.Parse (_yText.Text);
DimPosChanged (_curView);
} catch {
}
};
_yRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (_curView);
_wRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (_curView);
_wText.TextChanged += (s, args) => {
try {
_wVal = int.Parse (_wText.Text);
DimPosChanged (_curView);
} catch {
}
};
_hText.TextChanged += (s, args) => {
try {
_hVal = int.Parse (_hText.Text);
DimPosChanged (_curView);
} catch {
}
};
_hRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (_curView);
Top.Add (_leftPane, _settingsPane, _hostPane);
Top.LayoutSubviews ();
_curView = CreateClass (_viewClasses.First ().Value);
int iterations = 0;
Application.Iteration += (s, a) => {
iterations++;
if (iterations < _viewClasses.Count) {
_classListView.MoveDown ();
Assert.Equal (_curView.GetType ().Name,
_viewClasses.Values.ToArray () [_classListView.SelectedItem].Name);
} else {
Application.RequestStop ();
}
};
Application.Run ();
Assert.Equal (_viewClasses.Count, iterations);
Application.Shutdown ();
void DimPosChanged (View view)
{
if (view == null) {
return;
}
var layout = view.LayoutStyle;
try {
view.LayoutStyle = LayoutStyle.Absolute;
switch (_xRadioGroup.SelectedItem) {
case 0:
view.X = Pos.Percent (_xVal);
break;
case 1:
view.X = Pos.AnchorEnd (_xVal);
break;
case 2:
view.X = Pos.Center ();
break;
case 3:
view.X = Pos.At (_xVal);
break;
}
switch (_yRadioGroup.SelectedItem) {
case 0:
view.Y = Pos.Percent (_yVal);
break;
case 1:
view.Y = Pos.AnchorEnd (_yVal);
break;
case 2:
view.Y = Pos.Center ();
break;
case 3:
view.Y = Pos.At (_yVal);
break;
}
switch (_wRadioGroup.SelectedItem) {
case 0:
view.Width = Dim.Percent (_wVal);
break;
case 1:
view.Width = Dim.Fill (_wVal);
break;
case 2:
view.Width = Dim.Sized (_wVal);
break;
}
switch (_hRadioGroup.SelectedItem) {
case 0:
view.Height = Dim.Percent (_hVal);
break;
case 1:
view.Height = Dim.Fill (_hVal);
break;
case 2:
view.Height = Dim.Sized (_hVal);
break;
}
} catch (Exception e) {
MessageBox.ErrorQuery ("Exception", e.Message, "Ok");
} finally {
view.LayoutStyle = layout;
}
UpdateTitle (view);
}
void UpdateSettings (View view)
{
var x = view.X.ToString ();
var y = view.Y.ToString ();
_xRadioGroup.SelectedItem = posNames.IndexOf (posNames.Where (s => x.Contains (s)).First ());
_yRadioGroup.SelectedItem = posNames.IndexOf (posNames.Where (s => y.Contains (s)).First ());
_xText.Text = $"{view.Frame.X}";
_yText.Text = $"{view.Frame.Y}";
var w = view.Width.ToString ();
var h = view.Height.ToString ();
_wRadioGroup.SelectedItem = dimNames.IndexOf (dimNames.Where (s => w.Contains (s)).First ());
_hRadioGroup.SelectedItem = dimNames.IndexOf (dimNames.Where (s => h.Contains (s)).First ());
_wText.Text = $"{view.Frame.Width}";
_hText.Text = $"{view.Frame.Height}";
}
void UpdateTitle (View view)
{
_hostPane.Title = $"{view.GetType ().Name} - {view.X.ToString ()}, {view.Y.ToString ()}, {view.Width.ToString ()}, {view.Height.ToString ()}";
}
List<Type> GetAllViewClassesCollection ()
{
List<Type> types = new List<Type> ();
foreach (Type type in typeof (View).Assembly.GetTypes ()
.Where (myType => myType.IsClass && !myType.IsAbstract && myType.IsPublic && myType.IsSubclassOf (typeof (View)))) {
types.Add (type);
}
return types;
}
View CreateClass (Type type)
{
// If we are to create a generic Type
if (type.IsGenericType) {
// For each of the <T> arguments
List<Type> typeArguments = new List<Type> ();
// use <object>
foreach (var arg in type.GetGenericArguments ()) {
typeArguments.Add (typeof (object));
}
// And change what type we are instantiating from MyClass<T> to MyClass<object>
type = type.MakeGenericType (typeArguments.ToArray ());
}
// Instantiate view
var view = (View)Activator.CreateInstance (type);
//_curView.X = Pos.Center ();
//_curView.Y = Pos.Center ();
view.Width = Dim.Percent (75);
view.Height = Dim.Percent (75);
// Set the colorscheme to make it stand out if is null by default
if (view.ColorScheme == null) {
view.ColorScheme = Colors.Base;
}
// If the view supports a Text property, set it so we have something to look at
if (view.GetType ().GetProperty ("Text") != null) {
try {
view.GetType ().GetProperty ("Text")?.GetSetMethod ()?.Invoke (view, new [] { "Test Text" });
} catch (TargetInvocationException e) {
MessageBox.ErrorQuery ("Exception", e.InnerException.Message, "Ok");
view = null;
}
}
// If the view supports a Title property, set it so we have something to look at
if (view != null && view.GetType ().GetProperty ("Title") != null) {
if (view.GetType ().GetProperty ("Title").PropertyType == typeof (string)) {
view?.GetType ().GetProperty ("Title")?.GetSetMethod ()?.Invoke (view, new [] { "Test Title" });
} else {
view?.GetType ().GetProperty ("Title")?.GetSetMethod ()?.Invoke (view, new [] { "Test Title" });
}
}
// If the view supports a Source property, set it so we have something to look at
if (view != null && view.GetType ().GetProperty ("Source") != null && view.GetType ().GetProperty ("Source").PropertyType == typeof (Terminal.Gui.IListDataSource)) {
var source = new ListWrapper (new List<string> () { "Test Text #1", "Test Text #2", "Test Text #3" });
view?.GetType ().GetProperty ("Source")?.GetSetMethod ()?.Invoke (view, new [] { source });
}
// Set Settings
_computedCheckBox.Checked = view.LayoutStyle == LayoutStyle.Computed;
// Add
_hostPane.Add (view);
//DimPosChanged ();
_hostPane.LayoutSubviews ();
_hostPane.Clear ();
_hostPane.SetNeedsDisplay ();
UpdateSettings (view);
UpdateTitle (view);
view.LayoutComplete += LayoutCompleteHandler;
return view;
}
void LayoutCompleteHandler (object sender, LayoutEventArgs args)
{
UpdateTitle (_curView);
}
}
}
}