mirror of
https://github.com/RGBCube/serenity
synced 2025-07-10 11:57:35 +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:
parent
7d2c962836
commit
e14dd06b8c
4 changed files with 25 additions and 10 deletions
|
@ -137,8 +137,21 @@ String DirectoryTableModel::name_for_gid(uid_t gid) const
|
||||||
|
|
||||||
GVariant DirectoryTableModel::data(const GModelIndex& index, Role role) const
|
GVariant DirectoryTableModel::data(const GModelIndex& index, Role role) const
|
||||||
{
|
{
|
||||||
ASSERT(role == Role::Display);
|
ASSERT(is_valid(index));
|
||||||
auto& entry = this->entry(index.row());
|
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()) {
|
switch (index.column()) {
|
||||||
case Column::Icon: return icon_for(entry);
|
case Column::Icon: return icon_for(entry);
|
||||||
case Column::Name: return entry.name;
|
case Column::Name: return entry.name;
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
#include "DirectoryTableView.h"
|
#include "DirectoryTableView.h"
|
||||||
|
#include <LibGUI/GSortingProxyTableModel.h>
|
||||||
|
|
||||||
DirectoryTableView::DirectoryTableView(GWidget* parent)
|
DirectoryTableView::DirectoryTableView(GWidget* parent)
|
||||||
: GTableView(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()
|
DirectoryTableView::~DirectoryTableView()
|
||||||
|
|
|
@ -19,8 +19,10 @@ public:
|
||||||
private:
|
private:
|
||||||
virtual void model_notification(const GModelNotification&) override;
|
virtual void model_notification(const GModelNotification&) override;
|
||||||
|
|
||||||
DirectoryTableModel& model() { return static_cast<DirectoryTableModel&>(*GTableView::model()); }
|
DirectoryTableModel& model() { return *m_model; }
|
||||||
const DirectoryTableModel& model() const { return static_cast<const DirectoryTableModel&>(*GTableView::model()); }
|
const DirectoryTableModel& model() const { return *m_model; }
|
||||||
|
|
||||||
void set_status_message(const String&);
|
void set_status_message(const String&);
|
||||||
|
|
||||||
|
DirectoryTableModel* m_model { nullptr };
|
||||||
};
|
};
|
||||||
|
|
|
@ -28,14 +28,10 @@ int GSortingProxyTableModel::column_count() const
|
||||||
GModelIndex GSortingProxyTableModel::map_to_target(const GModelIndex& index) const
|
GModelIndex GSortingProxyTableModel::map_to_target(const GModelIndex& index) const
|
||||||
{
|
{
|
||||||
ASSERT(!m_row_mappings.is_empty());
|
ASSERT(!m_row_mappings.is_empty());
|
||||||
if (!index.is_valid()) {
|
if (!index.is_valid())
|
||||||
ASSERT_NOT_REACHED();
|
|
||||||
return { };
|
return { };
|
||||||
}
|
if (index.row() >= row_count() || index.column() >= column_count())
|
||||||
if (index.row() >= row_count() || index.column() >= column_count()) {
|
|
||||||
ASSERT_NOT_REACHED();
|
|
||||||
return { };
|
return { };
|
||||||
}
|
|
||||||
return { m_row_mappings[index.row()], index.column() };
|
return { m_row_mappings[index.row()], index.column() };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue