summaryrefslogtreecommitdiff
path: root/Applications/FileManager
diff options
context:
space:
mode:
Diffstat (limited to 'Applications/FileManager')
-rw-r--r--Applications/FileManager/DirectoryTableModel.cpp15
-rw-r--r--Applications/FileManager/DirectoryTableView.cpp6
-rw-r--r--Applications/FileManager/DirectoryTableView.h6
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 };
};