1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:28:12 +00:00

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.
This commit is contained in:
Andreas Kling 2019-03-09 14:52:25 +01:00
parent 7d2c962836
commit e14dd06b8c
4 changed files with 25 additions and 10 deletions

View file

@ -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;

View file

@ -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()

View file

@ -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 };
};

View file

@ -28,14 +28,10 @@ int GSortingProxyTableModel::column_count() const
GModelIndex GSortingProxyTableModel::map_to_target(const GModelIndex& index) const
{
ASSERT(!m_row_mappings.is_empty());
if (!index.is_valid()) {
ASSERT_NOT_REACHED();
if (!index.is_valid())
return { };
}
if (index.row() >= row_count() || index.column() >= column_count()) {
ASSERT_NOT_REACHED();
if (index.row() >= row_count() || index.column() >= column_count())
return { };
}
return { m_row_mappings[index.row()], index.column() };
}