diff options
-rw-r--r-- | Applications/FileManager/DirectoryView.cpp | 19 | ||||
-rw-r--r-- | Applications/FileManager/DirectoryView.h | 1 | ||||
-rw-r--r-- | Libraries/LibGUI/FileSystemModel.cpp | 1 | ||||
-rw-r--r-- | Libraries/LibGUI/SortingProxyModel.cpp | 17 |
4 files changed, 21 insertions, 17 deletions
diff --git a/Applications/FileManager/DirectoryView.cpp b/Applications/FileManager/DirectoryView.cpp index 65834ee3ea..f271bd06e4 100644 --- a/Applications/FileManager/DirectoryView.cpp +++ b/Applications/FileManager/DirectoryView.cpp @@ -166,8 +166,7 @@ DirectoryView::DirectoryView() handle_activation(index); }; m_table_view->on_activation = [&](auto& index) { - auto& filter_model = (GUI::SortingProxyModel&)*m_table_view->model(); - handle_activation(filter_model.map_to_target(index)); + handle_activation(map_table_view_index(index)); }; m_table_view->on_selection_change = [this] { @@ -188,7 +187,7 @@ DirectoryView::DirectoryView() m_table_view->on_context_menu_request = [this](auto& index, auto& event) { if (on_context_menu_request) - on_context_menu_request(*m_table_view, index, event); + on_context_menu_request(*m_table_view, map_table_view_index(index), event); }; m_icon_view->on_context_menu_request = [this](auto& index, auto& event) { if (on_context_menu_request) @@ -201,7 +200,7 @@ DirectoryView::DirectoryView() m_table_view->on_drop = [this](auto& index, auto& event) { if (on_drop) - on_drop(*m_table_view, index, event); + on_drop(*m_table_view, map_table_view_index(index), event); }; m_icon_view->on_drop = [this](auto& index, auto& event) { if (on_drop) @@ -304,6 +303,12 @@ void DirectoryView::open_next_directory() } } +GUI::ModelIndex DirectoryView::map_table_view_index(const GUI::ModelIndex& index) const +{ + auto& filter_model = (const GUI::SortingProxyModel&)*m_table_view->model(); + return filter_model.map_to_target(index); +} + void DirectoryView::update_statusbar() { size_t total_size = model().node({}).total_size; @@ -338,10 +343,8 @@ void DirectoryView::update_statusbar() auto index = current_view().selection().first(); // FIXME: This is disgusting. This code should not even be aware that there is a GUI::SortingProxyModel in the table view. - if (m_view_mode == ViewMode::Table) { - auto& filter_model = (GUI::SortingProxyModel&)*m_table_view->model(); - index = filter_model.map_to_target(index); - } + if (m_view_mode == ViewMode::Table) + index = map_table_view_index(index); auto& node = model().node(index); if (!node.symlink_target.is_empty()) { diff --git a/Applications/FileManager/DirectoryView.h b/Applications/FileManager/DirectoryView.h index b5728987ea..9ff361eca2 100644 --- a/Applications/FileManager/DirectoryView.h +++ b/Applications/FileManager/DirectoryView.h @@ -119,6 +119,7 @@ private: virtual void on_model_update(unsigned) override; void handle_activation(const GUI::ModelIndex&); + GUI::ModelIndex map_table_view_index(const GUI::ModelIndex&) const; void set_status_message(const StringView&); void update_statusbar(); diff --git a/Libraries/LibGUI/FileSystemModel.cpp b/Libraries/LibGUI/FileSystemModel.cpp index 88ea294cb8..2fc0913a60 100644 --- a/Libraries/LibGUI/FileSystemModel.cpp +++ b/Libraries/LibGUI/FileSystemModel.cpp @@ -332,6 +332,7 @@ const FileSystemModel::Node& FileSystemModel::node(const ModelIndex& index) cons { if (!index.is_valid()) return *m_root; + ASSERT(index.internal_data()); return *(Node*)index.internal_data(); } diff --git a/Libraries/LibGUI/SortingProxyModel.cpp b/Libraries/LibGUI/SortingProxyModel.cpp index 991cbb9786..c18b18fac5 100644 --- a/Libraries/LibGUI/SortingProxyModel.cpp +++ b/Libraries/LibGUI/SortingProxyModel.cpp @@ -57,12 +57,14 @@ void SortingProxyModel::on_model_update(unsigned flags) int SortingProxyModel::row_count(const ModelIndex& index) const { - return target().row_count(index); + auto target_index = map_to_target(index); + return target().row_count(target_index); } int SortingProxyModel::column_count(const ModelIndex& index) const { - return target().column_count(index); + auto target_index = map_to_target(index); + return target().column_count(target_index); } ModelIndex SortingProxyModel::map_to_target(const ModelIndex& index) const @@ -74,19 +76,16 @@ ModelIndex SortingProxyModel::map_to_target(const ModelIndex& index) const return target().index(m_row_mappings[index.row()], index.column()); } -String SortingProxyModel::column_name(int index) const +String SortingProxyModel::column_name(int column) const { - return target().column_name(index); + return target().column_name(column); } Variant SortingProxyModel::data(const ModelIndex& index, Role role) const { auto target_index = map_to_target(index); - if (!target_index.is_valid()) { - dbg() << "BUG! SortingProxyModel: Unable to convert " << index << " to target"; - return {}; - } - return target().data(map_to_target(index), role); + ASSERT(target_index.is_valid()); + return target().data(target_index, role); } void SortingProxyModel::update() |