mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:48:11 +00:00
LibGUI: Add allowed file extensions to FileSystemModel
This allows FileSystemModel to take an optional list of allowed file extensions which it will use to filter out all files that don't end with that file extension. The file extensions are set via `set_allowed_file_extensions` which has a coresponding `get_allowed_file_extensions`.
This commit is contained in:
parent
c3bd841d50
commit
fe5dfe4cd5
2 changed files with 28 additions and 3 deletions
|
@ -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<Vector<DeprecatedString>> 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())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue