Merge branch 'dk_notifications'

This commit is contained in:
David Kocik 2021-09-02 09:48:31 +02:00
commit b45ae0170b
8 changed files with 46 additions and 24 deletions

View file

@ -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 the<a>Minimum shell thickness</a>in millimeters? This feature is especially useful when using the variable layer height function.

View file

@ -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);
}*/

View file

@ -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);

View file

@ -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;

View file

@ -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

View file

@ -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),

View file

@ -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);

View file

@ -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)