diff --git a/Userland/Applications/FileManager/DirectoryView.cpp b/Userland/Applications/FileManager/DirectoryView.cpp index 005c9fb650..ddfba640f6 100644 --- a/Userland/Applications/FileManager/DirectoryView.cpp +++ b/Userland/Applications/FileManager/DirectoryView.cpp @@ -547,7 +547,7 @@ bool DirectoryView::can_modify_current_selection() // FIXME: remove once Clang formats this properly. // clang-format off 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(); // clang-format on } diff --git a/Userland/Libraries/LibGUI/FileSystemModel.cpp b/Userland/Libraries/LibGUI/FileSystemModel.cpp index 7c7cae44de..761679f87d 100644 --- a/Userland/Libraries/LibGUI/FileSystemModel.cpp +++ b/Userland/Libraries/LibGUI/FileSystemModel.cpp @@ -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::create_child(DeprecatedString const& child_name) { DeprecatedString child_path = LexicalPath::join(full_path(), child_name).string(); diff --git a/Userland/Libraries/LibGUI/FileSystemModel.h b/Userland/Libraries/LibGUI/FileSystemModel.h index 3120a5de30..86b14076c0 100644 --- a/Userland/Libraries/LibGUI/FileSystemModel.h +++ b/Userland/Libraries/LibGUI/FileSystemModel.h @@ -69,6 +69,8 @@ public: int error() const { return m_error; } char const* error_string() const { return strerror(m_error); } + bool can_delete_or_move() const; + DeprecatedString full_path() const; private: @@ -83,6 +85,7 @@ public: Node* m_parent { nullptr }; Vector> m_children; + mutable Optional m_can_delete_or_move; bool m_has_traversed { false }; bool m_selected { false };