I have a detail view with actions that I need to invoke via hot keys. Clicking the actions will display notifications at the bottom of the window as well as loading spinners when the action is a ShowPopupWindowAction. However, when I invoke the buttons via the assigned hot key, the notifications and loading spinners do not show.
I am using the Toolbelt.Blazor.HotKeys2
nuget package to trigger a callback in my controller, which performs an actionButton.DoExecute().
If I click the action with my mouse, all is fine. But from the hot key it's not working.
From the example below, if I don't have an Item record selected in my grid, then I need to display a notification to the user. This is working when I click the Select Item button, but not when I press F5. This holds true for all of the buttons with hot keys.
As a new user of the XAF framework, I'm at a loss how to resolve this.
protected CustomActionController() {
selectItemAction = new QpPopupWindowShowAction(this, "Select", PredefinedCategory.PopupActions)
{
Caption = "Select F5",
IsModal = true,
ImageName = "Find"
};
}
protected override async void OnActivated()
{
base.OnActivated();
hotKeys = ((BlazorApplication) Application).ServiceProvider.GetRequiredService<HotKeys>();
hotKeysContext = hotKeys.CreateContext()
.Add(Code.F5, SelectItem, "Open Select Item Popup");
var jsRuntime = ((BlazorApplication)Application).ServiceProvider.GetRequiredService<IJSRuntime>();
await jsRuntime.InvokeVoidAsync("enableBrowserShortcut");
selectItemAction.CustomizePopupWindowParams += SelectItemAction_CustomizePopupWindowParams;
}
private void SelectItemAction_CustomizePopupWindowParams(object sender, CustomizePopupWindowParamsEventArgs e)
{
var controller = GetControllerForViewItem<TransactionActionController>("Transactions");
switch (controller.View.SelectedObjects.Count)
{
case 0:
throw new UserFriendlyException("Please check an item to process");
case > 1:
throw new UserFriendlyException("One item at a time please.");
}
var taskPrefix = "Customer Updates: Select: ";
var popupObjectSpace = Application.CreateObjectSpace<SystemTask>();
var tasksCollectionSource = TasksManager.GetTaskCollectionSource(popupObjectSpace, taskPrefix);
e.View = Application.CreateListView("Task_Selector", tasksCollectionSource, true);
e.DialogController.AcceptAction.Caption = "Process";
}
public void SelectItem()
{
selectItemAction.OpenPopup(); // OpenPopup is from a subclass of ShowPopupWindowAction
}
I have switched to invoking the action button via javascript.
public void TriggerAction(ActionBase action)
{
JsRuntime.InvokeVoidAsync("invokeAction", action.Caption);
}
function invokeAction(caption) {
var selector = `.dxbl-active button[data-action-name="${caption}"].xaf-action`;
var button = document.querySelector(selector);
if (button) {
button.focus();
button.click();
}
}
That seems to be working for the time being. I may encounter issues down the road if there are multiple active actions with the same hot key.