mirror of
https://github.com/RGBCube/serenity
synced 2025-05-22 19:05:07 +00:00
FileManager: Make DirectoryView vend indexes from view model
Instead of translating between the sorting proxy and the underlying file system model at all the DirectoryView API boundaries, just hand out indexes into the sorting proxy model. The only thing those indexes are used for on the outside is to retrieve a GUI::FileSystemModel::Node for an index, so add a nice helper on DirectoryView that turns a ModelIndex into a Node&.
This commit is contained in:
parent
f0349323c4
commit
d1e83b4f6e
3 changed files with 20 additions and 20 deletions
|
@ -92,7 +92,7 @@ void DirectoryView::handle_activation(const GUI::ModelIndex& index)
|
||||||
if (!index.is_valid())
|
if (!index.is_valid())
|
||||||
return;
|
return;
|
||||||
dbgprintf("on activation: %d,%d, this=%p, m_model=%p\n", index.row(), index.column(), this, m_model.ptr());
|
dbgprintf("on activation: %d,%d, this=%p, m_model=%p\n", index.row(), index.column(), this, m_model.ptr());
|
||||||
auto& node = model().node(index);
|
auto& node = this->node(index);
|
||||||
auto path = node.full_path();
|
auto path = node.full_path();
|
||||||
|
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
@ -142,6 +142,11 @@ DirectoryView::DirectoryView(Mode mode)
|
||||||
set_view_mode(ViewMode::Icon);
|
set_view_mode(ViewMode::Icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const GUI::FileSystemModel::Node& DirectoryView::node(const GUI::ModelIndex& index) const
|
||||||
|
{
|
||||||
|
return model().node(m_sorting_model->map_to_source(index));
|
||||||
|
}
|
||||||
|
|
||||||
void DirectoryView::setup_model()
|
void DirectoryView::setup_model()
|
||||||
{
|
{
|
||||||
m_model->set_root_path(Core::StandardPaths::desktop_directory());
|
m_model->set_root_path(Core::StandardPaths::desktop_directory());
|
||||||
|
@ -195,7 +200,7 @@ void DirectoryView::setup_icon_view()
|
||||||
m_icon_view->set_model(m_sorting_model);
|
m_icon_view->set_model(m_sorting_model);
|
||||||
m_icon_view->set_model_column(GUI::FileSystemModel::Column::Name);
|
m_icon_view->set_model_column(GUI::FileSystemModel::Column::Name);
|
||||||
m_icon_view->on_activation = [&](auto& index) {
|
m_icon_view->on_activation = [&](auto& index) {
|
||||||
handle_activation(map_index(index));
|
handle_activation(index);
|
||||||
};
|
};
|
||||||
m_icon_view->on_selection_change = [this] {
|
m_icon_view->on_selection_change = [this] {
|
||||||
update_statusbar();
|
update_statusbar();
|
||||||
|
@ -204,11 +209,11 @@ void DirectoryView::setup_icon_view()
|
||||||
};
|
};
|
||||||
m_icon_view->on_context_menu_request = [this](auto& index, auto& event) {
|
m_icon_view->on_context_menu_request = [this](auto& index, auto& event) {
|
||||||
if (on_context_menu_request)
|
if (on_context_menu_request)
|
||||||
on_context_menu_request(map_index(index), event);
|
on_context_menu_request(index, event);
|
||||||
};
|
};
|
||||||
m_icon_view->on_drop = [this](auto& index, auto& event) {
|
m_icon_view->on_drop = [this](auto& index, auto& event) {
|
||||||
if (on_drop)
|
if (on_drop)
|
||||||
on_drop(map_index(index), event);
|
on_drop(index, event);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,7 +224,7 @@ void DirectoryView::setup_columns_view()
|
||||||
m_columns_view->set_model_column(GUI::FileSystemModel::Column::Name);
|
m_columns_view->set_model_column(GUI::FileSystemModel::Column::Name);
|
||||||
|
|
||||||
m_columns_view->on_activation = [&](auto& index) {
|
m_columns_view->on_activation = [&](auto& index) {
|
||||||
handle_activation(map_index(index));
|
handle_activation(index);
|
||||||
};
|
};
|
||||||
|
|
||||||
m_columns_view->on_selection_change = [this] {
|
m_columns_view->on_selection_change = [this] {
|
||||||
|
@ -230,12 +235,12 @@ void DirectoryView::setup_columns_view()
|
||||||
|
|
||||||
m_columns_view->on_context_menu_request = [this](auto& index, auto& event) {
|
m_columns_view->on_context_menu_request = [this](auto& index, auto& event) {
|
||||||
if (on_context_menu_request)
|
if (on_context_menu_request)
|
||||||
on_context_menu_request(map_index(index), event);
|
on_context_menu_request(index, event);
|
||||||
};
|
};
|
||||||
|
|
||||||
m_columns_view->on_drop = [this](auto& index, auto& event) {
|
m_columns_view->on_drop = [this](auto& index, auto& event) {
|
||||||
if (on_drop)
|
if (on_drop)
|
||||||
on_drop(map_index(index), event);
|
on_drop(index, event);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,7 +252,7 @@ void DirectoryView::setup_table_view()
|
||||||
m_table_view->set_key_column_and_sort_order(GUI::FileSystemModel::Column::Name, GUI::SortOrder::Ascending);
|
m_table_view->set_key_column_and_sort_order(GUI::FileSystemModel::Column::Name, GUI::SortOrder::Ascending);
|
||||||
|
|
||||||
m_table_view->on_activation = [&](auto& index) {
|
m_table_view->on_activation = [&](auto& index) {
|
||||||
handle_activation(map_index(index));
|
handle_activation(index);
|
||||||
};
|
};
|
||||||
|
|
||||||
m_table_view->on_selection_change = [this] {
|
m_table_view->on_selection_change = [this] {
|
||||||
|
@ -258,12 +263,12 @@ void DirectoryView::setup_table_view()
|
||||||
|
|
||||||
m_table_view->on_context_menu_request = [this](auto& index, auto& event) {
|
m_table_view->on_context_menu_request = [this](auto& index, auto& event) {
|
||||||
if (on_context_menu_request)
|
if (on_context_menu_request)
|
||||||
on_context_menu_request(map_index(index), event);
|
on_context_menu_request(index, event);
|
||||||
};
|
};
|
||||||
|
|
||||||
m_table_view->on_drop = [this](auto& index, auto& event) {
|
m_table_view->on_drop = [this](auto& index, auto& event) {
|
||||||
if (on_drop)
|
if (on_drop)
|
||||||
on_drop(map_index(index), event);
|
on_drop(index, event);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -356,11 +361,6 @@ void DirectoryView::open_next_directory()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GUI::ModelIndex DirectoryView::map_index(const GUI::ModelIndex& index) const
|
|
||||||
{
|
|
||||||
return m_sorting_model->map_to_source(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DirectoryView::update_statusbar()
|
void DirectoryView::update_statusbar()
|
||||||
{
|
{
|
||||||
size_t total_size = model().node({}).total_size;
|
size_t total_size = model().node({}).total_size;
|
||||||
|
@ -392,7 +392,7 @@ void DirectoryView::update_statusbar()
|
||||||
builder.append(')');
|
builder.append(')');
|
||||||
|
|
||||||
if (selected_item_count == 1) {
|
if (selected_item_count == 1) {
|
||||||
auto& node = model().node(map_index(current_view().selection().first()));
|
auto& node = this->node(current_view().selection().first());
|
||||||
if (!node.symlink_target.is_empty()) {
|
if (!node.symlink_target.is_empty()) {
|
||||||
builder.append(" -> ");
|
builder.append(" -> ");
|
||||||
builder.append(node.symlink_target);
|
builder.append(node.symlink_target);
|
||||||
|
|
|
@ -128,7 +128,7 @@ public:
|
||||||
|
|
||||||
void set_should_show_dotfiles(bool);
|
void set_should_show_dotfiles(bool);
|
||||||
|
|
||||||
GUI::FileSystemModel& model() { return *m_model; }
|
const GUI::FileSystemModel::Node& node(const GUI::ModelIndex&) const;
|
||||||
|
|
||||||
bool is_desktop() const { return m_mode == Mode::Desktop; }
|
bool is_desktop() const { return m_mode == Mode::Desktop; }
|
||||||
|
|
||||||
|
@ -140,6 +140,7 @@ public:
|
||||||
private:
|
private:
|
||||||
explicit DirectoryView(Mode);
|
explicit DirectoryView(Mode);
|
||||||
const GUI::FileSystemModel& model() const { return *m_model; }
|
const GUI::FileSystemModel& model() const { return *m_model; }
|
||||||
|
GUI::FileSystemModel& model() { return *m_model; }
|
||||||
|
|
||||||
// ^GUI::ModelClient
|
// ^GUI::ModelClient
|
||||||
virtual void model_did_update(unsigned) override;
|
virtual void model_did_update(unsigned) override;
|
||||||
|
@ -151,7 +152,6 @@ private:
|
||||||
void setup_table_view();
|
void setup_table_view();
|
||||||
|
|
||||||
void handle_activation(const GUI::ModelIndex&);
|
void handle_activation(const GUI::ModelIndex&);
|
||||||
GUI::ModelIndex map_index(const GUI::ModelIndex&) const;
|
|
||||||
|
|
||||||
void set_status_message(const StringView&);
|
void set_status_message(const StringView&);
|
||||||
void update_statusbar();
|
void update_statusbar();
|
||||||
|
|
|
@ -702,7 +702,7 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
|
||||||
|
|
||||||
directory_view.on_context_menu_request = [&](const GUI::ModelIndex& index, const GUI::ContextMenuEvent& event) {
|
directory_view.on_context_menu_request = [&](const GUI::ModelIndex& index, const GUI::ContextMenuEvent& event) {
|
||||||
if (index.is_valid()) {
|
if (index.is_valid()) {
|
||||||
auto& node = directory_view.model().node(index);
|
auto& node = directory_view.node(index);
|
||||||
|
|
||||||
if (node.is_directory()) {
|
if (node.is_directory()) {
|
||||||
auto should_get_enabled = access(node.full_path().characters(), W_OK) == 0 && GUI::Clipboard::the().type() == "text/uri-list";
|
auto should_get_enabled = access(node.full_path().characters(), W_OK) == 0 && GUI::Clipboard::the().type() == "text/uri-list";
|
||||||
|
@ -769,7 +769,7 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& target_node = directory_view.model().node(index);
|
auto& target_node = directory_view.node(index);
|
||||||
if (!target_node.is_directory())
|
if (!target_node.is_directory())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue