diff options
author | Enrico Turri <enricoturri@seznam.cz> | 2018-10-17 13:17:25 +0300 |
---|---|---|
committer | Enrico Turri <enricoturri@seznam.cz> | 2018-10-17 13:17:25 +0300 |
commit | 7d1828df05e9f18cc988a6f4913a3e39b428f909 (patch) | |
tree | 3f44da0685a2bdb1b6d996c27cd0c74afb2c85d7 | |
parent | 3059438853cc75c6100a1a7b46c62a7e0eb3c95b (diff) |
Object context menu wip / Removed links to settings dialog from user interface / Fixed and unified append_menu_item() function / Fixed File->Open menu item / Fixed Window menu items / Added Plater menu
-rw-r--r-- | src/slic3r/GUI/GLCanvas3D.cpp | 9 | ||||
-rw-r--r-- | src/slic3r/GUI/GLCanvas3D.hpp | 2 | ||||
-rw-r--r-- | src/slic3r/GUI/GLToolbar.cpp | 2 | ||||
-rw-r--r-- | src/slic3r/GUI/GLToolbar.hpp | 2 | ||||
-rw-r--r-- | src/slic3r/GUI/GUI_App.cpp | 19 | ||||
-rw-r--r-- | src/slic3r/GUI/GUI_App.hpp | 9 | ||||
-rw-r--r-- | src/slic3r/GUI/MainFrame.cpp | 48 | ||||
-rw-r--r-- | src/slic3r/GUI/MainFrame.hpp | 11 | ||||
-rw-r--r-- | src/slic3r/GUI/Plater.cpp | 74 | ||||
-rw-r--r-- | src/slic3r/GUI/Plater.hpp | 2 | ||||
-rw-r--r-- | src/slic3r/GUI/wxExtensions.cpp | 14 | ||||
-rw-r--r-- | src/slic3r/GUI/wxExtensions.hpp | 3 |
12 files changed, 109 insertions, 86 deletions
diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index d41e59afe..f0568c5f0 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -2667,7 +2667,9 @@ wxDEFINE_EVENT(EVT_GLCANVAS_OBJECT_SELECT, SimpleEvent); wxDEFINE_EVENT(EVT_GLCANVAS_OBJECT_SELECT, ObjectSelectEvent); #endif // ENABLE_EXTENDED_SELECTION wxDEFINE_EVENT(EVT_GLCANVAS_VIEWPORT_CHANGED, SimpleEvent); +#if !ENABLE_EXTENDED_SELECTION wxDEFINE_EVENT(EVT_GLCANVAS_DOUBLE_CLICK, SimpleEvent); +#endif // !ENABLE_EXTENDED_SELECTION wxDEFINE_EVENT(EVT_GLCANVAS_RIGHT_CLICK, Vec2dEvent); wxDEFINE_EVENT(EVT_GLCANVAS_MODEL_UPDATE, SimpleEvent); wxDEFINE_EVENT(EVT_GLCANVAS_REMOVE_OBJECT, SimpleEvent); @@ -3439,6 +3441,9 @@ void GLCanvas3D::reload_scene(bool force) { load_object(*m_model, obj_idx); } + + // to update the toolbar + post_event(SimpleEvent(EVT_GLCANVAS_OBJECT_SELECT)); } update_gizmos_data(); @@ -3796,8 +3801,10 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) m_mouse.position = Vec2d(-1.0, -1.0); m_dirty = true; } +#if !ENABLE_EXTENDED_SELECTION else if (evt.LeftDClick() && (m_hover_volume_id != -1) && !gizmos_overlay_contains_mouse && (toolbar_contains_mouse == -1)) post_event(SimpleEvent(EVT_GLCANVAS_DOUBLE_CLICK)); +#endif // !ENABLE_EXTENDED_SELECTION else if (evt.LeftDClick() && (toolbar_contains_mouse != -1)) { m_toolbar_action_running = true; @@ -4559,6 +4566,7 @@ bool GLCanvas3D::_init_toolbar() if (!m_toolbar.add_separator()) return false; +#if !ENABLE_EXTENDED_SELECTION item.name = "settings"; item.tooltip = GUI::L_str("Settings..."); item.sprite_id = 8; @@ -4566,6 +4574,7 @@ bool GLCanvas3D::_init_toolbar() item.action_event = EVT_GLTOOLBAR_SETTINGS; if (!m_toolbar.add_item(item)) return false; +#endif // !ENABLE_EXTENDED_SELECTION item.name = "layersediting"; item.tooltip = GUI::L_str("Layers editing"); diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index c887f2c19..be9548a49 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -105,7 +105,9 @@ template <size_t N> using Vec3dsEvent = ArrayEvent<Vec3d, N>; wxDECLARE_EVENT(EVT_GLCANVAS_VIEWPORT_CHANGED, SimpleEvent); +#if !ENABLE_EXTENDED_SELECTION wxDECLARE_EVENT(EVT_GLCANVAS_DOUBLE_CLICK, SimpleEvent); +#endif // !ENABLE_EXTENDED_SELECTION wxDECLARE_EVENT(EVT_GLCANVAS_RIGHT_CLICK, Vec2dEvent); wxDECLARE_EVENT(EVT_GLCANVAS_MODEL_UPDATE, SimpleEvent); wxDECLARE_EVENT(EVT_GLCANVAS_REMOVE_OBJECT, SimpleEvent); diff --git a/src/slic3r/GUI/GLToolbar.cpp b/src/slic3r/GUI/GLToolbar.cpp index 479238368..ec203541e 100644 --- a/src/slic3r/GUI/GLToolbar.cpp +++ b/src/slic3r/GUI/GLToolbar.cpp @@ -24,7 +24,9 @@ wxDEFINE_EVENT(EVT_GLTOOLBAR_MORE, SimpleEvent); wxDEFINE_EVENT(EVT_GLTOOLBAR_FEWER, SimpleEvent); wxDEFINE_EVENT(EVT_GLTOOLBAR_SPLIT, SimpleEvent); wxDEFINE_EVENT(EVT_GLTOOLBAR_CUT, SimpleEvent); +#if !ENABLE_EXTENDED_SELECTION wxDEFINE_EVENT(EVT_GLTOOLBAR_SETTINGS, SimpleEvent); +#endif // !ENABLE_EXTENDED_SELECTION wxDEFINE_EVENT(EVT_GLTOOLBAR_LAYERSEDITING, SimpleEvent); #if !ENABLE_EXTENDED_SELECTION wxDEFINE_EVENT(EVT_GLTOOLBAR_SELECTBYPARTS, SimpleEvent); diff --git a/src/slic3r/GUI/GLToolbar.hpp b/src/slic3r/GUI/GLToolbar.hpp index dc4d10f37..7c0f5bf84 100644 --- a/src/slic3r/GUI/GLToolbar.hpp +++ b/src/slic3r/GUI/GLToolbar.hpp @@ -24,7 +24,9 @@ wxDECLARE_EVENT(EVT_GLTOOLBAR_MORE, SimpleEvent); wxDECLARE_EVENT(EVT_GLTOOLBAR_FEWER, SimpleEvent); wxDECLARE_EVENT(EVT_GLTOOLBAR_SPLIT, SimpleEvent); wxDECLARE_EVENT(EVT_GLTOOLBAR_CUT, SimpleEvent); +#if !ENABLE_EXTENDED_SELECTION wxDECLARE_EVENT(EVT_GLTOOLBAR_SETTINGS, SimpleEvent); +#endif // !ENABLE_EXTENDED_SELECTION wxDECLARE_EVENT(EVT_GLTOOLBAR_LAYERSEDITING, SimpleEvent); #if !ENABLE_EXTENDED_SELECTION wxDECLARE_EVENT(EVT_GLTOOLBAR_SELECTBYPARTS, SimpleEvent); diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index a01825d2b..fd4559a35 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -326,25 +326,6 @@ void GUI_App::CallAfter(std::function<void()> cb) callback_register.unlock(); } -wxMenuItem* GUI_App::append_menu_item( wxMenu* menu, - int id, - const wxString& string, - const wxString& description, - const std::string& icon, - std::function<void(wxCommandEvent& event)> cb, - wxItemKind kind/* = wxITEM_NORMAL*/) -{ - if (id == wxID_ANY) - id = wxNewId(); - auto item = new wxMenuItem(menu, id, string, description, kind); - if (!icon.empty()) - item->SetBitmap(wxBitmap(Slic3r::var(icon), wxBITMAP_TYPE_PNG)); - menu->Append(item); - - menu->Bind(wxEVT_MENU, /*[cb](wxCommandEvent& event){cb; }*/cb); - return item; -} - wxMenuItem* GUI_App::append_submenu(wxMenu* menu, wxMenu* sub_menu, int id, diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index 4578f4c00..ff910ed42 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -107,14 +107,7 @@ public: // void notify(/*message*/); void update_ui_from_settings(); void CallAfter(std::function<void()> cb); - wxMenuItem* append_menu_item( wxMenu* menu, - int id, - const wxString& string, - const wxString& description, - const std::string& icon, - std::function<void(wxCommandEvent& event)> cb, - wxItemKind kind = wxITEM_NORMAL); - wxMenuItem* append_submenu( wxMenu* menu, + wxMenuItem* append_submenu(wxMenu* menu, wxMenu* sub_menu, int id, const wxString& string, diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 505a45125..767f629fd 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -17,6 +17,7 @@ #include "Print.hpp" #include "Polygon.hpp" #include "AppConfig.hpp" +#include "wxExtensions.hpp" #include <fstream> #include "GUI_App.hpp" @@ -237,10 +238,8 @@ void MainFrame::init_menubar() // File menu wxMenu* fileMenu = new wxMenu; { - wxGetApp().append_menu_item(fileMenu, wxID_ANY, _(L("Open STL/OBJ/AMF/3MF…\tCtrl+O")), _(L("Open a model")), - "", [](wxCommandEvent&){ -// if (m_plater) m_plater->add(); - }); //'brick_add.png'); + append_menu_item(fileMenu, wxID_ANY, _(L("Open STL/OBJ/AMF/3MF…\tCtrl+O")), _(L("Open a model")), + [this](wxCommandEvent&) { if (m_plater) m_plater->add(); }, "brick_add.png"); append_menu_item(fileMenu, wxID_ANY, _(L("&Load Config…\tCtrl+L")), _(L("Load exported configuration file")), [this](wxCommandEvent&){ load_config_file(); }, "plugin_add.png"); append_menu_item(fileMenu, wxID_ANY, _(L("&Export Config…\tCtrl+E")), _(L("Export current configuration to file")), @@ -285,19 +284,16 @@ void MainFrame::init_menubar() } // Plater menu - if(m_plater) { - auto plater_menu = new wxMenu(); - append_menu_item(plater_menu, wxID_ANY, L("Export G-code..."), L("Export current plate as G-code"), + if (m_plater) { + m_plater_menu = new wxMenu(); + append_menu_item(m_plater_menu, wxID_ANY, _(L("Export G-code...")), _(L("Export current plate as G-code")), [this](wxCommandEvent&){ /*m_plater->export_gcode(); */}, "cog_go.png"); - append_menu_item(plater_menu, wxID_ANY, L("Export plate as STL..."), L("Export current plate as STL"), + append_menu_item(m_plater_menu, wxID_ANY, _(L("Export plate as STL...")), _(L("Export current plate as STL")), [this](wxCommandEvent&){ /*m_plater->export_stl(); */}, "brick_go.png"); - append_menu_item(plater_menu, wxID_ANY, L("Export plate as AMF..."), L("Export current plate as AMF"), + append_menu_item(m_plater_menu, wxID_ANY, _(L("Export plate as AMF...")), _(L("Export current plate as AMF")), [this](wxCommandEvent&){ /*m_plater->export_amf();*/ }, "brick_go.png"); - append_menu_item(plater_menu, wxID_ANY, L("Export plate as 3MF..."), L("Export current plate as 3MF"), + append_menu_item(m_plater_menu, wxID_ANY, _(L("Export plate as 3MF...")), _(L("Export current plate as 3MF")), [this](wxCommandEvent&){ /*m_plater->export_3mf(); */}, "brick_go.png"); - -// m_object_menu = m_plater->object_menu; - on_plater_selection_changed(false); } // Window menu @@ -375,7 +371,6 @@ void MainFrame::init_menubar() auto menubar = new wxMenuBar(); menubar->Append(fileMenu, L("&File")); if (m_plater_menu) menubar->Append(m_plater_menu, L("&Plater")) ; - if (m_object_menu) menubar->Append(m_object_menu, L("&Object")) ; menubar->Append(windowMenu, L("&Window")); if (m_viewMenu) menubar->Append(m_viewMenu, L("&View")); // Add additional menus from C++ @@ -385,15 +380,6 @@ void MainFrame::init_menubar() } } -// Selection of a 3D object changed on the platter. -void MainFrame::on_plater_selection_changed(const bool have_selection) -{ - if (!m_object_menu) return; - - for (auto item : m_object_menu->GetMenuItems()) - m_object_menu->Enable(item->GetId(), have_selection); -} - void MainFrame::slice_to_png(){ // m_plater->stop_background_process(); // m_plater->async_apply_config(); @@ -702,22 +688,6 @@ void MainFrame::select_view(const std::string& direction){ // m_plater->select_view(direction); } -wxMenuItem* MainFrame::append_menu_item(wxMenu* menu, - int id, - const wxString& string, - const wxString& description, - std::function<void(wxCommandEvent& event)> cb, - const std::string& icon /*= ""*/) -{ - if (id == wxID_ANY) - id = wxNewId(); - auto item = menu->Append(id, string, description); - if (!icon.empty()) - item->SetBitmap(wxBitmap(Slic3r::var(icon), wxBITMAP_TYPE_PNG)); - menu->Bind(wxEVT_MENU, /*[cb](wxCommandEvent& event){cb; }*/cb); - return item; -} - void MainFrame::on_presets_changed(SimpleEvent &event) { auto *tab = dynamic_cast<Tab*>(event.GetEventObject()); diff --git a/src/slic3r/GUI/MainFrame.hpp b/src/slic3r/GUI/MainFrame.hpp index ed2646b69..1015e783c 100644 --- a/src/slic3r/GUI/MainFrame.hpp +++ b/src/slic3r/GUI/MainFrame.hpp @@ -57,17 +57,9 @@ class MainFrame : public wxFrame AppController* m_appController { nullptr }; std::map<std::string, Tab*> m_options_tabs; - wxMenuItem* append_menu_item(wxMenu* menu, - int id, - const wxString& string, - const wxString& description, - std::function<void(wxCommandEvent& event)> cb, - const std::string& icon = ""); - wxMenuItem* m_menu_item_reslice_now { nullptr }; wxMenu* m_plater_menu { nullptr }; - wxMenu* m_object_menu { nullptr }; - wxMenu* m_viewMenu { nullptr }; + wxMenu* m_viewMenu{ nullptr }; std::string get_base_name(const wxString full_name) const ; std::string get_dir_name(const wxString full_name) const ; @@ -93,7 +85,6 @@ public: bool is_loaded() const { return m_loaded; } bool is_last_input_file() const { return !m_qs_last_input_file.IsEmpty(); } - void on_plater_selection_changed(const bool have_selection); void slice_to_png(); void quick_slice(const int qs = qsUndef); void reslice_now(); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index cd0dc278d..f6e3983d9 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -37,6 +37,7 @@ #include "GUI_ObjectList.hpp" #include "GUI_ObjectManipulation.hpp" #include "GUI_Utils.hpp" +#include "wxExtensions.hpp" #include "MainFrame.hpp" #include "3DScene.hpp" #include "GLCanvas3D.hpp" @@ -727,6 +728,9 @@ struct Plater::priv Plater *q; MainFrame *main_frame; + // Object popup menu + wxMenu* object_menu; + // Data Slic3r::DynamicPrintConfig *config; Slic3r::Print print; @@ -751,6 +755,7 @@ struct Plater::priv static const std::regex pattern_zip_amf; priv(Plater *q, MainFrame *main_frame); + ~priv(); #if !ENABLE_EXTENDED_SELECTION std::vector<int> collect_selections(); @@ -804,7 +809,9 @@ struct Plater::priv void on_action_add(SimpleEvent&); void on_action_split(SimpleEvent&); void on_action_cut(SimpleEvent&); +#if !ENABLE_EXTENDED_SELECTION void on_action_settings(SimpleEvent&); +#endif // !ENABLE_EXTENDED_SELECTION void on_action_layersediting(SimpleEvent&); #if !ENABLE_EXTENDED_SELECTION void on_action_selectbyparts(SimpleEvent&); @@ -824,6 +831,9 @@ struct Plater::priv void on_wipetower_moved(Vec3dEvent&); void on_enable_action_buttons(Event<bool>&); void on_update_geometry(Vec3dsEvent<2>&); + +private: + bool init_object_menu(); }; const std::regex Plater::priv::pattern_bundle("[.](amf|amf[.]xml|zip[.]amf|3mf|prusa)$", std::regex::icase); @@ -833,6 +843,7 @@ const std::regex Plater::priv::pattern_zip_amf("[.]zip[.]amf$", std::regex::icas Plater::priv::priv(Plater *q, MainFrame *main_frame) : q(q), main_frame(main_frame), + object_menu(nullptr), config(Slic3r::DynamicPrintConfig::new_from_defaults_keys({ "bed_shape", "complete_objects", "extruder_clearance_radius", "skirts", "skirt_distance", "brim_width", "variable_layer_height", "serial_port", "serial_speed", "host_type", "print_host", @@ -892,6 +903,8 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) : hsizer->Add(sidebar, 0, wxEXPAND | wxLEFT | wxRIGHT, 0); q->SetSizer(hsizer); + init_object_menu(); + // Events: // Notebook page change event @@ -903,7 +916,9 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) : // 3DScene events: canvas3D->Bind(EVT_GLCANVAS_OBJECT_SELECT, &priv::on_object_select, this); canvas3D->Bind(EVT_GLCANVAS_VIEWPORT_CHANGED, &priv::on_viewport_changed, this); - // canvas3D->Bind(EVT_GLCANVAS_DOUBLE_CLICK, [](SimpleEvent&) { }); // XXX: remove? +#if !ENABLE_EXTENDED_SELECTION + canvas3D->Bind(EVT_GLCANVAS_DOUBLE_CLICK, [](SimpleEvent&) {}); // XXX: remove? +#endif // !ENABLE_EXTENDED_SELECTION canvas3D->Bind(EVT_GLCANVAS_RIGHT_CLICK, &priv::on_right_click, this); canvas3D->Bind(EVT_GLCANVAS_MODEL_UPDATE, &priv::on_model_update, this); canvas3D->Bind(EVT_GLCANVAS_REMOVE_OBJECT, [q](SimpleEvent&) { q->remove_selected(); }); @@ -924,7 +939,9 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) : canvas3D->Bind(EVT_GLTOOLBAR_FEWER, [q](SimpleEvent&) { q->decrease(); }); canvas3D->Bind(EVT_GLTOOLBAR_SPLIT, &priv::on_action_split, this); canvas3D->Bind(EVT_GLTOOLBAR_CUT, &priv::on_action_cut, this); +#if !ENABLE_EXTENDED_SELECTION canvas3D->Bind(EVT_GLTOOLBAR_SETTINGS, &priv::on_action_settings, this); +#endif // !ENABLE_EXTENDED_SELECTION canvas3D->Bind(EVT_GLTOOLBAR_LAYERSEDITING, &priv::on_action_layersediting, this); #if !ENABLE_EXTENDED_SELECTION canvas3D->Bind(EVT_GLTOOLBAR_SELECTBYPARTS, &priv::on_action_selectbyparts, this); @@ -943,6 +960,12 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) : q->Layout(); } +Plater::priv::~priv() +{ + if (object_menu != nullptr) + delete object_menu; +} + #if !ENABLE_EXTENDED_SELECTION std::vector<int> Plater::priv::collect_selections() { @@ -1645,14 +1668,8 @@ void Plater::priv::on_layer_editing_toggled(bool enable) void Plater::priv::on_action_add(SimpleEvent&) { - wxArrayString input_files; - wxGetApp().open_model(q, input_files); - - std::vector<fs::path> input_paths; - for (const auto &file : input_files) { - input_paths.push_back(file.wx_str()); - } - load_files(input_paths); + if (q != nullptr) + q->add(); } void Plater::priv::on_action_split(SimpleEvent&) @@ -1665,10 +1682,12 @@ void Plater::priv::on_action_cut(SimpleEvent&) // TODO } +#if !ENABLE_EXTENDED_SELECTION void Plater::priv::on_action_settings(SimpleEvent&) { // TODO } +#endif // !ENABLE_EXTENDED_SELECTION void Plater::priv::on_action_layersediting(SimpleEvent&) { @@ -1712,9 +1731,18 @@ void Plater::priv::on_viewport_changed(SimpleEvent& evt) preview->set_viewport_from_scene(canvas3D); } -void Plater::priv::on_right_click(Vec2dEvent&) +void Plater::priv::on_right_click(Vec2dEvent& evt) { +#if ENABLE_EXTENDED_SELECTION + int obj_idx = get_selected_object_idx(); + if (obj_idx == -1) + return; + + if ((q != nullptr) && (object_menu != nullptr)) + q->PopupMenu(object_menu, (int)evt.data.x(), (int)evt.data.y()); +#else // TODO +#endif // ENABLE_EXTENDED_SELECTION } void Plater::priv::on_model_update(SimpleEvent&) @@ -1777,6 +1805,20 @@ void Plater::priv::on_update_geometry(Vec3dsEvent<2>&) // TODO } +bool Plater::priv::init_object_menu() +{ + if (main_frame == nullptr) + return false; + + object_menu = new wxMenu(); + if (object_menu == nullptr) + return false; + + append_menu_item(object_menu, wxID_ANY, _(L("Delete…\tDel")), _(L("Remove the selected object")), + [this](wxCommandEvent&){ q->remove_selected(); }, "brick_delete.png"); + + return true; +} // Plater / Public @@ -1795,6 +1837,18 @@ Sidebar& Plater::sidebar() { return *p->sidebar; } Model& Plater::model() { return p->model; } Print& Plater::print() { return p->print; } +void Plater::add() +{ + wxArrayString input_files; + wxGetApp().open_model(this, input_files); + + std::vector<fs::path> input_paths; + for (const auto &file : input_files) { + input_paths.push_back(file.wx_str()); + } + load_files(input_paths); +} + void Plater::load_files(const std::vector<fs::path> &input_files) { p->load_files(input_files); } void Plater::update(bool force_autocenter) { p->update(force_autocenter); } diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index fba2e0dc0..135dcfcde 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -104,6 +104,8 @@ public: Model& model(); Print& print(); + void add(); + void load_files(const std::vector<boost::filesystem::path> &input_files); void update(bool force_autocenter = false); diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp index be3715641..4eaffe49f 100644 --- a/src/slic3r/GUI/wxExtensions.cpp +++ b/src/slic3r/GUI/wxExtensions.cpp @@ -10,6 +10,20 @@ #include "GUI_App.hpp" #include "GUI_ObjectList.hpp" +wxMenuItem* append_menu_item(wxMenu* menu, int id, const wxString& string, const wxString& description, + std::function<void(wxCommandEvent& event)> cb, const std::string& icon) +{ + if (id == wxID_ANY) + id = wxNewId(); + + wxMenuItem* item = menu->Append(id, string, description); + if (!icon.empty()) + item->SetBitmap(wxBitmap(Slic3r::var(icon), wxBITMAP_TYPE_PNG)); + + menu->Bind(wxEVT_MENU, cb, id); + return item; +} + const unsigned int wxCheckListBoxComboPopup::DefaultWidth = 200; const unsigned int wxCheckListBoxComboPopup::DefaultHeight = 200; const unsigned int wxCheckListBoxComboPopup::DefaultItemHeight = 18; diff --git a/src/slic3r/GUI/wxExtensions.hpp b/src/slic3r/GUI/wxExtensions.hpp index e199a1648..07f56e643 100644 --- a/src/slic3r/GUI/wxExtensions.hpp +++ b/src/slic3r/GUI/wxExtensions.hpp @@ -13,6 +13,9 @@ #include <vector> #include <set> +wxMenuItem* append_menu_item(wxMenu* menu, int id, const wxString& string, const wxString& description, + std::function<void(wxCommandEvent& event)> cb, const std::string& icon = ""); + class wxCheckListBoxComboPopup : public wxCheckListBox, public wxComboPopup { static const unsigned int DefaultWidth; |