private void Unregister(HotKeyEntry hotKeyEntry) { if (hotKeyEntry.Id == -1) { return; } this._AttachTask.ContinueWith(t => { if (t.IsCompleted && !t.IsFaulted) { return(t.Result.InvokeAsync <object>("Toolbelt.Blazor.HotKeys.unregister", hotKeyEntry.Id).AsTask()); } else { var tcs = new TaskCompletionSource <int>(); tcs.TrySetException(t.Exception.InnerExceptions); return(tcs.Task as Task); } }) .ContinueWith(t => { hotKeyEntry.Id = -1; hotKeyEntry.ObjectReference?.Dispose(); hotKeyEntry.ObjectReference = null; }); }
private HotKeyEntry Register(HotKeyEntry hotKeyEntry) { hotKeyEntry.ObjectReference = DotNetObjectReference.Create(hotKeyEntry); this._AttachTask.ContinueWith(t => { if (t.IsCompleted && !t.IsFaulted) { return(t.Result.InvokeAsync <int>( "Toolbelt.Blazor.HotKeys.register", hotKeyEntry.ObjectReference, hotKeyEntry.ModKeys, hotKeyEntry.KeyName, hotKeyEntry.Exclude).AsTask()); } else { var tcs = new TaskCompletionSource <int>(); tcs.TrySetException(t.Exception.InnerExceptions); return(tcs.Task); } }) .Unwrap() .ContinueWith(t => { if (!t.IsCanceled && !t.IsFaulted) { hotKeyEntry.Id = t.Result; } }); return(hotKeyEntry); }
private bool IsAllowedIn(HotKeyEntry entry, HotKeyDownEventArgs e) { if (e.SrcElementTagName == "TEXTAREA") { return((entry.AllowIn & AllowIn.TextArea) == AllowIn.TextArea); } if (e.SrcElementTagName == "INPUT") { if (NonTextInputTypes.Contains(e.SrcElementTypeAttribute) && (entry.AllowIn & AllowIn.NonTextInput) == AllowIn.NonTextInput) { return(true); } return((entry.AllowIn & AllowIn.Input) == AllowIn.Input); } return(true); }