BWindow: Clean up dispatch of NO_COMMAND_KEY shortcuts.
Only search once for a shortcut exactly matching the current modifiers, i.e. whether with or without COMMAND_KEY. Also clarify some of the comments and logic.
This commit is contained in:
@@ -1085,8 +1085,9 @@
|
||||
\brief Hook method that gets called just before a menu owned by the window is
|
||||
shown.
|
||||
|
||||
\note This method is not invoked by a message, there is no
|
||||
\c B_MENUS_BEGINNING flag.
|
||||
It will also be invoked while dispatching shortcuts.
|
||||
|
||||
\note This method is not invoked by a message.
|
||||
|
||||
\since BeOS R3
|
||||
*/
|
||||
@@ -1097,8 +1098,9 @@
|
||||
\brief Hook method that gets called just before a menu owned by the window is
|
||||
hidden.
|
||||
|
||||
\note This method is not invoked by a message, there is no
|
||||
\c B_MENUS_ENDED flag.
|
||||
It will also be invoked after dispatching shortcuts.
|
||||
|
||||
\note This method is not invoked by a message.
|
||||
|
||||
\since BeOS R3
|
||||
*/
|
||||
|
||||
@@ -3712,7 +3712,7 @@ BWindow::_HandleKeyDown(BMessage* event)
|
||||
return true;
|
||||
}
|
||||
|
||||
// Handle shortcuts
|
||||
// Special handling for Command+q, Command+Left, Command+Right
|
||||
if ((modifiers & B_COMMAND_KEY) != 0) {
|
||||
// Command+q has been pressed, so, we will quit
|
||||
// the shortcut mechanism doesn't allow handlers outside the window
|
||||
@@ -3734,9 +3734,7 @@ BWindow::_HandleKeyDown(BMessage* event)
|
||||
}
|
||||
}
|
||||
|
||||
bool foundShortcut = false;
|
||||
|
||||
// Handle B_NO_COMMAND_KEY and B_COMMAND_KEY shortcuts
|
||||
// Handle shortcuts
|
||||
{
|
||||
// Pretend that the user opened a menu, to give the subclass a
|
||||
// chance to update its menus. This may install new shortcuts,
|
||||
@@ -3744,13 +3742,9 @@ BWindow::_HandleKeyDown(BMessage* event)
|
||||
// a shortcut for the given key.
|
||||
MenusBeginning();
|
||||
|
||||
// look for B_NO_COMMAND_KEY shortcut then B_COMMAND_KEY
|
||||
Shortcut* shortcut = _FindShortcut(key, modifiers | B_NO_COMMAND_KEY);
|
||||
foundShortcut = shortcut != NULL;
|
||||
if (!foundShortcut && (modifiers & B_COMMAND_KEY) != 0)
|
||||
shortcut = _FindShortcut(key, modifiers);
|
||||
foundShortcut = shortcut != NULL;
|
||||
if (foundShortcut) {
|
||||
Shortcut* shortcut = _FindShortcut(key, modifiers
|
||||
| (((modifiers & B_COMMAND_KEY) == 0) ? B_NO_COMMAND_KEY : 0));
|
||||
if (shortcut != NULL) {
|
||||
// TODO: would be nice to move this functionality to
|
||||
// a Shortcut::Invoke() method - but since BMenu::InvokeItem()
|
||||
// (and BMenuItem::Invoke()) are private, I didn't want
|
||||
@@ -3778,9 +3772,12 @@ BWindow::_HandleKeyDown(BMessage* event)
|
||||
}
|
||||
|
||||
MenusEnded();
|
||||
|
||||
if (shortcut != NULL)
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((modifiers & B_COMMAND_KEY) != 0 || foundShortcut) {
|
||||
if ((modifiers & B_COMMAND_KEY) != 0) {
|
||||
// we always eat the event if the command key was pressed
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user