mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:57:47 +00:00
FileManager+LibGUI: Cache the FileSystem::can_delete_or_move value
Add the function FileSystemModel::Node::can_delete_or_move which will cache the result of FileSystem::can_delete_or_move for a node. This prevents having to make system calls repeatedly to obtain this information. Fixes #18399
This commit is contained in:
parent
d824d07784
commit
e758545b91
3 changed files with 11 additions and 1 deletions
|
@ -547,7 +547,7 @@ bool DirectoryView::can_modify_current_selection()
|
||||||
// FIXME: remove once Clang formats this properly.
|
// FIXME: remove once Clang formats this properly.
|
||||||
// clang-format off
|
// clang-format off
|
||||||
return selections.first_matching([&](auto& index) {
|
return selections.first_matching([&](auto& index) {
|
||||||
return FileSystem::can_delete_or_move(node(index).full_path());
|
return node(index).can_delete_or_move();
|
||||||
}).has_value();
|
}).has_value();
|
||||||
// clang-format on
|
// clang-format on
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,6 +159,13 @@ void FileSystemModel::Node::traverse_if_needed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FileSystemModel::Node::can_delete_or_move() const
|
||||||
|
{
|
||||||
|
if (!m_can_delete_or_move.has_value())
|
||||||
|
m_can_delete_or_move = FileSystem::can_delete_or_move(full_path());
|
||||||
|
return m_can_delete_or_move.value();
|
||||||
|
}
|
||||||
|
|
||||||
OwnPtr<FileSystemModel::Node> FileSystemModel::Node::create_child(DeprecatedString const& child_name)
|
OwnPtr<FileSystemModel::Node> FileSystemModel::Node::create_child(DeprecatedString const& child_name)
|
||||||
{
|
{
|
||||||
DeprecatedString child_path = LexicalPath::join(full_path(), child_name).string();
|
DeprecatedString child_path = LexicalPath::join(full_path(), child_name).string();
|
||||||
|
|
|
@ -69,6 +69,8 @@ public:
|
||||||
int error() const { return m_error; }
|
int error() const { return m_error; }
|
||||||
char const* error_string() const { return strerror(m_error); }
|
char const* error_string() const { return strerror(m_error); }
|
||||||
|
|
||||||
|
bool can_delete_or_move() const;
|
||||||
|
|
||||||
DeprecatedString full_path() const;
|
DeprecatedString full_path() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -83,6 +85,7 @@ public:
|
||||||
|
|
||||||
Node* m_parent { nullptr };
|
Node* m_parent { nullptr };
|
||||||
Vector<NonnullOwnPtr<Node>> m_children;
|
Vector<NonnullOwnPtr<Node>> m_children;
|
||||||
|
mutable Optional<bool> m_can_delete_or_move;
|
||||||
bool m_has_traversed { false };
|
bool m_has_traversed { false };
|
||||||
|
|
||||||
bool m_selected { false };
|
bool m_selected { false };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue