diff --git a/src/gui/menu.cpp b/src/gui/menu.cpp index 8f3959751..4596ae1d1 100644 --- a/src/gui/menu.cpp +++ b/src/gui/menu.cpp @@ -474,9 +474,10 @@ bool MenuBox::onProcessMessage(Message* msg) get_base(this)->was_clicked = false; - // Check for ALT+some letter in menubar and some letter in menuboxes - if (((this->type == JI_MENUBOX) && (!msg->any.shifts)) || - ((this->type == JI_MENUBAR) && (msg->any.shifts & KB_ALT_FLAG))) { + // Check for ALT+some underlined letter + if (((this->type == JI_MENUBOX) && (msg->any.shifts == 0 || // Inside menu-boxes we can use letters without Alt modifier pressed + msg->any.shifts == KB_ALT_FLAG)) || + ((this->type == JI_MENUBAR) && (msg->any.shifts == KB_ALT_FLAG))) { selected = check_for_letter(menu, scancode_to_ascii(msg->key.scancode)); if (selected) { menu->highlightItem(selected, true, true, true); @@ -503,17 +504,14 @@ bool MenuBox::onProcessMessage(Message* msg) if (!highlight && child_with_submenu_opened) highlight = child_with_submenu_opened; - + switch (msg->key.scancode) { case KEY_ESC: /* in menu-bar */ if (this->type == JI_MENUBAR) { if (highlight) { - menu->closeAll(); - - /* fetch the focus */ - jmanager_free_focus(); + cancelMenuLoop(); used = true; } } @@ -632,7 +630,14 @@ bool MenuBox::onProcessMessage(Message* msg) break; } - return used; + // Return true if we've already consumed the key. + if (used) { + return true; + } + // If the user presses the ALT key we close everything. + else if (msg->key.scancode == KEY_ALT) { + cancelMenuLoop(); + } } } break; @@ -1192,6 +1197,16 @@ void MenuBox::closePopup() jmanager_enqueue_message(msg); } +void MenuBox::cancelMenuLoop() +{ + Menu* menu = getMenu(); + if (menu) + menu->closeAll(); + + // Lost focus + jmanager_free_focus(); +} + void MenuItem::executeClick() { // Send the message diff --git a/src/gui/menu.h b/src/gui/menu.h index 572b1cb80..954872697 100644 --- a/src/gui/menu.h +++ b/src/gui/menu.h @@ -62,6 +62,10 @@ public: return m_base; } + // Closes all menu-boxes and goes back to the normal state of the + // menu-bar. + void cancelMenuLoop(); + protected: virtual bool onProcessMessage(Message* msg) OVERRIDE; MenuBaseData* createBase(); diff --git a/src/modules/gui.cpp b/src/modules/gui.cpp index 088525d50..31105fc16 100644 --- a/src/modules/gui.cpp +++ b/src/modules/gui.cpp @@ -1134,6 +1134,9 @@ static bool manager_msg_proc(JWidget widget, Message* msg) Shortcut* shortcut = *it; if (shortcut->is_pressed(msg)) { + // Cancel menu-bar loops (to close any popup menu) + app_get_menubar()->cancelMenuLoop(); + switch (shortcut->type) { case Shortcut_ChangeTool: {