diff --git a/Userland/Libraries/LibGUI/FileSystemModel.cpp b/Userland/Libraries/LibGUI/FileSystemModel.cpp index 91d804d25e..545b4fda7c 100644 --- a/Userland/Libraries/LibGUI/FileSystemModel.cpp +++ b/Userland/Libraries/LibGUI/FileSystemModel.cpp @@ -120,10 +120,21 @@ void FileSystemModel::Node::traverse_if_needed() auto child = maybe_child.release_nonnull(); total_size += child->size; - if (S_ISDIR(child->mode)) + if (S_ISDIR(child->mode)) { directory_children.append(move(child)); - else - file_children.append(move(child)); + } else { + if (!m_model.m_allowed_file_extensions.has_value()) { + file_children.append(move(child)); + continue; + } + + for (auto& extension : *m_model.m_allowed_file_extensions) { + if (child_name.ends_with(DeprecatedString::formatted(".{}", extension))) { + file_children.append(move(child)); + break; + } + } + } } m_children.extend(move(directory_children)); @@ -750,6 +761,15 @@ void FileSystemModel::set_should_show_dotfiles(bool show) invalidate(); } +void FileSystemModel::set_allowed_file_extensions(Optional> const& allowed_file_extensions) +{ + if (m_allowed_file_extensions == allowed_file_extensions) + return; + m_allowed_file_extensions = allowed_file_extensions; + + invalidate(); +} + bool FileSystemModel::is_editable(ModelIndex const& index) const { if (!index.is_valid()) diff --git a/Userland/Libraries/LibGUI/FileSystemModel.h b/Userland/Libraries/LibGUI/FileSystemModel.h index 085d0644f2..6f4ac96f6f 100644 --- a/Userland/Libraries/LibGUI/FileSystemModel.h +++ b/Userland/Libraries/LibGUI/FileSystemModel.h @@ -146,6 +146,9 @@ public: bool should_show_dotfiles() const { return m_should_show_dotfiles; } void set_should_show_dotfiles(bool); + Optional> allowed_file_extensions() const { return m_allowed_file_extensions; } + void set_allowed_file_extensions(Optional> const& allowed_file_extensions); + private: FileSystemModel(DeprecatedString root_path, Mode); @@ -169,6 +172,8 @@ private: unsigned m_thumbnail_progress { 0 }; unsigned m_thumbnail_progress_total { 0 }; + Optional> m_allowed_file_extensions; + bool m_should_show_dotfiles { false }; RefPtr m_file_watcher;