346{
347 namespace pt = boost::property_tree;
348 pt::ptree tree;
349 boost::nowide::ifstream ifs(path.string());
350 try {
351 pt::read_ini(ifs, tree);
352 }
353 catch (const boost::property_tree::ini_parser::ini_parser_error& err) {
354 throw Slic3r::RuntimeError(
format(
"Failed loading hints file \"%1%\"\nError: \"%2%\" at line %3%", path, err.message(), err.line()).c_str());
355 }
356
357 for (const auto& section : tree) {
358 if (boost::starts_with(section.first, "hint:")) {
359
360 std::map<std::string, std::string> dict;
361 for (const auto& data : section.second) {
362 dict.emplace(data.first, data.second.data());
363 }
364
365 std::string id_string = section.first.substr(5);
366 id_string = std::to_string(std::hash<std::string>{}(id_string));
367
368 std::string fulltext;
369 std::string text1;
370 std::string hypertext_text;
371 std::string follow_text;
372
373 std::string disabled_tags;
374 std::string enabled_tags;
375
376 std::string documentation_link;
377 std::string img_url;
378
379 size_t weight = 1;
380 bool was_displayed =
is_used(id_string);
381
383 fulltext =
_utf8(fulltext);
384#ifdef __APPLE__
385 boost::replace_all(fulltext, "Ctrl+", "?");
386#endif
387
388 std::string marker_s(1, ImGui::ColorMarkerStart);
389 std::string marker_e(1, ImGui::ColorMarkerEnd);
390
392 while (marker_pos != std::string::npos) {
393 fulltext.replace(marker_pos, 3, marker_s);
395 }
396
398 while (marker_pos != std::string::npos) {
399 fulltext.replace(marker_pos, 4, marker_e);
401 }
402
404 if (hypertext_start != std::string::npos) {
405
408
409 BOOST_LOG_TRIVIAL(error) <<
"Hint notification with multiple hypertexts: " <<
_utf8(dict[
"text"]);
410 continue;
411 }
413 if (hypertext_end == std::string::npos) {
414
415 BOOST_LOG_TRIVIAL(error) <<
"Hint notification without hypertext end marker: " <<
_utf8(dict[
"text"]);
416 continue;
417 }
420
421 BOOST_LOG_TRIVIAL(error) <<
"Hint notification with multiple hypertext end markers: " <<
_utf8(dict[
"text"]);
422 continue;
423 }
424
425 text1 = fulltext.substr(0, hypertext_start);
426 hypertext_text = fulltext.substr(hypertext_start, hypertext_end - hypertext_start);
427 follow_text = fulltext.substr(hypertext_end);
428 }
429 else {
430 text1 = fulltext;
431 }
432
433 if (dict.find("disabled_tags") != dict.end()) {
434 disabled_tags = dict["disabled_tags"];
435 }
436 if (dict.find("enabled_tags") != dict.end()) {
437 enabled_tags = dict["enabled_tags"];
438 }
439 if (dict.find("documentation_link") != dict.end()) {
440 documentation_link = dict["documentation_link"];
441 }
442 if (dict.find("image") != dict.end()) {
443 img_url = dict["image"];
444 }
445
446 if (dict.find("weight") != dict.end()) {
447 weight = (size_t)std::max(1, std::atoi(dict["weight"].c_str()));
448 }
449
450
451 if (dict.find("hypertext_type") != dict.end()) {
452
453 if (dict["hypertext_type"] == "link") {
454 std::string hypertext_link = dict["hypertext_link"];
455 HintData hint_data{ id_string, text1, weight, was_displayed, hypertext_text, follow_text, disabled_tags, enabled_tags,
false, documentation_link, img_url, [hypertext_link]() {
launch_browser_if_allowed(hypertext_link); } };
457
458 }
459 else if (dict["hypertext_type"] == "settings") {
460 std::string opt = dict["hypertext_settings_opt"];
462 std::wstring category = boost::nowide::widen(dict["hypertext_settings_category"]);
463 HintData hint_data{ id_string, text1, weight, was_displayed, hypertext_text, follow_text, disabled_tags, enabled_tags, true, documentation_link, img_url, [opt, type, category]() { GUI::wxGetApp().sidebar().jump_to_option(opt, type, category); } };
465
466 }
467 else if (dict["hypertext_type"] == "preferences") {
468 std::string item = dict["hypertext_preferences_item"];
469 HintData hint_data{ id_string, text1, weight, was_displayed, hypertext_text, follow_text, disabled_tags, enabled_tags,
false, documentation_link, img_url, [item]() { wxGetApp().open_preferences(
PreferencesTab::Control, item); } };
471 }
472 else if (dict["hypertext_type"] == "plater") {
473 std::string item = dict["hypertext_plater_item"];
474 HintData hint_data{ id_string, text1, weight, was_displayed, hypertext_text, follow_text, disabled_tags, enabled_tags, true, documentation_link, img_url, [item]() { wxGetApp().plater()->canvas3D()->highlight_toolbar_item(item); } };
476 }
477 else if (dict["hypertext_type"] == "gizmo") {
478 std::string item = dict["hypertext_gizmo_item"];
479 HintData hint_data{ id_string, text1, weight, was_displayed, hypertext_text, follow_text, disabled_tags, enabled_tags, true, documentation_link, img_url, [item]() { wxGetApp().plater()->canvas3D()->highlight_gizmo(item); } };
481 }
482 else if (dict["hypertext_type"] == "gallery") {
483 HintData hint_data{ id_string, text1, weight, was_displayed, hypertext_text, follow_text, disabled_tags, enabled_tags, false, documentation_link, img_url, []() {
484
485 wxGetApp().plater()->canvas3D()->deselect_all();
486
487 } };
489 }
490 else if (dict["hypertext_type"] == "menubar") {
491 wxString menu(
_(
"&" + dict[
"hypertext_menubar_menu_name"]));
492 wxString item(
_(dict[
"hypertext_menubar_item_name"]));
493 HintData hint_data{ id_string, text1, weight, was_displayed, hypertext_text, follow_text, disabled_tags, enabled_tags, true, documentation_link, img_url, [menu, item]() { wxGetApp().mainframe->open_menubar_item(menu, item); } };
495 }
496 }
497 else {
498
499 HintData hint_data{ id_string, text1, weight, was_displayed, hypertext_text, follow_text, disabled_tags, enabled_tags, false, documentation_link, img_url };
501 }
502 }
503 }
504}
#define _(s)
Definition 3mf.cpp:306
bool is_used(const std::string &id)
Definition HintNotification.cpp:591
Type
Definition Preset.hpp:244
void launch_browser_if_allowed(const std::string &url)
Definition HintNotification.cpp:306
const std::string HYPERTEXT_MARKER_START
Definition HintNotification.cpp:77
@ Control
Definition Preferences.hpp:40
const std::string HYPERTEXT_MARKER_END
Definition HintNotification.cpp:78
std::string format(const char *fmt, TArgs &&... args)
Definition format.hpp:36
const std::string BOLD_MARKER_END
Definition HintNotification.cpp:76
const std::string BOLD_MARKER_START
Definition HintNotification.cpp:75
bool unescape_string_cstyle(const std::string &str, std::string &str_out)
Definition Config.cpp:150
#define _utf8(s)
Definition I18N.hpp:10