Skip to content

Commit

Permalink
Merge pull request #12 from jhony1104/finer-excludes
Browse files Browse the repository at this point in the history
finer excludes with css selector
  • Loading branch information
jsakamoto authored Sep 30, 2023
2 parents 3a9493f + 1298f7f commit ba5ec48
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 68 deletions.
12 changes: 6 additions & 6 deletions HotKeys2.Test/HotKeyEntryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,34 @@ public class HotKeyEntryTest
[Test]
public void Mode_for_ByKey_Test()
{
var hotKeyEntry = new HotKeyEntryByKey(ModKey.None, Key.Question, Exclude.None, "Show help.", _ => ValueTask.CompletedTask);
var hotKeyEntry = new HotKeyEntryByKey(ModKey.None, Key.Question, Exclude.None, "", "Show help.", _ => ValueTask.CompletedTask);
hotKeyEntry.Mode.Is(HotKeyMode.ByKey);
}

[Test]
public void Mode_for_ByCode_Test()
{
var hotKeyEntry = new HotKeyEntryByCode(ModCode.Ctrl | ModCode.Alt, Code.F12, Exclude.None, "Set the volume level to 10.", _ => ValueTask.CompletedTask);
var hotKeyEntry = new HotKeyEntryByCode(ModCode.Ctrl | ModCode.Alt, Code.F12, Exclude.None, "", "Set the volume level to 10.", _ => ValueTask.CompletedTask);
hotKeyEntry.Mode.Is(HotKeyMode.ByCode);
}

[Test]
public void ToString_for_ByKey_Test()
{
var hotKeyEntry = new HotKeyEntryByKey(ModKey.None, Key.Question, Exclude.None, "Show help.", _ => ValueTask.CompletedTask);
var hotKeyEntry = new HotKeyEntryByKey(ModKey.None, Key.Question, Exclude.None, "", "Show help.", _ => ValueTask.CompletedTask);
hotKeyEntry.ToString().Is("?: Show help.");
}

[Test]
public void ToString_for_ByCode_Test()
{
var ctrl_alt_f12 = new HotKeyEntryByCode(ModCode.Ctrl | ModCode.Alt, Code.F12, Exclude.None, "Set the volume level to 10.", _ => ValueTask.CompletedTask);
var ctrl_alt_f12 = new HotKeyEntryByCode(ModCode.Ctrl | ModCode.Alt, Code.F12, Exclude.None, "", "Set the volume level to 10.", _ => ValueTask.CompletedTask);
ctrl_alt_f12.ToString().Is("Ctrl + Alt + F12: Set the volume level to 10.");

var meta_one = new HotKeyEntryByCode(ModCode.Meta, Code.Num1, Exclude.None, "Launch the notepad.", _ => ValueTask.CompletedTask);
var meta_one = new HotKeyEntryByCode(ModCode.Meta, Code.Num1, Exclude.None, "", "Launch the notepad.", _ => ValueTask.CompletedTask);
meta_one.ToString().Is("Meta + 1: Launch the notepad.");

var u = new HotKeyEntryByCode(ModCode.None, Code.U, Exclude.None, "Increment counter.", _ => ValueTask.CompletedTask);
var u = new HotKeyEntryByCode(ModCode.None, Code.U, Exclude.None, "", "Increment counter.", _ => ValueTask.CompletedTask);
u.ToString().Is("U: Increment counter.");
}
}
14 changes: 11 additions & 3 deletions HotKeys2/HotKeyEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public abstract class HotKeyEntry : IDisposable
/// </summary>
public Exclude Exclude { get; }

/// <summary>
/// Get Additional CSS selector for HTML elements that will not allow hotkey to work.
/// </summary>
public string ExcludeSelector { get; }

/// <summary>
/// Get the description of the meaning of this hot key entry.
/// </summary>
Expand Down Expand Up @@ -58,10 +63,11 @@ public abstract class HotKeyEntry : IDisposable
/// <param name="modifiers">The combination of modifier flags</param>
/// <param name="keyEntry">The key or code of the hot key</param>
/// <param name="exclude">The combination of HTML element flags that will be not allowed hotkey works.</param>
/// <param name="excludeSelector">Additional CSS selector for HTML elements that will not allow hotkey to work.</param>
/// <param name="description">The description of the meaning of this hot key entry.</param>
[DynamicDependency(nameof(InvokeAction), typeof(HotKeyEntry)), Obsolete]
internal HotKeyEntry(HotKeyMode mode, Type typeOfModifiers, int modifiers, string keyEntry, Exclude exclude, string? description)
: this(null, mode, typeOfModifiers, modifiers, keyEntry, exclude, description, null) { }
internal HotKeyEntry(HotKeyMode mode, Type typeOfModifiers, int modifiers, string keyEntry, Exclude exclude, string excludeSelector, string? description)
: this(null, mode, typeOfModifiers, modifiers, keyEntry, exclude, excludeSelector, description, null) { }

/// <summary>
/// Initialize a new instance of the HotKeyEntry class.
Expand All @@ -72,17 +78,19 @@ internal HotKeyEntry(HotKeyMode mode, Type typeOfModifiers, int modifiers, strin
/// <param name="modifiers">The combination of modifier flags</param>
/// <param name="keyEntry">The key or code of the hot key</param>
/// <param name="exclude">The combination of HTML element flags that will be not allowed hotkey works.</param>
/// <param name="excludeSelector">Additional CSS selector for HTML elements that will not allow hotkey to work.</param>
/// <param name="description">The description of the meaning of this hot key entry.</param>
/// <param name="ownerOfAction">The instance of a Razor component that is an owner of the callback action method.</param>
[DynamicDependency(nameof(InvokeAction), typeof(HotKeyEntry))]
internal HotKeyEntry(ILogger? logger, HotKeyMode mode, Type typeOfModifiers, int modifiers, string keyEntry, Exclude exclude, string? description, IHandleEvent? ownerOfAction)
internal HotKeyEntry(ILogger? logger, HotKeyMode mode, Type typeOfModifiers, int modifiers, string keyEntry, Exclude exclude, string excludeSelector, string? description, IHandleEvent? ownerOfAction)
{
this._Logger = logger;
this.Mode = mode;
this._Modifiers = modifiers;
this._TypeOfModifiers = typeOfModifiers;
this._KeyEntry = keyEntry;
this.Exclude = exclude;
this.ExcludeSelector = excludeSelector;
this.Description = description;
this._OwnerComponent = ownerOfAction;
this._ObjectRef = DotNetObjectReference.Create(this);
Expand Down
10 changes: 6 additions & 4 deletions HotKeys2/HotKeyEntryByCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ public class HotKeyEntryByCode : HotKeyEntry
/// <param name="code">The identifier of hotkey.</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>
/// <param name="excludeSelector">Additional CSS selector for HTML elements that will not allow hotkey to work.</param>
/// <param name="action">The callback action that will be invoked when user enter modKeys + key combination on the browser.</param>
public HotKeyEntryByCode(ModCode modCodes, Code code, Exclude exclude, string? description, Func<HotKeyEntryByCode, ValueTask> action)
: base(null, HotKeyMode.ByCode, typeof(ModCode), (int)modCodes, code.ToString(), exclude, description, action.Target as IHandleEvent)
public HotKeyEntryByCode(ModCode modCodes, Code code, Exclude exclude, string excludeSelector, string? description, Func<HotKeyEntryByCode, ValueTask> action)
: base(null, HotKeyMode.ByCode, typeof(ModCode), (int)modCodes, code.ToString(), exclude, excludeSelector, description, action.Target as IHandleEvent)
{
this.Modifiers = modCodes;
this.Code = code;
Expand All @@ -41,10 +42,11 @@ public HotKeyEntryByCode(ModCode modCodes, Code code, Exclude exclude, string? d
/// <param name="code">The identifier of hotkey.</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>
/// <param name="excludeSelector">Additional CSS selector for HTML elements that will not allow hotkey to work.</param>
/// <param name="action">The callback action that will be invoked when user enter modKeys + key combination on the browser.</param>
/// <param name="ownerOfAction">The instance of a Razor component that is an owner of the callback action method.</param>
internal HotKeyEntryByCode(ILogger logger, ModCode modCodes, Code code, Exclude exclude, string? description, Func<HotKeyEntryByCode, ValueTask> action, IHandleEvent? ownerOfAction)
: base(logger, HotKeyMode.ByCode, typeof(ModCode), (int)modCodes, code.ToString(), exclude, description, ownerOfAction)
internal HotKeyEntryByCode(ILogger logger, ModCode modCodes, Code code, Exclude exclude, string excludeSelector, string? description, Func<HotKeyEntryByCode, ValueTask> action, IHandleEvent? ownerOfAction)
: base(logger, HotKeyMode.ByCode, typeof(ModCode), (int)modCodes, code.ToString(), exclude, excludeSelector, description, ownerOfAction)
{
this.Modifiers = modCodes;
this.Code = code;
Expand Down
10 changes: 6 additions & 4 deletions HotKeys2/HotKeyEntryByKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ public class HotKeyEntryByKey : HotKeyEntry
/// <param name="action">The callback action that will be invoked when user enter modKeys + 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>
public HotKeyEntryByKey(ModKey modKeys, Key key, Exclude exclude, string? description, Func<HotKeyEntryByKey, ValueTask> action)
: base(null, HotKeyMode.ByKey, typeof(ModKey), (int)modKeys, key.ToString(), exclude, description, action.Target as IHandleEvent)
/// <param name="excludeSelector">Additional CSS selector for HTML elements that will not allow hotkey to work.</param>
public HotKeyEntryByKey(ModKey modKeys, Key key, Exclude exclude, string excludeSelector, string? description, Func<HotKeyEntryByKey, ValueTask> action)
: base(null, HotKeyMode.ByKey, typeof(ModKey), (int)modKeys, key.ToString(), exclude, excludeSelector, description, action.Target as IHandleEvent)
{
this.Modifiers = modKeys;
this.Key = key;
Expand All @@ -44,9 +45,10 @@ public HotKeyEntryByKey(ModKey modKeys, Key key, Exclude exclude, string? descri
/// <param name="action">The callback action that will be invoked when user enter modKeys + 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>
/// <param name="excludeSelector">Additional CSS selector for HTML elements that will not allow hotkey to work.</param>
/// <param name="ownerOfAction">The instance of a Razor component that is an owner of the callback action method.</param>
internal HotKeyEntryByKey(ILogger logger, ModKey modKeys, Key key, Exclude exclude, string? description, Func<HotKeyEntryByKey, ValueTask> action, IHandleEvent? ownerOfAction)
: base(logger, HotKeyMode.ByKey, typeof(ModKey), (int)modKeys, key.ToString(), exclude, description, ownerOfAction)
internal HotKeyEntryByKey(ILogger logger, ModKey modKeys, Key key, Exclude exclude, string excludeSelector, string? description, Func<HotKeyEntryByKey, ValueTask> action, IHandleEvent? ownerOfAction)
: base(logger, HotKeyMode.ByKey, typeof(ModKey), (int)modKeys, key.ToString(), exclude, excludeSelector, description, ownerOfAction)
{
this.Modifiers = modKeys;
this.Key = key;
Expand Down
Loading

0 comments on commit ba5ec48

Please sign in to comment.