mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:37:44 +00:00
LibGUI: Allow FileSystemModel to be rooted one level above "/"
You can now construct a FileSystemModel with a null String() as the root path. This will root it one level above "/" which makes the root directory itself selectable as a child. This will be useful in some places, e.g the FileManager application.
This commit is contained in:
parent
a9f7b576a4
commit
4d2782db5a
2 changed files with 21 additions and 2 deletions
|
@ -89,7 +89,18 @@ void FileSystemModel::Node::traverse_if_needed()
|
||||||
{
|
{
|
||||||
if (!is_directory() || has_traversed)
|
if (!is_directory() || has_traversed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
has_traversed = true;
|
has_traversed = true;
|
||||||
|
|
||||||
|
if (m_parent_of_root) {
|
||||||
|
auto root = adopt_own(*new Node(m_model));
|
||||||
|
root->fetch_data("/", true);
|
||||||
|
root->name = "/";
|
||||||
|
root->parent = this;
|
||||||
|
children.append(move(root));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
total_size = 0;
|
total_size = 0;
|
||||||
|
|
||||||
auto full_path = this->full_path();
|
auto full_path = this->full_path();
|
||||||
|
@ -149,7 +160,7 @@ void FileSystemModel::Node::reify_if_needed()
|
||||||
traverse_if_needed();
|
traverse_if_needed();
|
||||||
if (mode != 0)
|
if (mode != 0)
|
||||||
return;
|
return;
|
||||||
fetch_data(full_path(), parent == nullptr);
|
fetch_data(full_path(), parent == nullptr || parent->m_parent_of_root);
|
||||||
}
|
}
|
||||||
|
|
||||||
String FileSystemModel::Node::full_path() const
|
String FileSystemModel::Node::full_path() const
|
||||||
|
@ -290,7 +301,10 @@ void FileSystemModel::update_node_on_selection(const ModelIndex& index, const bo
|
||||||
|
|
||||||
void FileSystemModel::set_root_path(const StringView& root_path)
|
void FileSystemModel::set_root_path(const StringView& root_path)
|
||||||
{
|
{
|
||||||
m_root_path = LexicalPath::canonicalized_path(root_path);
|
if (root_path.is_null())
|
||||||
|
m_root_path = {};
|
||||||
|
else
|
||||||
|
m_root_path = LexicalPath::canonicalized_path(root_path);
|
||||||
update();
|
update();
|
||||||
|
|
||||||
if (m_root->has_error()) {
|
if (m_root->has_error()) {
|
||||||
|
@ -304,6 +318,10 @@ void FileSystemModel::set_root_path(const StringView& root_path)
|
||||||
void FileSystemModel::update()
|
void FileSystemModel::update()
|
||||||
{
|
{
|
||||||
m_root = adopt_own(*new Node(*this));
|
m_root = adopt_own(*new Node(*this));
|
||||||
|
|
||||||
|
if (m_root_path.is_null())
|
||||||
|
m_root->m_parent_of_root = true;
|
||||||
|
|
||||||
m_root->reify_if_needed();
|
m_root->reify_if_needed();
|
||||||
|
|
||||||
did_update();
|
did_update();
|
||||||
|
|
|
@ -109,6 +109,7 @@ public:
|
||||||
RefPtr<Core::Notifier> m_notifier;
|
RefPtr<Core::Notifier> m_notifier;
|
||||||
|
|
||||||
int m_error { 0 };
|
int m_error { 0 };
|
||||||
|
bool m_parent_of_root { false };
|
||||||
|
|
||||||
ModelIndex index(int column) const;
|
ModelIndex index(int column) const;
|
||||||
void traverse_if_needed();
|
void traverse_if_needed();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue