Skip to content

Commit

Permalink
Add overloaded version of Add() methods for method returns a "Task".
Browse files Browse the repository at this point in the history
  • Loading branch information
jsakamoto committed Jan 27, 2024
1 parent 63e2195 commit 12cf97d
Showing 1 changed file with 176 additions and 0 deletions.
176 changes: 176 additions & 0 deletions HotKeys2/HotKeysContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ public HotKeysContext Add(Key key, Action<HotKeyEntryByKey> action, HotKeyOption
public HotKeysContext Add(Key key, Func<ValueTask> action, HotKeyOptions options)
=> this.AddInternal(ModKey.None, key, _ => action(), action.Target as IHandleEvent, options);

/// <summary>
/// Add a new hotkey entry to this context.
/// </summary>
/// <param name="key">The identifier of hotkey by key.</param>
/// <param name="action">The callback action that will be invoked when user enter the key without any modifiers on the browser.</param>
/// <param name="options">The options for this hotkey entry.</param>
/// <returns>This context.</returns>
public HotKeysContext Add(Key key, Func<Task> action, HotKeyOptions options)
=> this.AddInternal(ModKey.None, key, async _ => await action(), action.Target as IHandleEvent, options);

/// <summary>
/// Add a new hotkey entry to this context.
/// </summary>
Expand All @@ -69,6 +79,16 @@ public HotKeysContext Add(Key key, Func<ValueTask> action, HotKeyOptions options
public HotKeysContext Add(Key key, Func<HotKeyEntryByKey, ValueTask> action, HotKeyOptions options)
=> this.AddInternal(ModKey.None, key, arg => action(arg), action.Target as IHandleEvent, options);

/// <summary>
/// Add a new hotkey entry to this context.
/// </summary>
/// <param name="key">The identifier of hotkey by key.</param>
/// <param name="action">The callback action that will be invoked when user enter the key without any modifiers on the browser.</param>
/// <param name="options">The options for this hotkey entry.</param>
/// <returns>This context.</returns>
public HotKeysContext Add(Key key, Func<HotKeyEntryByKey, Task> action, HotKeyOptions options)
=> this.AddInternal(ModKey.None, key, async arg => await action(arg), action.Target as IHandleEvent, options);

/// <summary>
/// Add a new hotkey entry to this context.
/// </summary>
Expand Down Expand Up @@ -102,6 +122,17 @@ public HotKeysContext Add(Key key, Action<HotKeyEntryByKey> action, string descr
public HotKeysContext Add(Key key, Func<ValueTask> action, string description = "", Exclude exclude = Exclude.Default)
=> this.AddInternal(ModKey.None, key, _ => action(), action.Target as IHandleEvent, new() { Description = description, Exclude = exclude });

/// <summary>
/// Add a new hotkey entry to this context.
/// </summary>
/// <param name="key">The identifier of hotkey by key.</param>
/// <param name="action">The callback action that will be invoked when user enter the key without any modifiers on the browser.</param>
/// <param name="exclude">The combination of HTML element flags that will be not allowed hotkey works.</param>
/// <param name="description">The description of the meaning of this hot key entry.</param>
/// <returns>This context.</returns>
public HotKeysContext Add(Key key, Func<Task> action, string description = "", Exclude exclude = Exclude.Default)
=> this.AddInternal(ModKey.None, key, async _ => await action(), action.Target as IHandleEvent, new() { Description = description, Exclude = exclude });

/// <summary>
/// Add a new hotkey entry to this context.
/// </summary>
Expand All @@ -113,6 +144,17 @@ public HotKeysContext Add(Key key, Func<ValueTask> action, string description =
public HotKeysContext Add(Key key, Func<HotKeyEntryByKey, ValueTask> action, string description = "", Exclude exclude = Exclude.Default)
=> this.AddInternal(ModKey.None, key, arg => action(arg), action.Target as IHandleEvent, new() { Description = description, Exclude = exclude });

/// <summary>
/// Add a new hotkey entry to this context.
/// </summary>
/// <param name="key">The identifier of hotkey by key.</param>
/// <param name="action">The callback action that will be invoked when user enter the key without any modifiers on the browser.</param>
/// <param name="exclude">The combination of HTML element flags that will be not allowed hotkey works.</param>
/// <param name="description">The description of the meaning of this hot key entry.</param>
/// <returns>This context.</returns>
public HotKeysContext Add(Key key, Func<HotKeyEntryByKey, Task> action, string description = "", Exclude exclude = Exclude.Default)
=> this.AddInternal(ModKey.None, key, async arg => await action(arg), action.Target as IHandleEvent, new() { Description = description, Exclude = exclude });

// -----------------------------------------------------------------------------------------------

/// <summary>
Expand Down Expand Up @@ -148,6 +190,17 @@ public HotKeysContext Add(ModKey modifiers, Key key, Action<HotKeyEntryByKey> ac
public HotKeysContext Add(ModKey modifiers, Key key, Func<ValueTask> action, HotKeyOptions options)
=> this.AddInternal(modifiers, key, _ => action(), action.Target as IHandleEvent, options);

/// <summary>
/// Add a new hotkey entry to this context.
/// </summary>
/// <param name="modifiers">The combination of modifier keys flags.</param>
/// <param name="key">The identifier of hotkey by key.</param>
/// <param name="action">The callback action that will be invoked when user enter modifiers + key combination on the browser.</param>
/// <param name="options">The options for this hotkey entry.</param>
/// <returns>This context.</returns>
public HotKeysContext Add(ModKey modifiers, Key key, Func<Task> action, HotKeyOptions options)
=> this.AddInternal(modifiers, key, async _ => await action(), action.Target as IHandleEvent, options);

/// <summary>
/// Add a new hotkey entry to this context.
/// </summary>
Expand All @@ -159,6 +212,17 @@ public HotKeysContext Add(ModKey modifiers, Key key, Func<ValueTask> action, Hot
public HotKeysContext Add(ModKey modifiers, Key key, Func<HotKeyEntryByKey, ValueTask> action, HotKeyOptions options)
=> this.AddInternal(modifiers, key, action, action.Target as IHandleEvent, options);

/// <summary>
/// Add a new hotkey entry to this context.
/// </summary>
/// <param name="modifiers">The combination of modifier keys flags.</param>
/// <param name="key">The identifier of hotkey by key.</param>
/// <param name="action">The callback action that will be invoked when user enter modifiers + key combination on the browser.</param>
/// <param name="options">The options for this hotkey entry.</param>
/// <returns>This context.</returns>
public HotKeysContext Add(ModKey modifiers, Key key, Func<HotKeyEntryByKey, Task> action, HotKeyOptions options)
=> this.AddInternal(modifiers, key, async arg => await action(arg), action.Target as IHandleEvent, options);

/// <summary>
/// Add a new hotkey entry to this context.
/// </summary>
Expand Down Expand Up @@ -195,6 +259,18 @@ public HotKeysContext Add(ModKey modifiers, Key key, Action<HotKeyEntryByKey> ac
public HotKeysContext Add(ModKey modifiers, Key key, Func<ValueTask> action, string description = "", Exclude exclude = Exclude.Default)
=> this.AddInternal(modifiers, key, _ => action(), action.Target as IHandleEvent, new() { Description = description, Exclude = exclude });

/// <summary>
/// Add a new hotkey entry to this context.
/// </summary>
/// <param name="modifiers">The combination of modifier keys flags.</param>
/// <param name="key">The identifier of hotkey by key.</param>
/// <param name="action">The callback action that will be invoked when user enter modifiers + key combination on the browser.</param>
/// <param name="exclude">The combination of HTML element flags that will be not allowed hotkey works.</param>
/// <param name="description">The description of the meaning of this hot key entry.</param>
/// <returns>This context.</returns>
public HotKeysContext Add(ModKey modifiers, Key key, Func<Task> action, string description = "", Exclude exclude = Exclude.Default)
=> this.AddInternal(modifiers, key, async _ => await action(), action.Target as IHandleEvent, new() { Description = description, Exclude = exclude });

/// <summary>
/// Add a new hotkey entry to this context.
/// </summary>
Expand All @@ -207,6 +283,18 @@ public HotKeysContext Add(ModKey modifiers, Key key, Func<ValueTask> action, str
public HotKeysContext Add(ModKey modifiers, Key key, Func<HotKeyEntryByKey, ValueTask> action, string description = "", Exclude exclude = Exclude.Default)
=> this.AddInternal(modifiers, key, action, action.Target as IHandleEvent, new() { Description = description, Exclude = exclude });

/// <summary>
/// Add a new hotkey entry to this context.
/// </summary>
/// <param name="modifiers">The combination of modifier keys flags.</param>
/// <param name="key">The identifier of hotkey by key.</param>
/// <param name="action">The callback action that will be invoked when user enter modifiers + key combination on the browser.</param>
/// <param name="description">The description of the meaning of this hot key entry.</param>
/// <param name="exclude">The combination of HTML element flags that will be not allowed hotkey works.</param>
/// <returns>This context.</returns>
public HotKeysContext Add(ModKey modifiers, Key key, Func<HotKeyEntryByKey, Task> action, string description = "", Exclude exclude = Exclude.Default)
=> this.AddInternal(modifiers, key, async arg => await action(arg), action.Target as IHandleEvent, new() { Description = description, Exclude = exclude });

/// <summary>
/// Add a new hotkey entry to this context.
/// </summary>
Expand Down Expand Up @@ -254,6 +342,16 @@ public HotKeysContext Add(Code code, Action<HotKeyEntryByCode> action, HotKeyOpt
public HotKeysContext Add(Code code, Func<ValueTask> action, HotKeyOptions options)
=> this.AddInternal(ModCode.None, code, _ => action(), action.Target as IHandleEvent, options);

/// <summary>
/// Add a new hotkey entry to this context.
/// </summary>
/// <param name="code">The identifier of hotkey by code.</param>
/// <param name="action">The callback action that will be invoked when user enter the key without any modifiers on the browser.</param>
/// <param name="options">The options for this hotkey entry.</param>
/// <returns>This context.</returns>
public HotKeysContext Add(Code code, Func<Task> action, HotKeyOptions options)
=> this.AddInternal(ModCode.None, code, async _ => await action(), action.Target as IHandleEvent, options);

/// <summary>
/// Add a new hotkey entry to this context.
/// </summary>
Expand All @@ -264,6 +362,16 @@ public HotKeysContext Add(Code code, Func<ValueTask> action, HotKeyOptions optio
public HotKeysContext Add(Code code, Func<HotKeyEntryByCode, ValueTask> action, HotKeyOptions options)
=> this.AddInternal(ModCode.None, code, action, action.Target as IHandleEvent, options);

/// <summary>
/// Add a new hotkey entry to this context.
/// </summary>
/// <param name="code">The identifier of hotkey by code.</param>
/// <param name="action">The callback action that will be invoked when user enter the key without any modifiers on the browser.</param>
/// <param name="options">The options for this hotkey entry.</param>
/// <returns>This context.</returns>
public HotKeysContext Add(Code code, Func<HotKeyEntryByCode, Task> action, HotKeyOptions options)
=> this.AddInternal(ModCode.None, code, async arg => await action(arg), action.Target as IHandleEvent, options);

/// <summary>
/// Add a new hotkey entry to this context.
/// </summary>
Expand Down Expand Up @@ -297,6 +405,17 @@ public HotKeysContext Add(Code code, Action<HotKeyEntryByCode> action, string de
public HotKeysContext Add(Code code, Func<ValueTask> action, string description = "", Exclude exclude = Exclude.Default)
=> this.AddInternal(ModCode.None, code, _ => action(), action.Target as IHandleEvent, new() { Description = description, Exclude = exclude });

/// <summary>
/// Add a new hotkey entry to this context.
/// </summary>
/// <param name="code">The identifier of hotkey by code.</param>
/// <param name="action">The callback action that will be invoked when user enter the key without any modifiers on the browser.</param>
/// <param name="exclude">The combination of HTML element flags that will be not allowed hotkey works.</param>
/// <param name="description">The description of the meaning of this hot key entry.</param>
/// <returns>This context.</returns>
public HotKeysContext Add(Code code, Func<Task> action, string description = "", Exclude exclude = Exclude.Default)
=> this.AddInternal(ModCode.None, code, async _ => await action(), action.Target as IHandleEvent, new() { Description = description, Exclude = exclude });

/// <summary>
/// Add a new hotkey entry to this context.
/// </summary>
Expand All @@ -308,6 +427,17 @@ public HotKeysContext Add(Code code, Func<ValueTask> action, string description
public HotKeysContext Add(Code code, Func<HotKeyEntryByCode, ValueTask> action, string description = "", Exclude exclude = Exclude.Default)
=> this.AddInternal(ModCode.None, code, action, action.Target as IHandleEvent, new() { Description = description, Exclude = exclude });

/// <summary>
/// Add a new hotkey entry to this context.
/// </summary>
/// <param name="code">The identifier of hotkey by code.</param>
/// <param name="action">The callback action that will be invoked when user enter the key without any modifiers on the browser.</param>
/// <param name="exclude">The combination of HTML element flags that will be not allowed hotkey works.</param>
/// <param name="description">The description of the meaning of this hot key entry.</param>
/// <returns>This context.</returns>
public HotKeysContext Add(Code code, Func<HotKeyEntryByCode, Task> action, string description = "", Exclude exclude = Exclude.Default)
=> this.AddInternal(ModCode.None, code, async arg => await action(arg), action.Target as IHandleEvent, new() { Description = description, Exclude = exclude });

// -----------------------------------------------------------------------------------------------

/// <summary>
Expand Down Expand Up @@ -343,6 +473,17 @@ public HotKeysContext Add(ModCode modifiers, Code code, Action<HotKeyEntryByCode
public HotKeysContext Add(ModCode modifiers, Code code, Func<ValueTask> action, HotKeyOptions options)
=> this.AddInternal(modifiers, code, _ => action(), action.Target as IHandleEvent, options);

/// <summary>
/// Add a new hotkey entry to this context.
/// </summary>
/// <param name="modifiers">The combination of modifier keys flags.</param>
/// <param name="code">The identifier of hotkey by code.</param>
/// <param name="action">The callback action that will be invoked when user enter modifiers + key combination on the browser.</param>
/// <param name="options">The options for this hotkey entry.</param>
/// <returns>This context.</returns>
public HotKeysContext Add(ModCode modifiers, Code code, Func<Task> action, HotKeyOptions options)
=> this.AddInternal(modifiers, code, async _ => await action(), action.Target as IHandleEvent, options);

/// <summary>
/// Add a new hotkey entry to this context.
/// </summary>
Expand All @@ -354,6 +495,17 @@ public HotKeysContext Add(ModCode modifiers, Code code, Func<ValueTask> action,
public HotKeysContext Add(ModCode modifiers, Code code, Func<HotKeyEntryByCode, ValueTask> action, HotKeyOptions options)
=> this.AddInternal(modifiers, code, action, action.Target as IHandleEvent, options);

/// <summary>
/// Add a new hotkey entry to this context.
/// </summary>
/// <param name="modifiers">The combination of modifier keys flags.</param>
/// <param name="code">The identifier of hotkey by code.</param>
/// <param name="action">The callback action that will be invoked when user enter modifiers + key combination on the browser.</param>
/// <param name="options">The options for this hotkey entry.</param>
/// <returns>This context.</returns>
public HotKeysContext Add(ModCode modifiers, Code code, Func<HotKeyEntryByCode, Task> action, HotKeyOptions options)
=> this.AddInternal(modifiers, code, async arg => await action(arg), action.Target as IHandleEvent, options);

/// <summary>
/// Add a new hotkey entry to this context.
/// </summary>
Expand Down Expand Up @@ -390,6 +542,18 @@ public HotKeysContext Add(ModCode modifiers, Code code, Action<HotKeyEntryByCode
public HotKeysContext Add(ModCode modifiers, Code code, Func<ValueTask> action, string description = "", Exclude exclude = Exclude.Default)
=> this.AddInternal(modifiers, code, _ => action(), action.Target as IHandleEvent, new() { Description = description, Exclude = exclude });

/// <summary>
/// Add a new hotkey entry to this context.
/// </summary>
/// <param name="modifiers">The combination of modifier keys flags.</param>
/// <param name="code">The identifier of hotkey by code.</param>
/// <param name="action">The callback action that will be invoked when user enter modifiers + key combination on the browser.</param>
/// <param name="exclude">The combination of HTML element flags that will be not allowed hotkey works.</param>
/// <param name="description">The description of the meaning of this hot key entry.</param>
/// <returns>This context.</returns>
public HotKeysContext Add(ModCode modifiers, Code code, Func<Task> action, string description = "", Exclude exclude = Exclude.Default)
=> this.AddInternal(modifiers, code, async _ => await action(), action.Target as IHandleEvent, new() { Description = description, Exclude = exclude });

/// <summary>
/// Add a new hotkey entry to this context.
/// </summary>
Expand All @@ -402,6 +566,18 @@ public HotKeysContext Add(ModCode modifiers, Code code, Func<ValueTask> action,
public HotKeysContext Add(ModCode modifiers, Code code, Func<HotKeyEntryByCode, ValueTask> action, string description = "", Exclude exclude = Exclude.Default)
=> this.AddInternal(modifiers, code, action, action.Target as IHandleEvent, new() { Description = description, Exclude = exclude });

/// <summary>
/// Add a new hotkey entry to this context.
/// </summary>
/// <param name="modifiers">The combination of modifier keys flags.</param>
/// <param name="code">The identifier of hotkey by code.</param>
/// <param name="action">The callback action that will be invoked when user enter modifiers + key combination on the browser.</param>
/// <param name="description">The description of the meaning of this hot key entry.</param>
/// <param name="exclude">The combination of HTML element flags that will be not allowed hotkey works.</param>
/// <returns>This context.</returns>
public HotKeysContext Add(ModCode modifiers, Code code, Func<HotKeyEntryByCode, Task> action, string description = "", Exclude exclude = Exclude.Default)
=> this.AddInternal(modifiers, code, async arg => await action(arg), action.Target as IHandleEvent, new() { Description = description, Exclude = exclude });

/// <summary>
/// Add a new hotkey entry to this context.
/// </summary>
Expand Down

0 comments on commit 12cf97d

Please sign in to comment.