ENH: use system menu on mac platform

Change-Id: Ia0e0bf42232d51cd08216811fdc6633527b3eb97
Signed-off-by: chunmao.guo <chunmao.guo@bambulab.com>
This commit is contained in:
chunmao.guo 2022-07-27 16:24:45 +08:00 committed by Lane.Wei
parent 099e72b885
commit 39f9c23b89
4 changed files with 88 additions and 13 deletions

View file

@ -2057,7 +2057,9 @@ bool GUI_App::on_init_inner()
} }
// BBS: // BBS:
#ifdef __WINDOWS__
mainframe->topbar()->SaveNormalRect(); mainframe->topbar()->SaveNormalRect();
#endif
mainframe->Show(true); mainframe->Show(true);
BOOST_LOG_TRIVIAL(info) << "main frame firstly shown"; BOOST_LOG_TRIVIAL(info) << "main frame firstly shown";

View file

@ -100,6 +100,11 @@ enum ConfigMenuIDs {
ConfigMenuCnt, ConfigMenuCnt,
}; };
enum BambuStudioMenuIDs {
BambuStudioMenuAbout,
BambuStudioMenuPreferences,
};
enum CameraMenuIDs { enum CameraMenuIDs {
wxID_CAMERA_PERSPECTIVE, wxID_CAMERA_PERSPECTIVE,
wxID_CAMERA_ORTHOGONAL, wxID_CAMERA_ORTHOGONAL,

View file

@ -142,7 +142,7 @@ static wxIcon main_frame_icon(GUI_App::EAppMode app_mode)
#ifdef __WINDOWS__ #ifdef __WINDOWS__
#define BORDERLESS_FRAME_STYLE (wxRESIZE_BORDER | wxMINIMIZE_BOX | wxMAXIMIZE_BOX | wxCLOSE_BOX) #define BORDERLESS_FRAME_STYLE (wxRESIZE_BORDER | wxMINIMIZE_BOX | wxMAXIMIZE_BOX | wxCLOSE_BOX)
#else #else
#define BORDERLESS_FRAME_STYLE (wxRESIZE_BORDER) #define BORDERLESS_FRAME_STYLE (wxMINIMIZE_BOX | wxMAXIMIZE_BOX | wxCLOSE_BOX)
#endif #endif
wxDEFINE_EVENT(EVT_SYNC_CLOUD_PRESET, SimpleEvent); wxDEFINE_EVENT(EVT_SYNC_CLOUD_PRESET, SimpleEvent);
@ -184,8 +184,6 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, BORDERLESS_FRAME_
auto panel_topbar = new wxPanel(this, wxID_ANY); auto panel_topbar = new wxPanel(this, wxID_ANY);
panel_topbar->SetBackgroundColour(wxColour(38, 46, 48)); panel_topbar->SetBackgroundColour(wxColour(38, 46, 48));
auto sizer_tobar = new wxBoxSizer(wxVERTICAL); auto sizer_tobar = new wxBoxSizer(wxVERTICAL);
m_topbar = new BBLTopbar(this);
sizer_tobar->Add(m_topbar, 0, wxEXPAND);
panel_topbar->SetSizer(sizer_tobar); panel_topbar->SetSizer(sizer_tobar);
panel_topbar->Layout(); panel_topbar->Layout();
#endif #endif
@ -286,13 +284,15 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, BORDERLESS_FRAME_
//Bind(wxEVT_MENU, [this](wxCommandEvent&) { m_plater->cut_selection_to_clipboard(); }, wxID_HIGHEST + wxID_CUT); //Bind(wxEVT_MENU, [this](wxCommandEvent&) { m_plater->cut_selection_to_clipboard(); }, wxID_HIGHEST + wxID_CUT);
Bind(wxEVT_SIZE, [this](wxSizeEvent&) { Bind(wxEVT_SIZE, [this](wxSizeEvent&) {
BOOST_LOG_TRIVIAL(trace) << "mainframe: size changed, is maximized = " << this->IsMaximized(); BOOST_LOG_TRIVIAL(trace) << "mainframe: size changed, is maximized = " << this->IsMaximized();
#ifdef __WINDOWS__
if (this->IsMaximized()) { if (this->IsMaximized()) {
m_topbar->SetWindowSize(); m_topbar->SetWindowSize();
} else { } else {
m_topbar->SetMaximizedSize(); m_topbar->SetMaximizedSize();
} }
Refresh(); #endif
Layout(); Refresh();
Layout();
}); });
//BBS //BBS
@ -828,13 +828,14 @@ void MainFrame::init_tabpanel()
//monitor //monitor
} }
#ifdef __WINDOWS__
if (sel == tp3DEditor) { if (sel == tp3DEditor) {
m_topbar->EnableUndoRedoItems(); m_topbar->EnableUndoRedoItems();
} }
else { else {
m_topbar->DisableUndoRedoItems(); m_topbar->DisableUndoRedoItems();
} }
#endif
/*switch (sel) { /*switch (sel) {
case TabPosition::tpHome: case TabPosition::tpHome:
@ -1475,8 +1476,10 @@ void MainFrame::on_dpi_changed(const wxRect& suggested_rect)
dynamic_cast<Notebook*>(m_tabpanel)->Rescale(); dynamic_cast<Notebook*>(m_tabpanel)->Rescale();
#endif #endif
#ifdef __WINDOWS__
// BBS // BBS
m_topbar->Rescale(); m_topbar->Rescale();
#endif
m_tabpanel->Rescale(); m_tabpanel->Rescale();
@ -1596,9 +1599,11 @@ static wxMenu* generate_help_menu()
return true; return true;
}); });
// About // About
#ifdef __WINDOWS__
wxString about_title = wxString::Format(_L("&About %s"), SLIC3R_APP_FULL_NAME); wxString about_title = wxString::Format(_L("&About %s"), SLIC3R_APP_FULL_NAME);
append_menu_item(helpMenu, wxID_ANY, about_title, about_title, append_menu_item(helpMenu, wxID_ANY, about_title, about_title,
[](wxCommandEvent&) { Slic3r::GUI::about(); }); [](wxCommandEvent&) { Slic3r::GUI::about(); });
#endif
return helpMenu; return helpMenu;
} }
@ -1628,6 +1633,7 @@ void MainFrame::init_menubar_as_editor()
{ {
#ifdef __APPLE__ #ifdef __APPLE__
wxMenuBar::SetAutoWindowMenu(false); wxMenuBar::SetAutoWindowMenu(false);
m_menubar = new wxMenuBar();
#endif #endif
// File menu // File menu
@ -1890,10 +1896,18 @@ void MainFrame::init_menubar_as_editor()
//auto config_wizard_name = _(ConfigWizard::name(true) + "(Debug)"); //auto config_wizard_name = _(ConfigWizard::name(true) + "(Debug)");
//const auto config_wizard_tooltip = from_u8((boost::format(_utf8(L("Run %s"))) % config_wizard_name).str()); //const auto config_wizard_tooltip = from_u8((boost::format(_utf8(L("Run %s"))) % config_wizard_name).str());
//auto config_item = new wxMenuItem(m_topbar->GetTopMenu(), ConfigMenuWizard + config_id_base, config_wizard_name, config_wizard_tooltip); //auto config_item = new wxMenuItem(m_topbar->GetTopMenu(), ConfigMenuWizard + config_id_base, config_wizard_name, config_wizard_tooltip);
auto preference_item = new wxMenuItem(m_topbar->GetTopMenu(), ConfigMenuPreferences + config_id_base, _L("Preferences") + "\tCtrl+P", ""); #ifdef __APPLE__
//auto printer_item = new wxMenuItem(m_topbar->GetTopMenu(), ConfigMenuPrinter + config_id_base, _L("Printer"), ""); wxWindowID bambu_studio_id_base = wxWindow::NewControlId(int(2));
//auto language_item = new wxMenuItem(m_topbar->GetTopMenu(), ConfigMenuLanguage + config_id_base, _L("Switch Language"), ""); wxMenu* parent_menu = m_menubar->OSXGetAppleMenu();
m_topbar->GetTopMenu()->Bind(wxEVT_MENU, [this, config_id_base](wxEvent& event) { auto preference_item = new wxMenuItem(parent_menu, BambuStudioMenuPreferences + bambu_studio_id_base, _L("Preferences") + "\tCtrl+P", "");
#else
wxMenu* parent_menu = m_topbar->GetTopMenu();
auto preference_item = new wxMenuItem(parent_menu, ConfigMenuPreferences + config_id_base, _L("Preferences") + "\tCtrl+P", "");
#endif
//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"), "");
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:
//{ //{
@ -1958,10 +1972,50 @@ void MainFrame::init_menubar_as_editor()
} }
}); });
#ifdef __APPLE__
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, "");
parent_menu->Bind(wxEVT_MENU, [this, bambu_studio_id_base](wxEvent& event) {
switch (event.GetId() - bambu_studio_id_base) {
case BambuStudioMenuAbout:
Slic3r::GUI::about();
break;
case BambuStudioMenuPreferences:
wxGetApp().CallAfter([this] {
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 // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
plater()->refresh_print();
#if ENABLE_CUSTOMIZABLE_FILES_ASSOCIATION_ON_WIN
#ifdef _WIN32
/*
if (wxGetApp().app_config()->get("associate_3mf") == "true")
wxGetApp().associate_3mf_files();
if (wxGetApp().app_config()->get("associate_stl") == "true")
wxGetApp().associate_stl_files();
/*if (wxGetApp().app_config()->get("associate_step") == "true")
wxGetApp().associate_step_files();*/
#endif // _WIN32
#endif
});
break;
default:
break;
}
});
parent_menu->Insert(0, about_item);
parent_menu->Insert(1, preference_item);
#endif
// Help menu // Help menu
auto helpMenu = generate_help_menu(); auto helpMenu = generate_help_menu();
#ifdef __WINDOWS__
m_topbar->SetFileMenu(fileMenu); m_topbar->SetFileMenu(fileMenu);
if (editMenu) if (editMenu)
m_topbar->AddDropDownSubMenu(editMenu, _L("Edit")); m_topbar->AddDropDownSubMenu(editMenu, _L("Edit"));
@ -1973,6 +2027,16 @@ void MainFrame::init_menubar_as_editor()
//m_topbar->AddDropDownMenuItem(language_item); //m_topbar->AddDropDownMenuItem(language_item);
//m_topbar->AddDropDownMenuItem(config_item); //m_topbar->AddDropDownMenuItem(config_item);
m_topbar->AddDropDownSubMenu(helpMenu, _L("Help")); m_topbar->AddDropDownSubMenu(helpMenu, _L("Help"));
#else
m_menubar->Append(fileMenu, _L("&File"));
if (editMenu)
m_menubar->Append(editMenu, _L("&Edit"));
if (viewMenu)
m_menubar->Append(viewMenu, _L("&View"));
if (helpMenu)
m_menubar->Append(helpMenu, _L("&Help"));
SetMenuBar(m_menubar);
#endif
#ifdef _MSW_DARK_MODE #ifdef _MSW_DARK_MODE
if (wxGetApp().tabs_as_menu()) if (wxGetApp().tabs_as_menu())
@ -1982,12 +2046,12 @@ void MainFrame::init_menubar_as_editor()
#ifdef __APPLE__ #ifdef __APPLE__
// This fixes a bug on Mac OS where the quit command doesn't emit window close events // This fixes a bug on Mac OS where the quit command doesn't emit window close events
// wx bug: https://trac.wxwidgets.org/ticket/18328 // wx bug: https://trac.wxwidgets.org/ticket/18328
/* wxMenu* apple_menu = m_menubar->OSXGetAppleMenu(); wxMenu* apple_menu = m_menubar->OSXGetAppleMenu();
if (apple_menu != nullptr) { if (apple_menu != nullptr) {
apple_menu->Bind(wxEVT_MENU, [this](wxCommandEvent &) { apple_menu->Bind(wxEVT_MENU, [this](wxCommandEvent &) {
Close(); Close();
}, wxID_EXIT); }, wxID_EXIT);
}*/ }
#endif // __APPLE__ #endif // __APPLE__
} }

View file

@ -5557,7 +5557,11 @@ void Plater::priv::set_project_name(const wxString& project_name)
{ {
m_project_name = project_name; m_project_name = project_name;
//update topbar title //update topbar title
#ifdef __WINDOWS__
wxGetApp().mainframe->topbar()->SetTitle(m_project_name); wxGetApp().mainframe->topbar()->SetTitle(m_project_name);
#else
wxGetApp().mainframe->SetTitle(m_project_name);
#endif
} }
void Plater::priv::set_project_filename(const wxString& filename) void Plater::priv::set_project_filename(const wxString& filename)