-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunnableExtensions.cs
More file actions
47 lines (43 loc) · 1.97 KB
/
Copy pathRunnableExtensions.cs
File metadata and controls
47 lines (43 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using Terminal.Gui.App;
using Terminal.Gui.Views;
namespace TerminalGui.Extensions.Extensions;
/// <summary>
/// Extension methods for <see cref="Runnable" />.
/// </summary>
public static class RunnableExtensions
{
extension(Runnable runnable)
{
/// <summary>
/// Subscribes to the <see cref="Runnable.IsRunningChanged" /> event.
/// </summary>
/// <param name="callback">The callback to invoke with the <see cref="EventArgs{T}" /> containing the new running state.</param>
/// <returns>The <see cref="Runnable" /> instance.</returns>
public Runnable OnRunningChanged(Action<EventArgs<bool>> callback)
{
runnable.IsRunningChanged += (_, e) => callback(e);
return runnable;
}
/// <summary>
/// Subscribes to the <see cref="Runnable.IsRunningChanging" /> event.
/// Set <see cref="CancelEventArgs{T}.Cancel" /> to <see langword="true" /> in the callback to cancel the change.
/// </summary>
/// <param name="callback">The callback to invoke with the <see cref="CancelEventArgs{T}" /> containing the proposed running state.</param>
/// <returns>The <see cref="Runnable" /> instance.</returns>
public Runnable OnRunningChanging(Action<CancelEventArgs<bool>> callback)
{
runnable.IsRunningChanging += (_, e) => callback(e);
return runnable;
}
/// <summary>
/// Subscribes to the <see cref="Runnable.IsModalChanged" /> event.
/// </summary>
/// <param name="callback">The callback to invoke with the <see cref="EventArgs{T}" /> containing the new modal state.</param>
/// <returns>The <see cref="Runnable" /> instance.</returns>
public Runnable OnModalChanged(Action<EventArgs<bool>> callback)
{
runnable.IsModalChanged += (_, e) => callback(e);
return runnable;
}
}
}