mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
Change AutoSpin from a method to a property
This commit is contained in:
@@ -190,9 +190,23 @@ namespace Terminal.Gui {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Automates spinning
|
||||
/// Gets or sets whether spinning should occur automatically or be manually
|
||||
/// triggered (e.g. from a background task).
|
||||
/// </summary>
|
||||
public void AutoSpin ()
|
||||
public bool AutoSpin {
|
||||
get {
|
||||
return _timeout != null;
|
||||
}
|
||||
set {
|
||||
if (value) {
|
||||
AddAutoSpinTimeout ();
|
||||
} else {
|
||||
RemoveAutoSpinTimeout ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void AddAutoSpinTimeout ()
|
||||
{
|
||||
if (_timeout != null) {
|
||||
return;
|
||||
@@ -205,13 +219,22 @@ namespace Terminal.Gui {
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void Dispose (bool disposing)
|
||||
|
||||
private void RemoveAutoSpinTimeout ()
|
||||
{
|
||||
if (_timeout != null) {
|
||||
Application.MainLoop.RemoveTimeout (_timeout);
|
||||
_timeout = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void Dispose (bool disposing)
|
||||
{
|
||||
RemoveAutoSpinTimeout ();
|
||||
|
||||
base.Dispose (disposing);
|
||||
}
|
||||
|
||||
@@ -516,7 +516,7 @@ class CharMap : ScrollView {
|
||||
Style = new SpinnerStyle.Aesthetic (),
|
||||
|
||||
};
|
||||
spinner.AutoSpin ();
|
||||
spinner.AutoSpin = true;
|
||||
waitIndicator.Add (errorLabel);
|
||||
waitIndicator.Add (spinner);
|
||||
waitIndicator.Ready += async (s, a) => {
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace UICatalog.Scenarios {
|
||||
Y = 0
|
||||
};
|
||||
preview.Add (spinner);
|
||||
spinner.AutoSpin ();
|
||||
spinner.AutoSpin = true;
|
||||
|
||||
var ckbAscii = new CheckBox ("Ascii Only", false) {
|
||||
X = Pos.Center () - 7,
|
||||
|
||||
@@ -13,24 +13,33 @@ namespace Terminal.Gui.ViewsTests {
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void TestSpinnerView_AutoSpin()
|
||||
[Theory, AutoInitShutdown]
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
public void TestSpinnerView_AutoSpin(bool callStop)
|
||||
{
|
||||
var view = GetSpinnerView ();
|
||||
|
||||
Assert.Empty (Application.MainLoop.timeouts);
|
||||
view.AutoSpin ();
|
||||
view.AutoSpin = true;
|
||||
Assert.NotEmpty (Application.MainLoop.timeouts);
|
||||
|
||||
//More calls to AutoSpin do not add more timeouts
|
||||
Assert.Single (Application.MainLoop.timeouts);
|
||||
view.AutoSpin ();
|
||||
view.AutoSpin ();
|
||||
view.AutoSpin ();
|
||||
view.AutoSpin = true;
|
||||
view.AutoSpin = true;
|
||||
view.AutoSpin = true;
|
||||
Assert.Single (Application.MainLoop.timeouts);
|
||||
|
||||
if(callStop) {
|
||||
view.AutoSpin = false;
|
||||
Assert.Empty (Application.MainLoop.timeouts);
|
||||
}
|
||||
else {
|
||||
Assert.NotEmpty (Application.MainLoop.timeouts);
|
||||
}
|
||||
|
||||
// Dispose clears timeout
|
||||
Assert.NotEmpty (Application.MainLoop.timeouts);
|
||||
view.Dispose ();
|
||||
Assert.Empty (Application.MainLoop.timeouts);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user