Sort entries in file dialog
This commit is contained in:
parent
b1063f83d9
commit
0a64bd0cbb
1 changed files with 31 additions and 8 deletions
|
|
@ -232,26 +232,49 @@ namespace psemek::ui
|
|||
|
||||
{
|
||||
std::string contents_str;
|
||||
int index = 0;
|
||||
for (auto const & entry : std::filesystem::directory_iterator(new_path))
|
||||
|
||||
struct directory_entry
|
||||
{
|
||||
if (std::filesystem::is_directory(entry.path()))
|
||||
bool folder;
|
||||
std::filesystem::path path;
|
||||
};
|
||||
|
||||
std::vector<directory_entry> entries;
|
||||
|
||||
for (auto const & entry : std::filesystem::directory_iterator(new_path))
|
||||
entries.push_back({std::filesystem::is_directory(entry.path()), entry.path()});
|
||||
|
||||
std::sort(entries.begin(), entries.end(), [](directory_entry const & e1, directory_entry const & e2){
|
||||
if (e1.folder && !e2.folder)
|
||||
return true;
|
||||
|
||||
if (!e1.folder && e2.folder)
|
||||
return false;
|
||||
|
||||
return e1.path.filename().string() < e2.path.filename().string();
|
||||
});
|
||||
|
||||
int index = 0;
|
||||
for (auto const & entry : entries)
|
||||
{
|
||||
if (entry.folder)
|
||||
contents_str += "[image:folder]";
|
||||
else
|
||||
contents_str += "[image:file]";
|
||||
|
||||
contents_str += "[link:" + util::to_string(index++) + "]";
|
||||
contents_str += entry.path().filename().string() + "[/link]\n";
|
||||
contents_str += entry.path.filename().string() + "[/link]\n";
|
||||
}
|
||||
directory_view->set_tagged_text(std::move(contents_str));
|
||||
|
||||
directory_view->on_link_click([=](std::string_view const & value){
|
||||
directory_view->on_link_click([=, entries = std::move(entries)](std::string_view const & value){
|
||||
int index = util::from_string<int>(std::string{value});
|
||||
auto path = std::next(std::filesystem::directory_iterator(new_path), index)->path();
|
||||
if (std::filesystem::is_directory(path))
|
||||
(*set_path_callback)(path);
|
||||
if (entries[index].folder)
|
||||
(*set_path_callback)(entries[index].path);
|
||||
else
|
||||
{
|
||||
auto path = entries[index].path;
|
||||
|
||||
try
|
||||
{
|
||||
if (type == file_dialog_type::load)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue