Allow to add extra accelerators to wxMenuItem

These accelerators are not shown in wxMenuItem label, but still will
work.

Implement support for them in all major ports and XRC.

Co-Authored-By: Vadim Zeitlin <vadim@wxwidgets.org>
This commit is contained in:
Alexander Koshelev 2021-11-02 16:19:25 +03:00 committed by Vadim Zeitlin
parent e729791222
commit 0cd898975c
18 changed files with 375 additions and 33 deletions

View file

@ -84,6 +84,7 @@ wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(XRCID("derived_tool_or_menuitem"), MyFrame::OnDerivedDialogToolOrMenuCommand)
EVT_MENU(XRCID("controls_tool_or_menuitem"), MyFrame::OnControlsToolOrMenuCommand)
EVT_MENU(XRCID("uncentered_tool_or_menuitem"), MyFrame::OnUncenteredToolOrMenuCommand)
EVT_MENU(XRCID("multiple_accels"), MyFrame::OnMultipleAccels)
EVT_MENU(XRCID("aui_demo_tool_or_menuitem"), MyFrame::OnAuiDemoToolOrMenuCommand)
EVT_MENU(XRCID("obj_ref_tool_or_menuitem"), MyFrame::OnObjRefToolOrMenuCommand)
EVT_MENU(XRCID("custom_class_tool_or_menuitem"), MyFrame::OnCustomClassToolOrMenuCommand)
@ -285,6 +286,26 @@ void MyFrame::OnUncenteredToolOrMenuCommand(wxCommandEvent& WXUNUSED(event))
dlg.ShowModal();
}
void MyFrame::OnMultipleAccels(wxCommandEvent& WXUNUSED(event))
{
wxString msg;
#if defined(__WXOSX_COCOA__)
wxString main = "Cmd-W";
wxString extra1 = "Cmd-T";
wxString extra2 = "Shift-Cmd-W";
#else
wxString main = "Ctrl-W";
wxString extra1 = "Ctrl-T";
wxString extra2 = "Shift-Ctrl-W";
#endif
msg.Printf(
"You can open this dialog with any of '%s' (main), '%s' or '%s' (extra) accelerators.",
main, extra1, extra2
);
wxMessageBox(msg, _("Multiple accelerators demo"), wxOK | wxICON_INFORMATION, this);
}
void MyFrame::OnAuiDemoToolOrMenuCommand(wxCommandEvent& WXUNUSED(event))
{
#if wxUSE_AUI

View file

@ -43,6 +43,7 @@ private:
void OnDerivedDialogToolOrMenuCommand(wxCommandEvent& event);
void OnControlsToolOrMenuCommand(wxCommandEvent& event);
void OnUncenteredToolOrMenuCommand(wxCommandEvent& event);
void OnMultipleAccels(wxCommandEvent& event);
void OnAuiDemoToolOrMenuCommand(wxCommandEvent& event);
void OnObjRefToolOrMenuCommand(wxCommandEvent& event);
void OnCustomClassToolOrMenuCommand(wxCommandEvent& event);

View file

@ -45,6 +45,15 @@
<bitmap>uncenter.xpm</bitmap>
<help>Disable autocentering of a dialog on its parent</help>
</object>
<object class="wxMenuItem" name="multiple_accels">
<label>_Multiple accelerators</label>
<help>You can open the dialog with multiple accelerators</help>
<accel>Ctrl-W</accel>
<extra-accels>
<accel>Ctrl-T</accel>
<accel>Shift-Ctrl-W</accel>
</extra-accels>
</object>
</object>
<object class="wxMenu" name="advanced_demos_menu">
<label>_Advanced</label>