Open menubar item by item index. Possible to call as hint notification hyperlink

This commit is contained in:
David Kocik 2021-09-01 10:25:46 +02:00
parent a72f50efa5
commit 229cf4b8b6
4 changed files with 39 additions and 15 deletions

View file

@ -4,6 +4,7 @@
#include "I18N.hpp"
#include "GUI_ObjectList.hpp"
#include "GLCanvas3D.hpp"
#include "MainFrame.hpp"
#include "libslic3r/AppConfig.hpp"
#include "libslic3r/Utils.hpp"
#include "libslic3r/Config.hpp"
@ -57,10 +58,6 @@ inline void push_style_color(ImGuiCol idx, const ImVec4& col, bool fading_out, f
ImGui::PushStyleColor(idx, col);
}
void write_used_binary(const std::vector<std::string>& ids)
{
boost::filesystem::ofstream file((boost::filesystem::path(data_dir()) / "cache" / "hints.cereal"), std::ios::binary);
@ -379,7 +376,13 @@ void HintDatabase::load_hints_from_file(const boost::filesystem::path& path)
HintData hint_data{ id_string, text1, weight, was_displayed, hypertext_text, follow_text, disabled_tags, enabled_tags, false, documentation_link, []() {
// Deselect all objects, otherwise gallery wont show.
wxGetApp().plater()->canvas3D()->deselect_all();
wxGetApp().obj_list()->load_shape_object_from_gallery(); } };
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());
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);
}
} else {

View file

@ -1479,6 +1479,27 @@ void MainFrame::init_menubar_as_editor()
update_menubar();
}
void MainFrame::open_menubar_item(int menu_index, int item_index)
{
if (m_menubar == nullptr)
return;
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;
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;
return;
}
wxPostEvent((wxEvtHandler*)menu, wxCommandEvent(wxEVT_MENU, item->GetId()));
}
void MainFrame::init_menubar_as_gcodeviewer()
{
wxMenu* fileMenu = new wxMenu;

View file

@ -158,6 +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);
#ifdef _WIN32
void show_tabs_menu(bool show);
#endif