From a605ee319705040c773a272761715c635f7e6f15 Mon Sep 17 00:00:00 2001 From: ali kettab Date: Wed, 23 Nov 2022 13:41:17 +0100 Subject: [PATCH] Don't pass hyphenated shortcuts to Qt Although there is no official Qt documentation about supporting hyphenated shortcuts or not, using them doesn't currently work (at least under Linux). So make sure that we always pass a non hyphenated shortcut to Qt to work correctly, and to display consistent shortcuts if there is a mix of standard shortcuts and user supplied ones. --- src/qt/menuitem.cpp | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/qt/menuitem.cpp b/src/qt/menuitem.cpp index 5fe6b45f1c..3aa2fde730 100644 --- a/src/qt/menuitem.cpp +++ b/src/qt/menuitem.cpp @@ -37,6 +37,14 @@ public: return static_cast(wxQtSignalHandler::GetHandler()); } + // Convert hyphenated shortcuts to use the plus sign (+) which Qt understands. + static wxString Normalize(const wxString& text) + { + QString normalized = wxQtConvertString( text ); + normalized.replace(QRegExp("([^+-])[-]"), "\\1+"); + return wxQtConvertString( normalized ); + } + private: void onActionToggled( bool checked ); void onActionTriggered( bool checked ); @@ -58,18 +66,22 @@ wxMenuItem::wxMenuItem(wxMenu *parentMenu, int id, const wxString& text, const wxString& help, wxItemKind kind, wxMenu *subMenu) : wxMenuItemBase( parentMenu, id, text, help, kind, subMenu ) { - m_qtAction = new wxQtAction( parentMenu, id, text, help, kind, subMenu, this ); + m_qtAction = new wxQtAction( parentMenu, id, + wxQtAction::Normalize( text ), + help, kind, subMenu, this ); } void wxMenuItem::SetItemLabel( const wxString &label ) { - wxMenuItemBase::SetItemLabel( label ); + const wxString qtlabel = wxQtAction::Normalize( label ); - m_qtAction->UpdateShortcutsFromLabel( label ); + wxMenuItemBase::SetItemLabel( qtlabel ); - m_qtAction->setText( wxQtConvertString( label )); + m_qtAction->UpdateShortcutsFromLabel( qtlabel ); + + m_qtAction->setText( wxQtConvertString( qtlabel )); } @@ -247,15 +259,6 @@ void wxQtAction::UpdateShortcuts(const wxString& text) #endif // wxUSE_ACCEL } -void wxQtAction::UpdateShortcutsFromLabel(const wxString& text) -{ - const wxString accelStr = text.AfterFirst('\t'); - if ( !accelStr.empty() ) - { - UpdateShortcuts(accelStr); - } -} - void wxQtAction::onActionToggled( bool checked ) { GetMenu()->Check(m_mitemId, checked);