mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-01 06:07:59 +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:
committed by
Andrew Kaster
parent
c3bd841d50
commit
fe5dfe4cd5
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user