From 5f7a4982f6ab241a5576df1ced11fddbe6ccdafb Mon Sep 17 00:00:00 2001 From: David Kocik Date: Wed, 1 Sep 2021 16:49:23 +0200 Subject: [PATCH] Open menubar item by name with translations --- resources/data/hints.ini | 10 ++++----- src/slic3r/GUI/HintNotification.cpp | 6 +++--- src/slic3r/GUI/MainFrame.cpp | 33 +++++++++++++++++------------ src/slic3r/GUI/MainFrame.hpp | 4 ++-- 4 files changed, 29 insertions(+), 24 deletions(-) diff --git a/resources/data/hints.ini b/resources/data/hints.ini index 5c89e93e0..e7b1bb681 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 cf35022c2..75bb69a65 100644 --- a/src/slic3r/GUI/HintNotification.cpp +++ b/src/slic3r/GUI/HintNotification.cpp @@ -379,9 +379,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/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 3d486f052..eb309b1af 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 093e9e5c4..e87f94f65 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