ENH:add shortcut in macos

Change-Id: I2c2145caab987fcb8073c4e7891769142dab840a
This commit is contained in:
liz.li 2022-08-08 10:05:00 +08:00 committed by Lane.Wei
parent 85ffeb291d
commit cd3a721f86
5 changed files with 170 additions and 121 deletions

View file

@ -145,19 +145,18 @@
document.onkeydown = function (event) { document.onkeydown = function (event) {
var e = event || window.event || arguments.callee.caller.arguments[0]; var e = event || window.event || arguments.callee.caller.arguments[0];
if (e.ctrlKey && e.metaKey)
OutputKey(e.keyCode, true, false, true);
else if (e.ctrlKey)
OutputKey(e.keyCode, true, false, false);
else if (e.metaKey)
OutputKey(e.keyCode, false, false, true);
if (e.shiftKey && e.ctrlKey) if (e.shiftKey && e.ctrlKey)
OutputKey(e.keyCode, true, true, false); OutputKey(e.keyCode, true, true, false);
else if (e.ctrlKey)
OutputKey(e.keyCode, true, false, false);
else if (e.keyCode === 27)
OutputKey(e.keyCode, false, false, false);
if (e.shiftKey && e.metaKey) if (e.shiftKey && e.metaKey)
OutputKey(e.keyCode, false, true, true); OutputKey(e.keyCode, false, true, true);
else if (e.metaKey)
OutputKey(e.keyCode, false, false, true);
else if (e.keyCode === 27)
OutputKey(e.keyCode, false, false, false);
if (window.event) { if (window.event) {
try { e.keyCode = 0; } catch (e) { } try { e.keyCode = 0; } catch (e) { }

View file

@ -3014,10 +3014,12 @@ std::string GUI_App::handle_web_request(std::string cmd)
wxKeyEvent e(wxEVT_CHAR_HOOK); wxKeyEvent e(wxEVT_CHAR_HOOK);
#ifdef __APPLE__ #ifdef __APPLE__
e.SetControlDown(cmdKey); e.SetControlDown(cmdKey);
e.SetRawControlDown(ctrlKey);
#else #else
e.SetControlDown(ctrlKey); e.SetControlDown(ctrlKey);
#endif #endif
e.SetShiftDown(shiftKey); e.SetShiftDown(shiftKey);
keyCode = keyCode == 188 ? ',' : keyCode;
e.m_keyCode = keyCode; e.m_keyCode = keyCode;
e.SetEventObject(mainframe); e.SetEventObject(mainframe);
wxPostEvent(mainframe, e); wxPostEvent(mainframe, e);

View file

@ -474,18 +474,36 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, BORDERLESS_FRAME_
Slic3r::run_backup_ui_tasks(); Slic3r::run_backup_ui_tasks();
}); });
; } ; }
this->Bind(wxEVT_CHAR_HOOK, [this](wxKeyEvent &evt) { this->Bind(wxEVT_CHAR_HOOK, [this](wxKeyEvent &evt) {
#ifdef __APPLE__ #ifdef __APPLE__
if (evt.CmdDown() && evt.GetKeyCode() == 'H') { this->Iconize(); return;} if (evt.CmdDown() && (evt.GetKeyCode() == 'H')) {
//call parent_menu hide behavior
return;}
if (evt.CmdDown() && (evt.GetKeyCode() == 'M')) {
this->Iconize();
return;
}
if (evt.CmdDown() && evt.GetKeyCode() == 'Q') { wxPostEvent(this, wxCloseEvent(wxEVT_CLOSE_WINDOW)); return;} if (evt.CmdDown() && evt.GetKeyCode() == 'Q') { wxPostEvent(this, wxCloseEvent(wxEVT_CLOSE_WINDOW)); return;}
if (evt.CmdDown() && evt.RawControlDown() && evt.GetKeyCode() == 'F') {
EnableFullScreenView(true);
if (IsFullScreen()) {
ShowFullScreen(false);
} else {
ShowFullScreen(true);
}
return;}
#endif #endif
if (evt.CmdDown() && evt.GetKeyCode() == 'N') { m_plater->new_project(); return;} if (evt.CmdDown() && evt.GetKeyCode() == 'N') { m_plater->new_project(); return;}
if (evt.CmdDown() && evt.GetKeyCode() == 'O') { m_plater->load_project(); return;} if (evt.CmdDown() && evt.GetKeyCode() == 'O') { m_plater->load_project(); return;}
if (evt.CmdDown() && evt.ShiftDown() && evt.GetKeyCode() == 'S') { if (m_plater) m_plater->save_project(true); return;} if (evt.CmdDown() && evt.ShiftDown() && evt.GetKeyCode() == 'S') { if (m_plater) m_plater->save_project(true); return;}
else if (evt.CmdDown() && evt.GetKeyCode() == 'S') { if (m_plater) m_plater->save_project(); return;} else if (evt.CmdDown() && evt.GetKeyCode() == 'S') { if (m_plater) m_plater->save_project(); return;}
if (evt.CmdDown() && evt.GetKeyCode() == 'P') { #ifdef __APPLE__
if (evt.CmdDown() && evt.GetKeyCode() == ',')
#else
if (evt.CmdDown() && evt.GetKeyCode() == 'P')
#endif
{
PreferencesDialog dlg(this); PreferencesDialog dlg(this);
dlg.ShowModal(); dlg.ShowModal();
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER #if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
@ -496,6 +514,7 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, BORDERLESS_FRAME_
plater()->refresh_print(); plater()->refresh_print();
return; return;
} }
if (evt.CmdDown() && evt.GetKeyCode() == 'I') { if (evt.CmdDown() && evt.GetKeyCode() == 'I') {
if (!can_add_models()) return; if (!can_add_models()) return;
if (m_plater) { m_plater->add_model(); } if (m_plater) { m_plater->add_model(); }
@ -1150,24 +1169,28 @@ bool MainFrame::can_change_view() const
} }
} }
bool MainFrame::can_clone() const {
return can_select() && !m_plater->is_selection_empty();
}
bool MainFrame::can_select() const bool MainFrame::can_select() const
{ {
return (m_plater != nullptr) && !m_plater->model().objects.empty(); return (m_plater != nullptr) && (m_tabpanel->GetSelection() == TabPosition::tp3DEditor) && !m_plater->model().objects.empty();
} }
bool MainFrame::can_deselect() const bool MainFrame::can_deselect() const
{ {
return (m_plater != nullptr) && !m_plater->is_selection_empty(); return (m_plater != nullptr) && (m_tabpanel->GetSelection() == TabPosition::tp3DEditor) && !m_plater->is_selection_empty();
} }
bool MainFrame::can_delete() const bool MainFrame::can_delete() const
{ {
return (m_plater != nullptr) && !m_plater->is_selection_empty(); return (m_plater != nullptr) && (m_tabpanel->GetSelection() == TabPosition::tp3DEditor) && !m_plater->is_selection_empty();
} }
bool MainFrame::can_delete_all() const bool MainFrame::can_delete_all() const
{ {
return (m_plater != nullptr) && !m_plater->model().objects.empty(); return (m_plater != nullptr) && (m_tabpanel->GetSelection() == TabPosition::tp3DEditor) && !m_plater->model().objects.empty();
} }
bool MainFrame::can_reslice() const bool MainFrame::can_reslice() const
@ -1795,7 +1818,7 @@ void MainFrame::init_menubar_as_editor()
_L("Clone copies of selections"),[this](wxCommandEvent&) { _L("Clone copies of selections"),[this](wxCommandEvent&) {
m_plater->clone_selection(); m_plater->clone_selection();
}, },
"menu_remove", nullptr, [this](){return can_select(); }, this); "menu_remove", nullptr, [this](){return can_clone(); }, this);
editMenu->AppendSeparator(); editMenu->AppendSeparator();
#else #else
// BBS undo // BBS undo
@ -1833,7 +1856,7 @@ void MainFrame::init_menubar_as_editor()
_L("Clone copies of selections"),[this](wxCommandEvent&) { _L("Clone copies of selections"),[this](wxCommandEvent&) {
m_plater->clone_selection(); m_plater->clone_selection();
}, },
"", nullptr, [this](){return can_select(); }, this); "", nullptr, [this](){return can_clone(); }, this);
editMenu->AppendSeparator(); editMenu->AppendSeparator();
#endif #endif
@ -1906,117 +1929,122 @@ void MainFrame::init_menubar_as_editor()
#ifdef __APPLE__ #ifdef __APPLE__
wxWindowID bambu_studio_id_base = wxWindow::NewControlId(int(2)); wxWindowID bambu_studio_id_base = wxWindow::NewControlId(int(2));
wxMenu* parent_menu = m_menubar->OSXGetAppleMenu(); wxMenu* parent_menu = m_menubar->OSXGetAppleMenu();
auto preference_item = new wxMenuItem(parent_menu, BambuStudioMenuPreferences + bambu_studio_id_base, _L("Preferences") + "\tCtrl+P", ""); auto preference_item = new wxMenuItem(parent_menu, BambuStudioMenuPreferences + bambu_studio_id_base, _L("Preferences") + "\tCtrl+,", "");
#else #else
wxMenu* parent_menu = m_topbar->GetTopMenu(); wxMenu* parent_menu = m_topbar->GetTopMenu();
auto preference_item = new wxMenuItem(parent_menu, ConfigMenuPreferences + config_id_base, _L("Preferences") + "\tCtrl+P", ""); auto preference_item = new wxMenuItem(parent_menu, ConfigMenuPreferences + config_id_base, _L("Preferences") + "\tCtrl+P", "");
#endif
#endif
//auto printer_item = new wxMenuItem(parent_menu, ConfigMenuPrinter + config_id_base, _L("Printer"), ""); //auto printer_item = new wxMenuItem(parent_menu, ConfigMenuPrinter + config_id_base, _L("Printer"), "");
//auto language_item = new wxMenuItem(parent_menu, ConfigMenuLanguage + config_id_base, _L("Switch Language"), ""); //auto language_item = new wxMenuItem(parent_menu, ConfigMenuLanguage + config_id_base, _L("Switch Language"), "");
parent_menu->Bind(wxEVT_MENU, [this, config_id_base](wxEvent& event) { // parent_menu->Bind(wxEVT_MENU, [this, config_id_base](wxEvent& event) {
switch (event.GetId() - config_id_base) { // switch (event.GetId() - config_id_base) {
//case ConfigMenuLanguage: // //case ConfigMenuLanguage:
//{ // //{
// /* Before change application language, let's check unsaved changes on 3D-Scene // // /* Before change application language, let's check unsaved changes on 3D-Scene
// * and draw user's attention to the application restarting after a language change // // * and draw user's attention to the application restarting after a language change
// */ // // */
// { // // {
// // the dialog needs to be destroyed before the call to switch_language() // // // the dialog needs to be destroyed before the call to switch_language()
// // or sometimes the application crashes into wxDialogBase() destructor // // // or sometimes the application crashes into wxDialogBase() destructor
// // so we put it into an inner scope // // // so we put it into an inner scope
// wxString title = _L("Language selection"); // // wxString title = _L("Language selection");
// wxMessageDialog dialog(nullptr, // // wxMessageDialog dialog(nullptr,
// _L("Switching the language requires application restart.\n") + "\n\n" + // // _L("Switching the language requires application restart.\n") + "\n\n" +
// _L("Do you want to continue?"), // // _L("Do you want to continue?"),
// title, // // title,
// wxICON_QUESTION | wxOK | wxCANCEL); // // wxICON_QUESTION | wxOK | wxCANCEL);
// if (dialog.ShowModal() == wxID_CANCEL) // // if (dialog.ShowModal() == wxID_CANCEL)
// return; // // return;
// } // // }
//
// wxGetApp().switch_language(); // // wxGetApp().switch_language();
// break; // // break;
//} // //}
//case ConfigMenuWizard: // //case ConfigMenuWizard:
//{ // //{
// wxGetApp().run_wizard(ConfigWizard::RR_USER); // // wxGetApp().run_wizard(ConfigWizard::RR_USER);
// break; // // break;
//} // //}
case ConfigMenuPrinter: // case ConfigMenuPrinter:
{ // {
wxGetApp().params_dialog()->Popup(); // wxGetApp().params_dialog()->Popup();
wxGetApp().get_tab(Preset::TYPE_PRINTER)->restore_last_select_item(); // wxGetApp().get_tab(Preset::TYPE_PRINTER)->restore_last_select_item();
break; // break;
} // }
case ConfigMenuPreferences: // case ConfigMenuPreferences:
{ // {
wxGetApp().CallAfter([this] { // wxGetApp().CallAfter([this] {
PreferencesDialog dlg(this); // PreferencesDialog dlg(this);
dlg.ShowModal(); // dlg.ShowModal();
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER //#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
if (dlg.seq_top_layer_only_changed() || dlg.seq_seq_top_gcode_indices_changed()) // if (dlg.seq_top_layer_only_changed() || dlg.seq_seq_top_gcode_indices_changed())
#else //#else
if (dlg.seq_top_layer_only_changed()) // if (dlg.seq_top_layer_only_changed())
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER //#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
plater()->refresh_print(); // plater()->refresh_print();
#if ENABLE_CUSTOMIZABLE_FILES_ASSOCIATION_ON_WIN //#if ENABLE_CUSTOMIZABLE_FILES_ASSOCIATION_ON_WIN
#ifdef _WIN32 //#ifdef _WIN32
/* // /*
if (wxGetApp().app_config()->get("associate_3mf") == "true") // if (wxGetApp().app_config()->get("associate_3mf") == "true")
wxGetApp().associate_3mf_files(); // wxGetApp().associate_3mf_files();
if (wxGetApp().app_config()->get("associate_stl") == "true") // if (wxGetApp().app_config()->get("associate_stl") == "true")
wxGetApp().associate_stl_files(); // wxGetApp().associate_stl_files();
/*if (wxGetApp().app_config()->get("associate_step") == "true") // /*if (wxGetApp().app_config()->get("associate_step") == "true")
wxGetApp().associate_step_files();*/ // wxGetApp().associate_step_files();*/
#endif // _WIN32 //#endif // _WIN32
#endif //#endif
}); // });
break; // break;
} // }
default: // default:
break; // break;
} // }
}); // });
#ifdef __APPLE__ #ifdef __APPLE__
wxString about_title = wxString::Format(_L("&About %s"), SLIC3R_APP_FULL_NAME); wxString about_title = wxString::Format(_L("&About %s"), SLIC3R_APP_FULL_NAME);
auto about_item = new wxMenuItem(parent_menu, BambuStudioMenuAbout + bambu_studio_id_base, about_title, ""); auto about_item = new wxMenuItem(parent_menu, BambuStudioMenuAbout + bambu_studio_id_base, about_title, "");
parent_menu->Bind(wxEVT_MENU, [this, bambu_studio_id_base](wxEvent& event) { //parent_menu->Bind(wxEVT_MENU, [this, bambu_studio_id_base](wxEvent& event) {
switch (event.GetId() - bambu_studio_id_base) { // switch (event.GetId() - bambu_studio_id_base) {
case BambuStudioMenuAbout: // case BambuStudioMenuAbout:
Slic3r::GUI::about(); // Slic3r::GUI::about();
break; // break;
case BambuStudioMenuPreferences: // case BambuStudioMenuPreferences:
wxGetApp().CallAfter([this] { // wxGetApp().CallAfter([this] {
PreferencesDialog dlg(this); // PreferencesDialog dlg(this);
dlg.ShowModal(); // dlg.ShowModal();
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER //#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
if (dlg.seq_top_layer_only_changed() || dlg.seq_seq_top_gcode_indices_changed()) // if (dlg.seq_top_layer_only_changed() || dlg.seq_seq_top_gcode_indices_changed())
#else //#else
if (dlg.seq_top_layer_only_changed()) // if (dlg.seq_top_layer_only_changed())
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER //#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
plater()->refresh_print(); // plater()->refresh_print();
#if ENABLE_CUSTOMIZABLE_FILES_ASSOCIATION_ON_WIN // });
#ifdef _WIN32 // break;
/* // default:
if (wxGetApp().app_config()->get("associate_3mf") == "true") // break;
wxGetApp().associate_3mf_files(); // }
if (wxGetApp().app_config()->get("associate_stl") == "true") //});
wxGetApp().associate_stl_files(); //parent_menu->Insert(0, about_item);
/*if (wxGetApp().app_config()->get("associate_step") == "true") append_menu_item(
wxGetApp().associate_step_files();*/ parent_menu, wxID_ANY, _L("About") + "", _L(""),
#endif // _WIN32 [this](wxCommandEvent &) { Slic3r::GUI::about();},
#endif "", nullptr, []() { return true; }, this, 0);
}); append_menu_item(
break; parent_menu, wxID_ANY, _L("Preferences") + "\tCtrl+'", _L(""),
default: [this](wxCommandEvent &) {
break; PreferencesDialog dlg(this);
} dlg.ShowModal();
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
}); if (dlg.seq_top_layer_only_changed() || dlg.seq_seq_top_gcode_indices_changed())
parent_menu->Insert(0, about_item); #else
parent_menu->Insert(1, preference_item); if (dlg.seq_top_layer_only_changed())
#endif
plater()->refresh_print();
},
"", nullptr, []() { return true; }, this, 1);
//parent_menu->Insert(1, preference_item);
#endif #endif
// Help menu // Help menu
auto helpMenu = generate_help_menu(); auto helpMenu = generate_help_menu();
@ -2029,7 +2057,21 @@ void MainFrame::init_menubar_as_editor()
if (viewMenu) if (viewMenu)
m_topbar->AddDropDownSubMenu(viewMenu, _L("View")); m_topbar->AddDropDownSubMenu(viewMenu, _L("View"));
//BBS add Preference //BBS add Preference
m_topbar->AddDropDownMenuItem(preference_item);
append_menu_item(
m_topbar->GetTopMenu(), wxID_ANY, _L("Preferences") + "\tCtrl+P", _L(""),
[this](wxCommandEvent &) {
PreferencesDialog dlg(this);
dlg.ShowModal();
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
if (dlg.seq_top_layer_only_changed() || dlg.seq_seq_top_gcode_indices_changed())
#else
if (dlg.seq_top_layer_only_changed())
#endif
plater()->refresh_print();
},
"", nullptr, []() { return true; }, this);
//m_topbar->AddDropDownMenuItem(preference_item);
//m_topbar->AddDropDownMenuItem(printer_item); //m_topbar->AddDropDownMenuItem(printer_item);
//m_topbar->AddDropDownMenuItem(language_item); //m_topbar->AddDropDownMenuItem(language_item);
//m_topbar->AddDropDownMenuItem(config_item); //m_topbar->AddDropDownMenuItem(config_item);

View file

@ -116,6 +116,7 @@ class MainFrame : public DPIFrame
bool can_change_view() const; bool can_change_view() const;
bool can_select() const; bool can_select() const;
bool can_deselect() const; bool can_deselect() const;
bool can_clone() const;
bool can_delete() const; bool can_delete() const;
bool can_delete_all() const; bool can_delete_all() const;
bool can_reslice() const; bool can_reslice() const;

View file

@ -9854,6 +9854,8 @@ bool Plater::can_split_to_volumes() const { return p->can_split_to_volumes(); }
bool Plater::can_arrange() const { return p->can_arrange(); } bool Plater::can_arrange() const { return p->can_arrange(); }
bool Plater::can_paste_from_clipboard() const bool Plater::can_paste_from_clipboard() const
{ {
if (!IsShown() || !p->is_view3D_shown()) return false;
const Selection& selection = p->view3D->get_canvas3d()->get_selection(); const Selection& selection = p->view3D->get_canvas3d()->get_selection();
const Selection::Clipboard& clipboard = selection.get_clipboard(); const Selection::Clipboard& clipboard = selection.get_clipboard();
@ -9883,6 +9885,9 @@ bool Plater::can_cut_to_clipboard() const
bool Plater::can_copy_to_clipboard() const bool Plater::can_copy_to_clipboard() const
{ {
if (!IsShown() || !p->is_view3D_shown())
return false;
if (is_selection_empty()) if (is_selection_empty())
return false; return false;
@ -9893,8 +9898,8 @@ bool Plater::can_copy_to_clipboard() const
return true; return true;
} }
bool Plater::can_undo() const { return p->undo_redo_stack().has_undo_snapshot(); } bool Plater::can_undo() const { return IsShown() && p->is_view3D_shown() && p->undo_redo_stack().has_undo_snapshot(); }
bool Plater::can_redo() const { return p->undo_redo_stack().has_redo_snapshot(); } bool Plater::can_redo() const { return IsShown() && p->is_view3D_shown() && p->undo_redo_stack().has_redo_snapshot(); }
bool Plater::can_reload_from_disk() const { return p->can_reload_from_disk(); } bool Plater::can_reload_from_disk() const { return p->can_reload_from_disk(); }
//BBS //BBS
bool Plater::can_fillcolor() const { return p->can_fillcolor(); } bool Plater::can_fillcolor() const { return p->can_fillcolor(); }