diff --git a/resources/data/hints.ini b/resources/data/hints.ini index 5c89e93e07..e7b1bb6814 100644 --- a/resources/data/hints.ini +++ b/resources/data/hints.ini @@ -40,8 +40,8 @@ # hypertext_type = gallery # #Open top menubar item -#hypertext_menubar_menu_id = 4 (0 - 5, index of menu from left: File = 0, Edit = 1...) -#hypertext_menubar_item_id = 1 (index of item, starting at 0, Including separators! In Window: 0 = Plater Tab, 1 = SEPARATOR, 2 = Print Setting Tab...) +#hypertext_menubar_menu_name = (Name in english visible as menu name: File, ) +#hypertext_menubar_item_name = (Name of item in english, if there are three dots at the end of name, put name without three dots) # # # Each notification can have disabled and enabled modes and techs - divided by ; and space @@ -196,9 +196,9 @@ disabled_tags = SLA [hint:Configuration snapshots] text = Configuration snapshots\nDid you know that roll back to a complete backup of all system and user profiles? You can view and move back and forth between snapshots using the Configuration - Configuration snapshots menu. documentation_link = https://help.prusa3d.com/en/article/configuration-snapshots_1776 -#hypertext_type = menubar -#hypertext_menubar_menu_id = 4 -#hypertext_menubar_item_id = 1 +hypertext_type = menubar +hypertext_menubar_menu_name = Configuration +hypertext_menubar_item_name = Configuration Snapshots [hint:Minimum wall thickness] text = Minimum wall thickness\nDid you know that instead of the number of top and bottom layers, you can define theMinimum shell thicknessin millimeters? This feature is especially useful when using the variable layer height function. diff --git a/src/slic3r/GUI/HintNotification.cpp b/src/slic3r/GUI/HintNotification.cpp index cf35022c2a..d1a2328e9a 100644 --- a/src/slic3r/GUI/HintNotification.cpp +++ b/src/slic3r/GUI/HintNotification.cpp @@ -242,6 +242,13 @@ HintDatabase::~HintDatabase() write_used_binary(m_used_ids); } } +void HintDatabase::uninit() +{ + if (m_initialized) { + write_used_binary(m_used_ids); + } + m_initialized = false; +} void HintDatabase::init() { load_hints_from_file(std::move(boost::filesystem::path(resources_dir()) / "data" / "hints.ini")); @@ -379,9 +386,9 @@ void HintDatabase::load_hints_from_file(const boost::filesystem::path& path) wxGetApp().obj_list()->load_shape_object_from_gallery(); } }; m_loaded_hints.emplace_back(hint_data); - } /*else if (dict["hypertext_type"] == "menubar") { - int menu = std::atoi(dict["hypertext_menubar_menu_id"].c_str()); - int item = std::atoi(dict["hypertext_menubar_item_id"].c_str()); + } else if (dict["hypertext_type"] == "menubar") { + wxString menu(_L("&" + dict["hypertext_menubar_menu_name"])); + wxString item(_L(dict["hypertext_menubar_item_name"])); HintData hint_data{ id_string, text1, weight, was_displayed, hypertext_text, follow_text, disabled_tags, enabled_tags, true, documentation_link, [menu, item]() { wxGetApp().mainframe->open_menubar_item(menu, item); } }; m_loaded_hints.emplace_back(hint_data); }*/ diff --git a/src/slic3r/GUI/HintNotification.hpp b/src/slic3r/GUI/HintNotification.hpp index c1e7c0ed3c..e5dd90bdbd 100644 --- a/src/slic3r/GUI/HintNotification.hpp +++ b/src/slic3r/GUI/HintNotification.hpp @@ -47,6 +47,9 @@ public: return 0; return m_loaded_hints.size(); } + // resets m_initiailized to false and writes used if was initialized + // used when reloading in runtime - like change language + void uninit(); private: void init(); void load_hints_from_file(const boost::filesystem::path& path); diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 3d486f052d..eb309b1afb 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -1480,29 +1480,34 @@ void MainFrame::init_menubar_as_editor() if (plater()->printer_technology() == ptSLA) update_menubar(); } -/* -void MainFrame::open_menubar_item(int menu_index, int item_index) + +void MainFrame::open_menubar_item(const wxString& menu_name,const wxString& item_name) { if (m_menubar == nullptr) return; - wxMenu* menu = m_menubar->GetMenu(menu_index); + // Get menu object from menubar + int menu_index = m_menubar->FindMenu(menu_name); + wxMenu* menu = m_menubar->GetMenu(menu_index); if (menu == nullptr) { - BOOST_LOG_TRIVIAL(error) << "Mainframe open_menubar_item function couldn't find menu: " << menu_index; + BOOST_LOG_TRIVIAL(error) << "Mainframe open_menubar_item function couldn't find menu: " << menu_name; return; } - wxMenuItemList items = menu->GetMenuItems(); - if (items.size() <= item_index) { - BOOST_LOG_TRIVIAL(error) << "Mainframe open_menubar_item function couldn't find item: " << item_index; - return; - } - wxMenuItem* item = items[item_index]; - if (item == nullptr) { - BOOST_LOG_TRIVIAL(error) << "Mainframe open_menubar_item function couldn't find item: " << item_index; + // Get item id from menu + int item_id = menu->FindItem(item_name); + if (item_id == wxNOT_FOUND) + { + // try adding three dots char + item_id = menu->FindItem(item_name + dots); + } + if (item_id == wxNOT_FOUND) + { + BOOST_LOG_TRIVIAL(error) << "Mainframe open_menubar_item function couldn't find item: " << item_name; return; } - wxPostEvent((wxEvtHandler*)menu, wxCommandEvent(wxEVT_MENU, item->GetId())); + // wxEVT_MENU will trigger item + wxPostEvent((wxEvtHandler*)menu, wxCommandEvent(wxEVT_MENU, item_id)); } -*/ + void MainFrame::init_menubar_as_gcodeviewer() { wxMenu* fileMenu = new wxMenu; diff --git a/src/slic3r/GUI/MainFrame.hpp b/src/slic3r/GUI/MainFrame.hpp index 093e9e5c47..e87f94f650 100644 --- a/src/slic3r/GUI/MainFrame.hpp +++ b/src/slic3r/GUI/MainFrame.hpp @@ -158,8 +158,8 @@ public: void init_menubar_as_editor(); void init_menubar_as_gcodeviewer(); void update_menubar(); - // Open item in menu by menu and item index (visible order of items including separators) - //void open_menubar_item(int menu_index, int item_index); + // Open item in menu by menu and item name (in actual language) + void open_menubar_item(const wxString& menu_name,const wxString& item_name); #ifdef _WIN32 void show_tabs_menu(bool show); #endif diff --git a/src/slic3r/GUI/NotificationManager.cpp b/src/slic3r/GUI/NotificationManager.cpp index 219faf42ef..4e94d82608 100644 --- a/src/slic3r/GUI/NotificationManager.cpp +++ b/src/slic3r/GUI/NotificationManager.cpp @@ -1107,6 +1107,10 @@ NotificationManager::NotificationManager(wxEvtHandler* evt_handler) : m_evt_handler(evt_handler) { } +NotificationManager::~NotificationManager() +{ + HintDatabase::get_instance().uninit(); +} void NotificationManager::push_notification(const NotificationType type, int timestamp) { auto it = std::find_if(std::begin(basic_notifications), std::end(basic_notifications), diff --git a/src/slic3r/GUI/NotificationManager.hpp b/src/slic3r/GUI/NotificationManager.hpp index 4aba35f4cb..1e667e4525 100644 --- a/src/slic3r/GUI/NotificationManager.hpp +++ b/src/slic3r/GUI/NotificationManager.hpp @@ -121,6 +121,7 @@ public: }; NotificationManager(wxEvtHandler* evt_handler); + ~NotificationManager(); // Push a prefabricated notification from basic_notifications (see the table at the end of this file). void push_notification(const NotificationType type, int timestamp = 0); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index f80f2cc3b5..b86092795d 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -2073,6 +2073,8 @@ Plater::priv::~priv() { if (config != nullptr) delete config; + if (notification_manager != nullptr) + delete notification_manager; } void Plater::priv::update(unsigned int flags)