FileManager: Make the tree view follow the directory view navigations.

This commit is contained in:
Andreas Kling 2019-03-30 03:27:25 +01:00
parent f10e0d0546
commit 2c6a597d77
Notes: sideshowbarker 2024-07-19 14:53:45 +09:00
10 changed files with 72 additions and 3 deletions

View file

@ -92,6 +92,30 @@ struct GFileSystemModel::Node {
}
};
GModelIndex GFileSystemModel::index(const String& path) const
{
FileSystemPath canonical_path(path);
const Node* node = m_root;
if (canonical_path.string() == "/")
return m_root->index(*this);
for (int i = 0; i < canonical_path.parts().size(); ++i) {
auto& part = canonical_path.parts()[i];
bool found = false;
for (auto& child : node->children) {
if (child->name == part) {
node = child;
found = true;
if (i == canonical_path.parts().size() - 1)
return node->index(*this);
break;
}
}
if (!found)
return { };
}
return { };
}
String GFileSystemModel::path(const GModelIndex& index) const
{
if (!index.is_valid())