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:
parent
e6ddc7e022
commit
deceb91c48
Notes:
sideshowbarker
2024-07-19 04:59:24 +09:00
Author: https://github.com/thankyouverycool Commit: https://github.com/SerenityOS/serenity/commit/deceb91c489 Pull-request: https://github.com/SerenityOS/serenity/pull/2752
3 changed files with 36 additions and 0 deletions
|
@ -805,6 +805,14 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
|
|||
}
|
||||
};
|
||||
|
||||
tree_view.on_selection = [&](const GUI::ModelIndex& index) {
|
||||
if (directories_model->m_previously_selected_index.is_valid())
|
||||
directories_model->update_node_on_selection(directories_model->m_previously_selected_index, false);
|
||||
|
||||
directories_model->update_node_on_selection(index, true);
|
||||
directories_model->m_previously_selected_index = index;
|
||||
};
|
||||
|
||||
tree_view.on_selection_change = [&] {
|
||||
if (tree_view.selection().is_empty())
|
||||
return;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -95,6 +95,9 @@ public:
|
|||
bool is_directory() const { return S_ISDIR(mode); }
|
||||
bool is_executable() const { return mode & (S_IXUSR | S_IXGRP | S_IXOTH); }
|
||||
|
||||
bool is_selected() const { return m_selected; }
|
||||
void set_selected(bool selected);
|
||||
|
||||
bool has_error() const { return m_error != 0; }
|
||||
int error() const { return m_error; }
|
||||
const char* error_string() const { return strerror(m_error); }
|
||||
|
@ -108,6 +111,8 @@ public:
|
|||
NonnullOwnPtrVector<Node> children;
|
||||
bool has_traversed { false };
|
||||
|
||||
bool m_selected { false };
|
||||
|
||||
int m_watch_fd { -1 };
|
||||
RefPtr<Core::Notifier> m_notifier;
|
||||
|
||||
|
@ -130,6 +135,9 @@ public:
|
|||
String full_path(const ModelIndex&) const;
|
||||
ModelIndex index(const StringView& path, int column) const;
|
||||
|
||||
void update_node_on_selection(const ModelIndex&, const bool);
|
||||
ModelIndex m_previously_selected_index {};
|
||||
|
||||
const Node& node(const ModelIndex& index) const;
|
||||
GUI::Icon icon_for_file(const mode_t mode, const String& name) const;
|
||||
|
||||
|
@ -171,6 +179,7 @@ private:
|
|||
OwnPtr<Node> m_root { nullptr };
|
||||
|
||||
GUI::Icon m_directory_icon;
|
||||
GUI::Icon m_directory_open_icon;
|
||||
GUI::Icon m_file_icon;
|
||||
GUI::Icon m_symlink_icon;
|
||||
GUI::Icon m_socket_icon;
|
||||
|
|
Loading…
Add table
Reference in a new issue