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