Fix shortcut collision on macOS (#9136)

Fix #8152
This commit is contained in:
SoftFever 2025-04-05 21:44:48 +08:00 committed by GitHub
commit 85d46d2979
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -168,8 +168,10 @@ wxDEFINE_EVENT(EVT_SYNC_CLOUD_PRESET, SimpleEvent);
#ifdef __APPLE__ #ifdef __APPLE__
static const wxString ctrl = ("Ctrl+"); static const wxString ctrl = ("Ctrl+");
static const std::string ctrl_t = "";
#else #else
static const wxString ctrl = _L("Ctrl+"); static const wxString ctrl = _L("Ctrl+");
static const wxString ctrl_t = ctrl;
#endif #endif
MainFrame::MainFrame() : MainFrame::MainFrame() :
@ -2183,14 +2185,13 @@ void MainFrame::on_sys_color_changed()
this->Refresh(); this->Refresh();
} }
#ifdef _MSC_VER // On macOS, we use system menu bar, which handles the key accelerators automatically and breaks key handling in normal typing
// \xA0 is a non-breaking space. It is entered here to spoil the automatic accelerators, // See https://github.com/SoftFever/OrcaSlicer/issues/8152
// as the simple numeric accelerators spoil all numeric data entry. // So we disable some of the accelerators on macOS, by replacing the accelerator seperator to a hyphen.
static const wxString sep = "\t\xA0"; #ifdef __APPLE__
static const wxString sep_space = "\xA0";
#else
static const wxString sep = " - "; static const wxString sep = " - ";
static const wxString sep_space = ""; #else
static const wxString sep = "\t";
#endif #endif
static wxMenu* generate_help_menu() static wxMenu* generate_help_menu()
@ -2503,7 +2504,7 @@ void MainFrame::init_menubar_as_editor()
editMenu->AppendSeparator(); editMenu->AppendSeparator();
#else #else
// BBS undo // BBS undo
append_menu_item(editMenu, wxID_ANY, _L("Undo") + "\t" + ctrl + "Z", append_menu_item(editMenu, wxID_ANY, _L("Undo") + sep + ctrl_t + "Z",
_L("Undo"), [this, handle_key_event](wxCommandEvent&) { _L("Undo"), [this, handle_key_event](wxCommandEvent&) {
wxKeyEvent e; wxKeyEvent e;
e.SetEventType(wxEVT_KEY_DOWN); e.SetEventType(wxEVT_KEY_DOWN);
@ -2515,7 +2516,7 @@ void MainFrame::init_menubar_as_editor()
m_plater->undo(); }, m_plater->undo(); },
"", nullptr, [this](){return m_plater->can_undo(); }, this); "", nullptr, [this](){return m_plater->can_undo(); }, this);
// BBS redo // BBS redo
append_menu_item(editMenu, wxID_ANY, _L("Redo") + "\t" + ctrl + "Y", append_menu_item(editMenu, wxID_ANY, _L("Redo") + sep + ctrl_t + "Y",
_L("Redo"), [this, handle_key_event](wxCommandEvent&) { _L("Redo"), [this, handle_key_event](wxCommandEvent&) {
wxKeyEvent e; wxKeyEvent e;
e.SetEventType(wxEVT_KEY_DOWN); e.SetEventType(wxEVT_KEY_DOWN);
@ -2528,7 +2529,7 @@ void MainFrame::init_menubar_as_editor()
"", nullptr, [this](){return m_plater->can_redo(); }, this); "", nullptr, [this](){return m_plater->can_redo(); }, this);
editMenu->AppendSeparator(); editMenu->AppendSeparator();
// BBS Cut TODO // BBS Cut TODO
append_menu_item(editMenu, wxID_ANY, _L("Cut") + "\t" + ctrl + "X", append_menu_item(editMenu, wxID_ANY, _L("Cut") + sep + ctrl_t + "X",
_L("Cut selection to clipboard"), [this, handle_key_event](wxCommandEvent&) { _L("Cut selection to clipboard"), [this, handle_key_event](wxCommandEvent&) {
wxKeyEvent e; wxKeyEvent e;
e.SetEventType(wxEVT_KEY_DOWN); e.SetEventType(wxEVT_KEY_DOWN);
@ -2540,7 +2541,7 @@ void MainFrame::init_menubar_as_editor()
m_plater->cut_selection_to_clipboard(); }, m_plater->cut_selection_to_clipboard(); },
"", nullptr, [this]() {return m_plater->can_copy_to_clipboard(); }, this); "", nullptr, [this]() {return m_plater->can_copy_to_clipboard(); }, this);
// BBS Copy // BBS Copy
append_menu_item(editMenu, wxID_ANY, _L("Copy") + "\t" + ctrl + "C", append_menu_item(editMenu, wxID_ANY, _L("Copy") + sep + ctrl_t + "C",
_L("Copy selection to clipboard"), [this, handle_key_event](wxCommandEvent&) { _L("Copy selection to clipboard"), [this, handle_key_event](wxCommandEvent&) {
wxKeyEvent e; wxKeyEvent e;
e.SetEventType(wxEVT_KEY_DOWN); e.SetEventType(wxEVT_KEY_DOWN);
@ -2552,7 +2553,7 @@ void MainFrame::init_menubar_as_editor()
m_plater->copy_selection_to_clipboard(); }, m_plater->copy_selection_to_clipboard(); },
"", nullptr, [this](){return m_plater->can_copy_to_clipboard(); }, this); "", nullptr, [this](){return m_plater->can_copy_to_clipboard(); }, this);
// BBS Paste // BBS Paste
append_menu_item(editMenu, wxID_ANY, _L("Paste") + "\t" + ctrl + "V", append_menu_item(editMenu, wxID_ANY, _L("Paste") + sep + ctrl_t + "V",
_L("Paste clipboard"), [this, handle_key_event](wxCommandEvent&) { _L("Paste clipboard"), [this, handle_key_event](wxCommandEvent&) {
wxKeyEvent e; wxKeyEvent e;
e.SetEventType(wxEVT_KEY_DOWN); e.SetEventType(wxEVT_KEY_DOWN);
@ -2608,7 +2609,7 @@ void MainFrame::init_menubar_as_editor()
#endif #endif
// BBS Select All // BBS Select All
append_menu_item(editMenu, wxID_ANY, _L("Select all") + "\t" + ctrl + "A", append_menu_item(editMenu, wxID_ANY, _L("Select all") + sep + ctrl_t + "A",
_L("Selects all objects"), [this, handle_key_event](wxCommandEvent&) { _L("Selects all objects"), [this, handle_key_event](wxCommandEvent&) {
wxKeyEvent e; wxKeyEvent e;
e.SetEventType(wxEVT_KEY_DOWN); e.SetEventType(wxEVT_KEY_DOWN);
@ -2620,7 +2621,7 @@ void MainFrame::init_menubar_as_editor()
m_plater->select_all(); }, m_plater->select_all(); },
"", nullptr, [this](){return can_select(); }, this); "", nullptr, [this](){return can_select(); }, this);
// BBS Deslect All // BBS Deslect All
append_menu_item(editMenu, wxID_ANY, _L("Deselect all") + "\tEsc", append_menu_item(editMenu, wxID_ANY, _L("Deselect all") + sep + "Esc",
_L("Deselects all objects"), [this, handle_key_event](wxCommandEvent&) { _L("Deselects all objects"), [this, handle_key_event](wxCommandEvent&) {
wxKeyEvent e; wxKeyEvent e;
e.SetEventType(wxEVT_KEY_DOWN); e.SetEventType(wxEVT_KEY_DOWN);
@ -2691,7 +2692,7 @@ void MainFrame::init_menubar_as_editor()
[this]() { return wxGetApp().app_config->get_bool("auto_perspective"); }, this); [this]() { return wxGetApp().app_config->get_bool("auto_perspective"); }, this);
viewMenu->AppendSeparator(); viewMenu->AppendSeparator();
append_menu_check_item(viewMenu, wxID_ANY, _L("Show &G-code Window") + "\tC", _L("Show g-code window in Preview scene"), append_menu_check_item(viewMenu, wxID_ANY, _L("Show &G-code Window") + sep + "C", _L("Show g-code window in Preview scene"),
[this](wxCommandEvent &) { [this](wxCommandEvent &) {
wxGetApp().toggle_show_gcode_window(); wxGetApp().toggle_show_gcode_window();
m_plater->get_current_canvas3D()->post_event(SimpleEvent(wxEVT_PAINT)); m_plater->get_current_canvas3D()->post_event(SimpleEvent(wxEVT_PAINT));