diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-03-09 14:52:25 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-03-09 14:52:25 +0100 |
commit | e14dd06b8c590fb1292b6219f8c1da249ec85f98 (patch) | |
tree | 420655f5f44177937ef59440278008c62ef5e607 /Applications/FileManager | |
parent | 7d2c962836095a8c9ece86927821c27f7ccb8d12 (diff) | |
download | serenity-e14dd06b8c590fb1292b6219f8c1da249ec85f98.zip |
FileManager: Hook up a GSortingProxyTableModel so we get sorted files. :^)
The next step here is coming up with a nice way to always put directories
ahead of files.
Diffstat (limited to 'Applications/FileManager')
-rw-r--r-- | Applications/FileManager/DirectoryTableModel.cpp | 15 | ||||
-rw-r--r-- | Applications/FileManager/DirectoryTableView.cpp | 6 | ||||
-rw-r--r-- | Applications/FileManager/DirectoryTableView.h | 6 |
3 files changed, 23 insertions, 4 deletions
diff --git a/Applications/FileManager/DirectoryTableModel.cpp b/Applications/FileManager/DirectoryTableModel.cpp index c21a8a98d7..e04b544098 100644 --- a/Applications/FileManager/DirectoryTableModel.cpp +++ b/Applications/FileManager/DirectoryTableModel.cpp @@ -137,8 +137,21 @@ String DirectoryTableModel::name_for_gid(uid_t gid) const GVariant DirectoryTableModel::data(const GModelIndex& index, Role role) const { - ASSERT(role == Role::Display); + ASSERT(is_valid(index)); auto& entry = this->entry(index.row()); + if (role == Role::Sort) { + switch (index.column()) { + case Column::Icon: return entry.is_directory() ? 0 : 1; + case Column::Name: return entry.name; + case Column::Size: return (int)entry.size; + case Column::Owner: return name_for_uid(entry.uid); + case Column::Group: return name_for_gid(entry.gid); + case Column::Permissions: return permission_string(entry.mode); + case Column::Inode: return (int)entry.inode; + } + ASSERT_NOT_REACHED(); + } + ASSERT(role == Role::Display); switch (index.column()) { case Column::Icon: return icon_for(entry); case Column::Name: return entry.name; diff --git a/Applications/FileManager/DirectoryTableView.cpp b/Applications/FileManager/DirectoryTableView.cpp index 4e116a1981..28f54303de 100644 --- a/Applications/FileManager/DirectoryTableView.cpp +++ b/Applications/FileManager/DirectoryTableView.cpp @@ -1,9 +1,13 @@ #include "DirectoryTableView.h" +#include <LibGUI/GSortingProxyTableModel.h> DirectoryTableView::DirectoryTableView(GWidget* parent) : GTableView(parent) { - set_model(make<DirectoryTableModel>()); + auto directory_model = make<DirectoryTableModel>(); + m_model = directory_model.ptr(); + set_model(make<GSortingProxyTableModel>(move(directory_model))); + GTableView::model()->set_key_column_and_sort_order(DirectoryTableModel::Column::Name, GSortOrder::Ascending); } DirectoryTableView::~DirectoryTableView() diff --git a/Applications/FileManager/DirectoryTableView.h b/Applications/FileManager/DirectoryTableView.h index 4d2c369a81..1bc56e8ab1 100644 --- a/Applications/FileManager/DirectoryTableView.h +++ b/Applications/FileManager/DirectoryTableView.h @@ -19,8 +19,10 @@ public: private: virtual void model_notification(const GModelNotification&) override; - DirectoryTableModel& model() { return static_cast<DirectoryTableModel&>(*GTableView::model()); } - const DirectoryTableModel& model() const { return static_cast<const DirectoryTableModel&>(*GTableView::model()); } + DirectoryTableModel& model() { return *m_model; } + const DirectoryTableModel& model() const { return *m_model; } void set_status_message(const String&); + + DirectoryTableModel* m_model { nullptr }; }; |