private boolean dispatch( KeyboardShortcut shortcut, Map<KeyboardShortcut, ArrayList<AppCommand>> bindings, NativeEvent event, Map<AppCommand, Boolean> maskedCommandsMap) { if (!bindings.containsKey(shortcut) || bindings.get(shortcut) == null) return false; AppCommand command = null; for (int i = 0; i < bindings.get(shortcut).size(); i++) { command = bindings.get(shortcut).get(i); if (command != null) { boolean enabled = isEnabled() && command.isEnabled(); // some commands want their keyboard shortcut to pass through // to the browser when they are disabled (e.g. Cmd+W) if (!enabled && !command.preventShortcutWhenDisabled()) return false; // if we've remapped an AppCommand to a new binding, it's // implicitly disabled if (maskedCommandsMap != null && maskedCommandsMap.containsKey(command)) { command = null; continue; } event.preventDefault(); // if this command is enabled, execute it and stop looking if (enabled) { command.executeFromShortcut(); break; } } } return command != null; }