From 39f9c23b89a3933e1fec1b0d1021575c8c6c4279 Mon Sep 17 00:00:00 2001 From: "chunmao.guo" Date: Wed, 27 Jul 2022 16:24:45 +0800 Subject: [PATCH] ENH: use system menu on mac platform Change-Id: Ia0e0bf42232d51cd08216811fdc6633527b3eb97 Signed-off-by: chunmao.guo --- src/slic3r/GUI/GUI_App.cpp | 2 + src/slic3r/GUI/GUI_App.hpp | 5 ++ src/slic3r/GUI/MainFrame.cpp | 90 ++++++++++++++++++++++++++++++------ src/slic3r/GUI/Plater.cpp | 4 ++ 4 files changed, 88 insertions(+), 13 deletions(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 4a4933355..666e6ce46 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -2057,7 +2057,9 @@ bool GUI_App::on_init_inner() } // BBS: +#ifdef __WINDOWS__ mainframe->topbar()->SaveNormalRect(); +#endif mainframe->Show(true); BOOST_LOG_TRIVIAL(info) << "main frame firstly shown"; diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index af2b4e134..cba3d947f 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -100,6 +100,11 @@ enum ConfigMenuIDs { ConfigMenuCnt, }; +enum BambuStudioMenuIDs { + BambuStudioMenuAbout, + BambuStudioMenuPreferences, +}; + enum CameraMenuIDs { wxID_CAMERA_PERSPECTIVE, wxID_CAMERA_ORTHOGONAL, diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 4d5181158..070081152 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -142,7 +142,7 @@ static wxIcon main_frame_icon(GUI_App::EAppMode app_mode) #ifdef __WINDOWS__ #define BORDERLESS_FRAME_STYLE (wxRESIZE_BORDER | wxMINIMIZE_BOX | wxMAXIMIZE_BOX | wxCLOSE_BOX) #else -#define BORDERLESS_FRAME_STYLE (wxRESIZE_BORDER) +#define BORDERLESS_FRAME_STYLE (wxMINIMIZE_BOX | wxMAXIMIZE_BOX | wxCLOSE_BOX) #endif 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); panel_topbar->SetBackgroundColour(wxColour(38, 46, 48)); 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->Layout(); #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_SIZE, [this](wxSizeEvent&) { BOOST_LOG_TRIVIAL(trace) << "mainframe: size changed, is maximized = " << this->IsMaximized(); +#ifdef __WINDOWS__ if (this->IsMaximized()) { m_topbar->SetWindowSize(); } else { m_topbar->SetMaximizedSize(); } - Refresh(); - Layout(); +#endif + Refresh(); + Layout(); }); //BBS @@ -828,13 +828,14 @@ void MainFrame::init_tabpanel() //monitor } +#ifdef __WINDOWS__ if (sel == tp3DEditor) { m_topbar->EnableUndoRedoItems(); } else { m_topbar->DisableUndoRedoItems(); } - +#endif /*switch (sel) { case TabPosition::tpHome: @@ -1475,8 +1476,10 @@ void MainFrame::on_dpi_changed(const wxRect& suggested_rect) dynamic_cast(m_tabpanel)->Rescale(); #endif +#ifdef __WINDOWS__ // BBS m_topbar->Rescale(); +#endif m_tabpanel->Rescale(); @@ -1596,9 +1599,11 @@ static wxMenu* generate_help_menu() return true; }); // About +#ifdef __WINDOWS__ wxString about_title = wxString::Format(_L("&About %s"), SLIC3R_APP_FULL_NAME); append_menu_item(helpMenu, wxID_ANY, about_title, about_title, [](wxCommandEvent&) { Slic3r::GUI::about(); }); +#endif return helpMenu; } @@ -1628,6 +1633,7 @@ void MainFrame::init_menubar_as_editor() { #ifdef __APPLE__ wxMenuBar::SetAutoWindowMenu(false); + m_menubar = new wxMenuBar(); #endif // File menu @@ -1890,10 +1896,18 @@ void MainFrame::init_menubar_as_editor() //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()); //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", ""); - //auto printer_item = new wxMenuItem(m_topbar->GetTopMenu(), ConfigMenuPrinter + config_id_base, _L("Printer"), ""); - //auto language_item = new wxMenuItem(m_topbar->GetTopMenu(), ConfigMenuLanguage + config_id_base, _L("Switch Language"), ""); - m_topbar->GetTopMenu()->Bind(wxEVT_MENU, [this, config_id_base](wxEvent& event) { +#ifdef __APPLE__ + wxWindowID bambu_studio_id_base = wxWindow::NewControlId(int(2)); + wxMenu* parent_menu = m_menubar->OSXGetAppleMenu(); + 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) { //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 auto helpMenu = generate_help_menu(); + +#ifdef __WINDOWS__ m_topbar->SetFileMenu(fileMenu); if (editMenu) m_topbar->AddDropDownSubMenu(editMenu, _L("Edit")); @@ -1973,6 +2027,16 @@ void MainFrame::init_menubar_as_editor() //m_topbar->AddDropDownMenuItem(language_item); //m_topbar->AddDropDownMenuItem(config_item); 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 if (wxGetApp().tabs_as_menu()) @@ -1982,12 +2046,12 @@ void MainFrame::init_menubar_as_editor() #ifdef __APPLE__ // 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 - /* wxMenu* apple_menu = m_menubar->OSXGetAppleMenu(); + wxMenu* apple_menu = m_menubar->OSXGetAppleMenu(); if (apple_menu != nullptr) { apple_menu->Bind(wxEVT_MENU, [this](wxCommandEvent &) { Close(); }, wxID_EXIT); - }*/ + } #endif // __APPLE__ } diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 1d7f30743..d957a3f88 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -5557,7 +5557,11 @@ void Plater::priv::set_project_name(const wxString& project_name) { m_project_name = project_name; //update topbar title +#ifdef __WINDOWS__ wxGetApp().mainframe->topbar()->SetTitle(m_project_name); +#else + wxGetApp().mainframe->SetTitle(m_project_name); +#endif } void Plater::priv::set_project_filename(const wxString& filename)