mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:07:35 +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())
|
||||
|
|
|
@ -146,6 +146,9 @@ public:
|
|||
bool should_show_dotfiles() const { return m_should_show_dotfiles; }
|
||||
void set_should_show_dotfiles(bool);
|
||||
|
||||
Optional<Vector<DeprecatedString>> allowed_file_extensions() const { return m_allowed_file_extensions; }
|
||||
void set_allowed_file_extensions(Optional<Vector<DeprecatedString>> 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<Vector<DeprecatedString>> m_allowed_file_extensions;
|
||||
|
||||
bool m_should_show_dotfiles { false };
|
||||
|
||||
RefPtr<Core::FileWatcher> m_file_watcher;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue