This commit is contained in:
Charlie Kindel
2020-09-29 13:15:26 -07:00
4 changed files with 42 additions and 27 deletions

View File

@@ -27,7 +27,7 @@ jobs:
PACKAGE_NAME: Terminal.Gui
# Filepath with version info, relative to root of repository & defaults to PROJECT_FILE_PATH
VERSION_FILE_PATH: Directory.Build.props
VERSION_FILE_PATH: Terminal.Gui/Directory.Build.props
# Regex pattern to extract version info in a capturing group
VERSION_REGEX: ^\s*<Version>(.*)<\/Version>\s*$

View File

@@ -1,10 +0,0 @@
<Project>
<PropertyGroup>
<Version>0.90.0</Version>
<AssemblyVersion>0.90.0</AssemblyVersion>
<FileVersion>0.90.0</FileVersion>
<Authors>Miguel de Icaza, Charlie Kindel (@tig), @BDisp</Authors>
</PropertyGroup>
</Project>

View File

@@ -283,12 +283,15 @@ namespace Terminal.Gui {
public override bool CanFocus {
get => base.CanFocus;
set {
if (!addingView && IsInitialized && SuperView?.CanFocus == false && value) {
throw new InvalidOperationException ("Cannot set CanFocus to true if the SuperView CanFocus is false!");
}
if (base.CanFocus != value) {
base.CanFocus = value;
if (!value && tabIndex > -1) {
TabIndex = -1;
}
if (value && SuperView != null && !SuperView.CanFocus) {
if (value && SuperView?.CanFocus == false && addingView) {
SuperView.CanFocus = value;
}
if (value && tabIndex == -1) {
@@ -305,8 +308,12 @@ namespace Terminal.Gui {
view.CanFocus = value;
view.tabIndex = -1;
} else {
if (addingView) {
view.addingView = true;
}
view.CanFocus = view.oldCanFocus;
view.tabIndex = view.oldTabIndex;
view.addingView = false;
}
}
}
@@ -693,6 +700,8 @@ namespace Terminal.Gui {
container.ChildNeedsDisplay ();
}
internal bool addingView = false;
/// <summary>
/// Adds a subview (child) to this view.
/// </summary>
@@ -713,14 +722,22 @@ namespace Terminal.Gui {
tabIndexes.Add (view);
view.container = this;
if (view.CanFocus) {
addingView = true;
if (SuperView?.CanFocus == false) {
SuperView.addingView = true;
SuperView.CanFocus = true;
SuperView.addingView = false;
}
CanFocus = true;
view.tabIndex = tabIndexes.IndexOf (view);
addingView = false;
}
SetNeedsLayout ();
SetNeedsDisplay ();
OnAdded (view);
if (IsInitialized) {
view.BeginInit ();
view.EndInit ();
}
}
@@ -1985,7 +2002,6 @@ namespace Terminal.Gui {
if (!IsInitialized) {
oldCanFocus = CanFocus;
oldTabIndex = tabIndex;
Initialized?.Invoke (this, EventArgs.Empty);
}
if (subviews?.Count > 0) {
foreach (var view in subviews) {
@@ -2009,6 +2025,7 @@ namespace Terminal.Gui {
}
}
}
Initialized?.Invoke (this, EventArgs.Empty);
}
/// <summary>

View File

@@ -578,10 +578,10 @@ namespace Terminal.Gui {
t.Initialized += (s, e) => {
tc++;
Assert.Equal (1, tc);
Assert.Equal (0, wc);
Assert.Equal (0, v1c);
Assert.Equal (0, v2c);
Assert.Equal (0, sv1c);
Assert.Equal (1, wc);
Assert.Equal (1, v1c);
Assert.Equal (1, v2c);
Assert.Equal (1, sv1c);
Assert.True (t.CanFocus);
Assert.True (w.CanFocus);
@@ -611,8 +611,8 @@ namespace Terminal.Gui {
Assert.Equal (t.Frame.Width, sv1.Frame.Width);
Assert.Equal (t.Frame.Height, sv1.Frame.Height);
Assert.False (sv1.CanFocus);
sv1.CanFocus = true;
Assert.True (sv1.CanFocus);
Assert.Throws<InvalidOperationException> (() => sv1.CanFocus = true);
Assert.False (sv1.CanFocus);
};
v1.Add (sv1);
@@ -637,7 +637,10 @@ namespace Terminal.Gui {
Assert.True (w.CanFocus);
Assert.False (v1.CanFocus);
Assert.False (v2.CanFocus);
Assert.True (sv1.CanFocus);
Assert.False (sv1.CanFocus);
v1.CanFocus = true;
Assert.False (sv1.CanFocus); // False because sv1 was disposed and it isn't a subview of v1.
}
[Fact]
@@ -656,10 +659,10 @@ namespace Terminal.Gui {
t.Initialized += (s, e) => {
tc++;
Assert.Equal (1, tc);
Assert.Equal (0, wc);
Assert.Equal (0, v1c);
Assert.Equal (0, v2c);
Assert.Equal (0, sv1c);
Assert.Equal (1, wc);
Assert.Equal (1, v1c);
Assert.Equal (1, v2c);
Assert.Equal (0, sv1c); // Added after t in the Application.Iteration.
Assert.True (t.CanFocus);
Assert.True (w.CanFocus);
@@ -694,8 +697,8 @@ namespace Terminal.Gui {
Assert.NotEqual (t.Frame.Width, sv1.Frame.Width);
Assert.NotEqual (t.Frame.Height, sv1.Frame.Height);
Assert.False (sv1.CanFocus);
sv1.CanFocus = true;
Assert.True (sv1.CanFocus);
Assert.Throws<InvalidOperationException> (() => sv1.CanFocus = true);
Assert.False (sv1.CanFocus);
};
v1.Add (sv1);
@@ -813,7 +816,11 @@ namespace Terminal.Gui {
Assert.False (f.CanFocus);
Assert.False (v.CanFocus);
v.CanFocus = true;
Assert.Throws<InvalidOperationException> (() => v.CanFocus = true);
Assert.False (f.CanFocus);
Assert.False (v.CanFocus);
f.CanFocus = true;
Assert.True (f.CanFocus);
Assert.True (v.CanFocus);
};
@@ -1015,5 +1022,6 @@ namespace Terminal.Gui {
Application.Run ();
Application.Shutdown ();
}
}
}