Escape paths in file dialog
This commit is contained in:
parent
361ef9fd7a
commit
1b8339ed5d
1 changed files with 20 additions and 3 deletions
|
|
@ -98,6 +98,23 @@ namespace psemek::ui
|
||||||
gfx::texture_2d file_;
|
gfx::texture_2d file_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::string replace(std::string str, std::string const & match, std::string const & replacement)
|
||||||
|
{
|
||||||
|
for (std::size_t i = 0; (i = str.find(match, i)) != std::string::npos;)
|
||||||
|
{
|
||||||
|
str.replace(i, match.size(), replacement);
|
||||||
|
i += replacement.size();
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string escape(std::string str)
|
||||||
|
{
|
||||||
|
str = replace(std::move(str), "[", "\\[");
|
||||||
|
str = replace(std::move(str), "]", "\\]");
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<window> make_file_dialog(file_dialog_options const & options)
|
std::shared_ptr<window> make_file_dialog(file_dialog_options const & options)
|
||||||
|
|
@ -217,9 +234,9 @@ namespace psemek::ui
|
||||||
for (auto const & component : new_path)
|
for (auto const & component : new_path)
|
||||||
{
|
{
|
||||||
if (component.string() != "/")
|
if (component.string() != "/")
|
||||||
path_str += "[link:" + util::to_string(++index) + "]" + component.string() + "[/link]/";
|
path_str += "[link:" + util::to_string(++index) + "]" + escape(component.string()) + "[/link]/";
|
||||||
else
|
else
|
||||||
path_str += "[link:" + util::to_string(++index) + "]" + component.string() + "[/link]";
|
path_str += "[link:" + util::to_string(++index) + "]" + escape(component.string()) + "[/link]";
|
||||||
}
|
}
|
||||||
current_path_label->set_tagged_text(std::move(path_str));
|
current_path_label->set_tagged_text(std::move(path_str));
|
||||||
|
|
||||||
|
|
@ -265,7 +282,7 @@ namespace psemek::ui
|
||||||
contents_str += "[image:file]";
|
contents_str += "[image:file]";
|
||||||
|
|
||||||
contents_str += "[link:" + util::to_string(index++) + "]";
|
contents_str += "[link:" + util::to_string(index++) + "]";
|
||||||
contents_str += entry.path.filename().string() + "[/link]\n";
|
contents_str += escape(entry.path.filename().string()) + "[/link]\n";
|
||||||
}
|
}
|
||||||
directory_view->set_tagged_text(std::move(contents_str));
|
directory_view->set_tagged_text(std::move(contents_str));
|
||||||
directory_view_scroller->set_position(scroller::direction::vertical, 0.f, false);
|
directory_view_scroller->set_position(scroller::direction::vertical, 0.f, false);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue