From 8200c9ed5f58d01a58851fdb9132ece76f785a24 Mon Sep 17 00:00:00 2001 From: Filip Sykala Date: Mon, 11 Oct 2021 16:07:04 +0200 Subject: [PATCH] hide filepath --- src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp | 21 ++++++++++++++------- src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp | 3 +++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index a7d180585d..8171a83574 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -614,9 +614,7 @@ bool GLGizmoEmboss::choose_true_type_file() bool font_loaded = false; for (auto &input_file : input_files) { std::string path = std::string(input_file.c_str()); - size_t pos = path.find_last_of('\\'); - size_t pos2 = path.find_last_of('.'); - std::string name = path.substr(pos + 1, pos2 - pos - 1); + std::string name = get_file_name(path); m_font_list.emplace_back(name, path); // set first valid added font as active @@ -643,9 +641,7 @@ bool GLGizmoEmboss::choose_svg_file() if (input_files.size() != 1) return false; auto &input_file = input_files.front(); std::string path = std::string(input_file.c_str()); - size_t pos = path.find_last_of('\\'); - size_t pos2 = path.find_last_of('.'); - std::string name = path.substr(pos + 1, pos2 - pos - 1); + std::string name = get_file_name(path); NSVGimage *image = nsvgParseFromFile(path.c_str(), "mm", 96.0f); ExPolygons polys = NSVGUtils::to_ExPolygons(image); @@ -664,6 +660,14 @@ bool GLGizmoEmboss::choose_svg_file() return add_volume(name, its); } +std::string GLGizmoEmboss::get_file_name(const std::string &file_path) { + size_t pos_last_delimiter = file_path.find_last_of('\\'); + size_t pos_point = file_path.find_last_of('.'); + size_t offset = pos_last_delimiter + 1; + size_t count = pos_point - pos_last_delimiter - 1; + return file_path.substr(offset, count); +} + TextConfiguration GLGizmoEmboss::create_configuration() { return TextConfiguration(m_font_list[m_font_selected], m_font_prop, m_text); } @@ -741,11 +745,14 @@ void GLGizmoEmboss::notify_cant_load_font(const FontItem &font_item) { auto type = NotificationType::CustomNotification; auto level = NotificationManager::NotificationLevel::WarningNotificationLevel; std::string font_type_name = TextConfigurationSerialization::serialize(font_item.type); + std::string value = font_item.path; + // discard file path + if (font_item.type == FontItem::Type::file_path) value = get_file_name(value); std::string text = GUI::format(_L("WARNING: Can't load font (name=\"%1%\", type=\"%2%\", value=\"%3%\"), " "Selected font is different. " "When you edit, actual font will be used."), - font_item.name, font_type_name, font_item.path); + font_item.name, font_type_name, value); auto notification_manager = wxGetApp().plater()->get_notification_manager(); notification_manager->push_notification(type, level, text); } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp index 59e630410f..3dd71192ba 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp @@ -58,6 +58,9 @@ private: bool choose_true_type_file(); bool choose_svg_file(); + // TODO: move to file utils + static std::string get_file_name(const std::string &file_path); + // Create object described how to make a Volume TextConfiguration create_configuration(); bool load_configuration(ModelVolume *volume);