Skip to content

Commit

Permalink
feat: add new type for file sort
Browse files Browse the repository at this point in the history
1.Add new type of column in list view mode.
2.Add new type for file sort.

Log: add new type for file sort
Task: https://pms.uniontech.com/story-view-37825.html
  • Loading branch information
Lighto-Ku committed Jan 9, 2025
1 parent 644c907 commit a42fd89
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ QMap<QString, QStringList> CanvasBaseSortMenuScenePrivate::secondaryMenuRule()
"sort-by-source-path",
"sort-by-lastRead",
"sort-by-time-modified",
"sort-by-time-created",
"sort-by-time-deleted",
"sort-by-size",
"sort-by-type" }); // 排序方式
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ inline constexpr char kAutoArrange[] { "auto-arrange" }; // 1071: removed
// sort by
inline constexpr char kSrtName[] { "sort-by-name" };
inline constexpr char kSrtTimeModified[] { "sort-by-time-modified" };
inline constexpr char kSrtTimeCreated[] { "sort-by-time-created" };
inline constexpr char kSrtSize[] { "sort-by-size" };
inline constexpr char kSrtType[] { "sort-by-type" };

Expand Down
8 changes: 7 additions & 1 deletion src/plugins/desktop/ddplugin-canvas/menu/canvasmenuscene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ CanvasMenuScene::CanvasMenuScene(QObject *parent)
// 排序子菜单
d->predicateName[ActionID::kSrtName] = tr("Name");
d->predicateName[ActionID::kSrtTimeModified] = tr("Time modified");
d->predicateName[ActionID::kSrtTimeCreated] = tr("Time created");
d->predicateName[ActionID::kSrtSize] = tr("Size");
d->predicateName[ActionID::kSrtType] = tr("Type");

Expand Down Expand Up @@ -294,7 +295,8 @@ bool CanvasMenuScene::triggered(QAction *action)
{ ActionID::kSrtName, Global::ItemRoles::kItemFileDisplayNameRole },
{ ActionID::kSrtSize, Global::ItemRoles::kItemFileSizeRole },
{ ActionID::kSrtType, Global::ItemRoles::kItemFileMimeTypeRole },
{ ActionID::kSrtTimeModified, Global::ItemRoles::kItemFileLastModifiedRole }
{ ActionID::kSrtTimeModified, Global::ItemRoles::kItemFileLastModifiedRole },
{ ActionID::kSrtTimeCreated, Global::ItemRoles::kItemFileCreatedRole },
};

if (sortRole.contains(actionId)) {
Expand Down Expand Up @@ -555,6 +557,10 @@ QMenu *CanvasMenuScene::sortBySubActions(QMenu *menu)
d->predicateAction[ActionID::kSrtTimeModified] = tempAction;
tempAction->setProperty(ActionPropertyKey::kActionID, QString(ActionID::kSrtTimeModified));

tempAction = subMenu->addAction(d->predicateName.value(ActionID::kSrtTimeCreated));
d->predicateAction[ActionID::kSrtTimeCreated] = tempAction;
tempAction->setProperty(ActionPropertyKey::kActionID, QString(ActionID::kSrtTimeCreated));

tempAction = subMenu->addAction(d->predicateName.value(ActionID::kSrtSize));
d->predicateAction[ActionID::kSrtSize] = tempAction;
tempAction->setProperty(ActionPropertyKey::kActionID, QString(ActionID::kSrtSize));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ bool ExtendCanvasScenePrivate::triggerSortby(const QString &actionId)
{ ddplugin_canvas::ActionID::kSrtName, Global::ItemRoles::kItemFileDisplayNameRole },
{ ddplugin_canvas::ActionID::kSrtSize, Global::ItemRoles::kItemFileSizeRole },
{ ddplugin_canvas::ActionID::kSrtType, Global::ItemRoles::kItemFileMimeTypeRole },
{ ddplugin_canvas::ActionID::kSrtTimeModified, Global::ItemRoles::kItemFileLastModifiedRole }
{ ddplugin_canvas::ActionID::kSrtTimeModified, Global::ItemRoles::kItemFileLastModifiedRole },
{ ddplugin_canvas::ActionID::kSrtTimeCreated, Global::ItemRoles::kItemFileCreatedRole }
};

if (sortRole.contains(actionId)) {
Expand Down
14 changes: 14 additions & 0 deletions src/plugins/filemanager/dfmplugin-titlebar/views/sortbybutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ static constexpr int kSortToolHMargin { 6 };
static constexpr int kSortToolVMargin { 9 };
static constexpr char kSortToolName[] = "sort-by-name";
static constexpr char kSortToolTimeModified[] = "sort-by-time-modified";
static constexpr char kSortToolTimeCreated[] = "sort-by-time-created";
static constexpr char kSortToolSize[] = "sort-by-size";
static constexpr char kSortToolType[] = "sort-by-type";

Expand All @@ -58,6 +59,12 @@ void SortByButtonPrivate::setItemSortRoles()
action->setChecked(true);
}
} break;
case DFMGLOBAL_NAMESPACE::kItemFileCreatedRole: {
auto action = menu->findChild<QAction *>(kSortToolTimeCreated);
if (action) {
action->setChecked(true);
}
} break;
case DFMGLOBAL_NAMESPACE::kItemFileSizeRole: {
auto action = menu->findChild<QAction *>(kSortToolSize);
if (action) {
Expand Down Expand Up @@ -98,6 +105,11 @@ void SortByButtonPrivate::initializeUi()
action->setCheckable(true);
actionGroup->addAction(action);

action = menu->addAction(tr("Time created"));
action->setObjectName(kSortToolTimeCreated);
action->setCheckable(true);
actionGroup->addAction(action);

action = menu->addAction(tr("Size"));
action->setObjectName(kSortToolSize);
action->setCheckable(true);
Expand All @@ -122,6 +134,8 @@ void SortByButtonPrivate::menuTriggered(QAction *action)
TitleBarEventCaller::sendSetSort(q, DFMGLOBAL_NAMESPACE::kItemFileDisplayNameRole);
} else if (action->objectName() == kSortToolTimeModified) {
TitleBarEventCaller::sendSetSort(q, DFMGLOBAL_NAMESPACE::kItemFileLastModifiedRole);
} else if (action->objectName() == kSortToolTimeCreated) {
TitleBarEventCaller::sendSetSort(q, DFMGLOBAL_NAMESPACE::kItemFileCreatedRole);
} else if (action->objectName() == kSortToolSize) {
TitleBarEventCaller::sendSetSort(q, DFMGLOBAL_NAMESPACE::kItemFileSizeRole);
} else if (action->objectName() == kSortToolType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ inline constexpr int kIconViewSpacing { 10 }; // icon模式下的间距的一
inline constexpr int kListViewSpacing { 0 };
inline constexpr int kIconModeColumnPadding { 10 };
inline constexpr int kDefualtHeaderSectionWidth { 140 };
inline constexpr int kDefaultItemFileLastModifiedWidth { 145 };
inline constexpr int kDefaultItemFileTimeWidth { 145 };
inline constexpr int kMinimumHeaderSectionWidth { 120 };
inline constexpr int kListViewHeaderHeight { 36 };
inline constexpr int kListViewIconSize { 24 };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ QMap<QString, QStringList> BaseSortMenuScenePrivate::secondaryMenuRule()
"sort-by-source-path",
"sort-by-lastRead",
"sort-by-time-modified",
"sort-by-time-created",
"sort-by-time-deleted",
"sort-by-size",
"sort-by-type" }); // 排序方式
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ SortAndDisplayMenuScene::SortAndDisplayMenuScene(QObject *parent)
// 排序子菜单
d->predicateName[ActionID::kSrtName] = tr("Name");
d->predicateName[ActionID::kSrtTimeModified] = tr("Time modified");
d->predicateName[ActionID::kSrtTimeCreated] = tr("Time created");
d->predicateName[ActionID::kSrtSize] = tr("Size");
d->predicateName[ActionID::kSrtType] = tr("Type");

Expand Down Expand Up @@ -130,13 +131,19 @@ bool SortAndDisplayMenuScene::triggered(QAction *action)
return true;
}

// sort by time created
if (actionId == ActionID::kSrtTimeCreated) {
d->sortByRole(Global::ItemRoles::kItemFileCreatedRole);
return true;
}

// sort by size
if (actionId == ActionID::kSrtSize) {
d->sortByRole(Global::ItemRoles::kItemFileSizeRole);
return true;
}

// sort by size
// sort by type
if (actionId == ActionID::kSrtType) {
d->sortByRole(Global::ItemRoles::kItemFileMimeTypeRole);
return true;
Expand Down Expand Up @@ -180,6 +187,11 @@ QMenu *SortAndDisplayMenuScenePrivate::addSortByActions(QMenu *menu)
predicateAction[ActionID::kSrtTimeModified] = tempAction;
tempAction->setProperty(ActionPropertyKey::kActionID, QString(ActionID::kSrtTimeModified));

tempAction = subMenu->addAction(predicateName.value(ActionID::kSrtTimeCreated));
tempAction->setCheckable(true);
predicateAction[ActionID::kSrtTimeCreated] = tempAction;
tempAction->setProperty(ActionPropertyKey::kActionID, QString(ActionID::kSrtTimeCreated));

tempAction = subMenu->addAction(predicateName.value(ActionID::kSrtSize));
tempAction->setCheckable(true);
predicateAction[ActionID::kSrtSize] = tempAction;
Expand Down Expand Up @@ -243,6 +255,9 @@ void SortAndDisplayMenuScenePrivate::updateEmptyAreaActionState()
case kItemFileLastModifiedRole:
predicateAction[ActionID::kSrtTimeModified]->setChecked(true);
break;
case kItemFileCreatedRole:
predicateAction[ActionID::kSrtTimeCreated]->setChecked(true);
break;
case kItemFileSizeRole:
predicateAction[ActionID::kSrtSize]->setChecked(true);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ inline constexpr char kRefresh[] = "refresh";
// sort by
inline constexpr char kSrtName[] = "sort-by-name";
inline constexpr char kSrtTimeModified[] = "sort-by-time-modified";
inline constexpr char kSrtTimeCreated[] = "sort-by-time-created";
inline constexpr char kSrtSize[] = "sort-by-size";
inline constexpr char kSrtType[] = "sort-by-type";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ QVariant FileItemData::data(int role) const
}
return "-";
}
case kItemFileCreatedRole: {
if (info) {
auto created = info->timeOf(TimeInfoType::kCreateTime).value<QDateTime>();
return created.isValid() ? created.toString(FileUtils::dateTimeFormat()) : "-";
}
return "-";
}
case kItemIconRole:
return fileIcon();
case kItemFileSizeRole:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ QList<ItemRoles> FileViewModel::getColumnRoles() const
} else if (!customOnly) {
static QList<ItemRoles> defualtColumnRoleList = QList<ItemRoles>() << kItemFileDisplayNameRole
<< kItemFileLastModifiedRole
<< kItemFileCreatedRole
<< kItemFileSizeRole
<< kItemFileMimeTypeRole;

Expand Down Expand Up @@ -616,6 +617,7 @@ ItemRoles FileViewModel::columnToRole(int column) const
} else if (!customOnly) {
static QList<ItemRoles> defualtColumnRoleList = QList<ItemRoles>() << kItemFileDisplayNameRole
<< kItemFileLastModifiedRole
<< kItemFileCreatedRole
<< kItemFileSizeRole
<< kItemFileMimeTypeRole;

Expand All @@ -639,6 +641,8 @@ QString FileViewModel::roleDisplayString(int role) const
return tr("Name");
case kItemFileLastModifiedRole:
return tr("Time modified");
case kItemFileCreatedRole:
return tr("Time created");
case kItemFileSizeRole:
return tr("Size");
case kItemFileMimeTypeRole:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1450,6 +1450,7 @@ bool FileSortWorker::lessThan(const QUrl &left, const QUrl &right, AbstractSortF
switch (orgSortRole) {
case kItemFileDisplayNameRole:
case kItemFileLastModifiedRole:
case kItemFileCreatedRole:
case kItemFileMimeTypeRole:
return FileUtils::compareByStringEx(leftData.toString(), rightData.toString());
case kItemFileSizeRole: {
Expand Down Expand Up @@ -1478,6 +1479,10 @@ QVariant FileSortWorker::data(const FileInfoPointer &info, ItemRoles role)
auto lastModified = info->timeOf(TimeInfoType::kLastModified).value<QDateTime>();
return lastModified.isValid() ? lastModified.toString(FileUtils::dateTimeFormat()) : "-";
}
case kItemFileCreatedRole: {
auto created = info->timeOf(TimeInfoType::kCreateTime).value<QDateTime>();
return created.isValid() ? created.toString(FileUtils::dateTimeFormat()) : "-";
}
case kItemIconRole:
return info->fileIcon();
case kItemFileSizeRole:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2260,8 +2260,8 @@ void FileView::updateListHeaderView()
if (colWidth > 0) {
d->headerView->resizeSection(model()->getColumnByRole(curRole), colWidth);
} else {
if (curRole == kItemFileLastModifiedRole) {
d->headerView->resizeSection(model()->getColumnByRole(curRole), kDefaultItemFileLastModifiedWidth);
if (curRole == kItemFileLastModifiedRole || curRole == kItemFileCreatedRole) {
d->headerView->resizeSection(model()->getColumnByRole(curRole), kDefaultItemFileTimeWidth);
}
}
} else {
Expand Down

0 comments on commit a42fd89

Please sign in to comment.