FileManager: Show an open folder icon for the selected directory

The currently selected directory now displays an open folder icon
in the directory tree.
This commit is contained in:
thankyouverycool 2020-07-10 09:51:15 -04:00 committed by Andreas Kling
parent e6ddc7e022
commit deceb91c48
Notes: sideshowbarker 2024-07-19 04:59:24 +09:00
3 changed files with 36 additions and 0 deletions

View file

@ -204,6 +204,7 @@ FileSystemModel::FileSystemModel(const StringView& root_path, Mode mode)
, m_mode(mode)
{
m_directory_icon = Icon::default_icon("filetype-folder");
m_directory_open_icon = Icon::default_icon("filetype-folder-open");
m_file_icon = Icon::default_icon("filetype-unknown");
m_symlink_icon = Icon::default_icon("filetype-symlink");
m_socket_icon = Icon::default_icon("filetype-socket");
@ -284,6 +285,19 @@ static String permission_string(mode_t mode)
return builder.to_string();
}
void FileSystemModel::Node::set_selected(bool selected)
{
if (m_selected == selected)
return;
m_selected = selected;
}
void FileSystemModel::update_node_on_selection(const ModelIndex& index, const bool selected)
{
Node& node = const_cast<Node&>(this->node(index));
node.set_selected(selected);
}
void FileSystemModel::set_root_path(const StringView& root_path)
{
m_root_path = LexicalPath::canonicalized_path(root_path);
@ -470,6 +484,11 @@ Icon FileSystemModel::icon_for(const Node& node) const
return GUI::Icon(m_filetype_image_icon.bitmap_for_size(16), *node.thumbnail);
}
if (node.is_directory()) {
if (node.is_selected())
return m_directory_open_icon;
}
return icon_for_file(node.mode, node.name);
}