hide filepath

This commit is contained in:
Filip Sykala 2021-10-11 16:07:04 +02:00
parent 905d6f4be7
commit 8200c9ed5f
2 changed files with 17 additions and 7 deletions

View File

@ -614,9 +614,7 @@ bool GLGizmoEmboss::choose_true_type_file()
bool font_loaded = false; bool font_loaded = false;
for (auto &input_file : input_files) { for (auto &input_file : input_files) {
std::string path = std::string(input_file.c_str()); std::string path = std::string(input_file.c_str());
size_t pos = path.find_last_of('\\'); std::string name = get_file_name(path);
size_t pos2 = path.find_last_of('.');
std::string name = path.substr(pos + 1, pos2 - pos - 1);
m_font_list.emplace_back(name, path); m_font_list.emplace_back(name, path);
// set first valid added font as active // set first valid added font as active
@ -643,9 +641,7 @@ bool GLGizmoEmboss::choose_svg_file()
if (input_files.size() != 1) return false; if (input_files.size() != 1) return false;
auto &input_file = input_files.front(); auto &input_file = input_files.front();
std::string path = std::string(input_file.c_str()); std::string path = std::string(input_file.c_str());
size_t pos = path.find_last_of('\\'); std::string name = get_file_name(path);
size_t pos2 = path.find_last_of('.');
std::string name = path.substr(pos + 1, pos2 - pos - 1);
NSVGimage *image = nsvgParseFromFile(path.c_str(), "mm", 96.0f); NSVGimage *image = nsvgParseFromFile(path.c_str(), "mm", 96.0f);
ExPolygons polys = NSVGUtils::to_ExPolygons(image); ExPolygons polys = NSVGUtils::to_ExPolygons(image);
@ -664,6 +660,14 @@ bool GLGizmoEmboss::choose_svg_file()
return add_volume(name, its); 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() { TextConfiguration GLGizmoEmboss::create_configuration() {
return TextConfiguration(m_font_list[m_font_selected], m_font_prop, m_text); 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 type = NotificationType::CustomNotification;
auto level = NotificationManager::NotificationLevel::WarningNotificationLevel; auto level = NotificationManager::NotificationLevel::WarningNotificationLevel;
std::string font_type_name = TextConfigurationSerialization::serialize(font_item.type); 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 = std::string text =
GUI::format(_L("WARNING: Can't load font (name=\"%1%\", type=\"%2%\", value=\"%3%\"), " GUI::format(_L("WARNING: Can't load font (name=\"%1%\", type=\"%2%\", value=\"%3%\"), "
"Selected font is different. " "Selected font is different. "
"When you edit, actual font will be used."), "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(); auto notification_manager = wxGetApp().plater()->get_notification_manager();
notification_manager->push_notification(type, level, text); notification_manager->push_notification(type, level, text);
} }

View File

@ -58,6 +58,9 @@ private:
bool choose_true_type_file(); bool choose_true_type_file();
bool choose_svg_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 // Create object described how to make a Volume
TextConfiguration create_configuration(); TextConfiguration create_configuration();
bool load_configuration(ModelVolume *volume); bool load_configuration(ModelVolume *volume);