From c614980dca230bd13205fd4b56b82c56a71d74d1 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Sat, 7 Apr 2012 01:06:34 +0000 Subject: [PATCH] "Fix" issues with hotkeys not working with wxGTK GTK accelerators silently swallow the keypresses when the menu item is disabled, so disable accelerators completely and just use our hotkey system. Closes #1314. Originally committed to SVN as r6673. --- aegisub/src/menu.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/aegisub/src/menu.cpp b/aegisub/src/menu.cpp index 86134dba2..a8b1fbb03 100644 --- a/aegisub/src/menu.cpp +++ b/aegisub/src/menu.cpp @@ -441,7 +441,25 @@ namespace menu { window->Bind(wxEVT_MENU_OPEN, &CommandManager::OnMenuOpen, &menu->cm); window->Bind(wxEVT_COMMAND_MENU_SELECTED, &CommandManager::OnMenuClick, &menu->cm); - window->SetMenuBar(menu.release()); + window->SetMenuBar(menu.get()); + +#ifdef __WXGTK__ + // GTK silently swallows keypresses for accelerators whose associated + // menu items are disabled. As we don't update the menu until it's + // opened, this means that conditional hotkeys don't work if the menu + // hasn't been opened since they became valid. + // + // To work around this, we completely disable accelerators from menu + // item. wxGTK doesn't expose any way to do this other that at wx + // compile time (SetAcceleratorTable is a no-op), so have some fun with + // the implementation details of undocumented methods. Detaching via + // wxMenuBar::Detach removes the accelerator table, and then + // wxMenuBarBase::Attch is used to avoid readding it. + menu->Detach(); + menu->wxMenuBarBase::Attach(window); +#endif + + menu.release(); } wxMenu *GetMenu(std::string const& name, agi::Context *c) {