Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Form.ShowAsync #2706

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Eto/Forms/Form.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ public void Show()
base.Visible = true;
}
}

/// <summary>
/// Shows the form with a task that can be awaited until it is closed
/// </summary>
/// <returns>Task that completes when the form is closed.</returns>
public Task ShowAsync()
{
var tcs = new TaskCompletionSource<bool>();
Closed += (sender, e) => tcs.TrySetResult(true);
Show();
return tcs.Task;
}

/// <summary>
/// Interface handler for the <see cref="Form"/> control
Expand Down
8 changes: 1 addition & 7 deletions test/Eto.Test/UnitTests/Forms/FormTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@ public class FormTests : WindowTests<Form>
protected override void Test(Action<Form> test, int timeout = 4000) => Form(test, timeout);
protected override void ManualTest(string message, Func<Form, Control> test) => ManualForm(message, test);
protected override void Show(Form window) => window.Show();
protected override Task ShowAsync(Form window)
{
var tcs = new TaskCompletionSource<bool>();
window.Closed += (sender, e) => tcs.TrySetResult(true);
window.Show();
return tcs.Task;
}
protected override Task ShowAsync(Form window) => window.ShowAsync();

[Test, ManualTest]
public void WindowShouldCloseOnLostFocusWithoutHidingParent()
Expand Down
Loading