mirror of
https://invent.kde.org/system/dolphin
synced 2024-10-05 16:19:10 +00:00
Add the ability to sort by file extension
Currently, Dolphin doesn't have the ability to sort by file extension (sorting by type means that files will be sorted by mimetype but not by extension). This MR fixes this shortcoming. BUG: 429579
This commit is contained in:
parent
c88ce580e6
commit
e6f142e5e7
|
@ -1580,6 +1580,7 @@ QList<KFileItemModel::ItemData*> KFileItemModel::createItemDataList(const QUrl&
|
|||
void KFileItemModel::prepareItemsForSorting(QList<ItemData*>& itemDataList)
|
||||
{
|
||||
switch (m_sortRole) {
|
||||
case ExtensionRole:
|
||||
case PermissionsRole:
|
||||
case OwnerRole:
|
||||
case GroupRole:
|
||||
|
@ -1801,6 +1802,10 @@ QHash<QByteArray, QVariant> KFileItemModel::retrieveData(const KFileItem& item,
|
|||
data.insert(sharedValue("text"), item.text());
|
||||
}
|
||||
|
||||
if (m_requestRole[ExtensionRole]) {
|
||||
data.insert(sharedValue("extension"), QFileInfo(item.name()).suffix());
|
||||
}
|
||||
|
||||
if (m_requestRole[SizeRole] && !isDir) {
|
||||
data.insert(sharedValue("size"), item.size());
|
||||
}
|
||||
|
@ -2609,6 +2614,7 @@ const KFileItemModel::RoleInfoMap* KFileItemModel::rolesInfoMap(int& count)
|
|||
{ "creationtime", CreationTimeRole, kli18nc("@label", "Created"), KLazyLocalizedString(), false, false },
|
||||
{ "accesstime", AccessTimeRole, kli18nc("@label", "Accessed"), KLazyLocalizedString(), false, false },
|
||||
{ "type", TypeRole, kli18nc("@label", "Type"), KLazyLocalizedString(), false, false },
|
||||
{ "extension", ExtensionRole, kli18nc("@label", "Extension"), KLazyLocalizedString(), false, false },
|
||||
{ "rating", RatingRole, kli18nc("@label", "Rating"), KLazyLocalizedString(), true, false },
|
||||
{ "tags", TagsRole, kli18nc("@label", "Tags"), KLazyLocalizedString(), true, false },
|
||||
{ "comment", CommentRole, kli18nc("@label", "Comment"), KLazyLocalizedString(), true, false },
|
||||
|
|
|
@ -290,7 +290,7 @@ private:
|
|||
enum RoleType {
|
||||
// User visible roles:
|
||||
NoRole, NameRole, SizeRole, ModificationTimeRole, CreationTimeRole, AccessTimeRole, PermissionsRole, OwnerRole,
|
||||
GroupRole, TypeRole, DestinationRole, PathRole, DeletionTimeRole,
|
||||
GroupRole, TypeRole, ExtensionRole, DestinationRole, PathRole, DeletionTimeRole,
|
||||
// User visible roles available with Baloo:
|
||||
CommentRole, TagsRole, RatingRole, DimensionsRole, WidthRole, HeightRole, ImageDateTimeRole, OrientationRole,
|
||||
WordCountRole, TitleRole, AuthorRole, LineCountRole, ArtistRole, GenreRole, AlbumRole, DurationRole, TrackRole, ReleaseYearRole,
|
||||
|
@ -527,6 +527,7 @@ private:
|
|||
inline bool KFileItemModel::isRoleValueNatural(RoleType roleType)
|
||||
{
|
||||
return (roleType == TypeRole ||
|
||||
roleType == ExtensionRole ||
|
||||
roleType == TagsRole ||
|
||||
roleType == CommentRole ||
|
||||
roleType == TitleRole ||
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#endif
|
||||
|
||||
#include <QApplication>
|
||||
#include <QFileInfo>
|
||||
#include <QIcon>
|
||||
#include <QPainter>
|
||||
#include <QPluginLoader>
|
||||
|
@ -1337,6 +1338,10 @@ QHash<QByteArray, QVariant> KFileItemModelRolesUpdater::rolesData(const KFileIte
|
|||
}
|
||||
}
|
||||
|
||||
if (m_roles.contains("extension")) {
|
||||
data.insert("extension", QFileInfo(item.name()).suffix());
|
||||
}
|
||||
|
||||
if (m_roles.contains("type")) {
|
||||
data.insert("type", item.mimeComment());
|
||||
}
|
||||
|
|
|
@ -664,7 +664,7 @@ void DolphinViewActionHandler::slotSortRoleChanged(const QByteArray& role)
|
|||
QAction* descending = m_actionCollection->action(QStringLiteral("descending"));
|
||||
QAction* ascending = m_actionCollection->action(QStringLiteral("ascending"));
|
||||
|
||||
if (role == "text" || role == "type" || role == "tags" || role == "comment") {
|
||||
if (role == "text" || role == "type" || role == "extension" || role == "tags" || role == "comment") {
|
||||
descending->setText(i18nc("Sort descending", "Z-A"));
|
||||
ascending->setText(i18nc("Sort ascending", "A-Z"));
|
||||
} else if (role == "size") {
|
||||
|
|
Loading…
Reference in a new issue