summaryrefslogtreecommitdiff
path: root/Applications
diff options
context:
space:
mode:
authorSergey Bugaev <bugaevc@serenityos.org>2020-07-15 14:33:12 +0300
committerAndreas Kling <kling@serenityos.org>2020-07-15 13:41:46 +0200
commit5fd8dbacb13538c6808e8f40dbcf371af76ca470 (patch)
tree42221935c6f4479b5f67a6b545c315ac466e5a83 /Applications
parente12b591509ca54fcdf76a27aa3af43eb3d09744d (diff)
downloadserenity-5fd8dbacb13538c6808e8f40dbcf371af76ca470.zip
LibGUI+FileManager: Fix forgetting to map sorting proxy model indexes
Also assert indexes are valid in a few more places. Finally fixes https://github.com/SerenityOS/serenity/issues/1440 and https://github.com/SerenityOS/serenity/issues/2787 :^)
Diffstat (limited to 'Applications')
-rw-r--r--Applications/FileManager/DirectoryView.cpp19
-rw-r--r--Applications/FileManager/DirectoryView.h1
2 files changed, 12 insertions, 8 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();