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.
This commit is contained in:
ali kettab 2022-11-23 13:41:17 +01:00
parent 2345cc5650
commit a605ee3197

View file

@ -37,6 +37,14 @@ public:
return static_cast<wxMenu*>(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);