Skip to content

Commit

Permalink
feat: [desktop] new organize mode
Browse files Browse the repository at this point in the history
1. add more dconfigs;
2. files are inserted into desktop not into collection on created;
3. new menu action: organize desktop, renamed action: Organize desktop-
>enable desktop organizition;
4. organize files on file renamed;
5. drag files from canvas to collections;
6. drag files from collections to canvas;
7. move 'Enable organize' from contextmenu to option dialog;

Log: as contents.

Task: https://pms.uniontech.com/task-view-354097.html
  • Loading branch information
itsXuSt authored and Johnson-zs committed Jun 28, 2024
1 parent 17117aa commit 06d2b53
Show file tree
Hide file tree
Showing 16 changed files with 228 additions and 48 deletions.
4 changes: 2 additions & 2 deletions assets/configs/org.deepin.dde.file-manager.desktop.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"description": "It's used to control whether the auto align on desktop is enabled.",
"permissions": "readwrite",
"visibility": "public"
},
},
"maskLogoUri": {
"value": "",
"serial": 0,
Expand Down Expand Up @@ -80,4 +80,4 @@
"visibility": "public"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@
"description": "Prompt dialog for turning on/off hidden collections.",
"permissions": "readwrite",
"visibility": "public"
}
},
"organizeAction": {
"value": 0,
"serial": 0,
"flags": [],
"name": "Organize action",
"name[zh_CN]": "整理动作",
"description[zh_CN]": "单次整理(0)或自动整理(1),当选择单次整理时,整理行为仅在用户触发整理时发生,新建的文件不会被整理到集合中",
"description": "Single-time organization (0) or automatic organization (1): When single-time organization is selected, the organization action only occurs when triggered by the user, and newly created files will not be organized into the collection.",
"permissions": "readwrite",
"visibility": "public"
}
}
}
11 changes: 11 additions & 0 deletions src/plugins/desktop/ddplugin-organizer/config/configpresenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,17 @@ void ConfigPresenter::setEnabledTypeCategories(ItemCategories flags)
conf->sync();
}

OrganizeAction ConfigPresenter::organizeAction() const

Check warning on line 241 in src/plugins/desktop/ddplugin-organizer/config/configpresenter.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'organizeAction' is never used.

Check warning on line 241 in src/plugins/desktop/ddplugin-organizer/config/configpresenter.cpp

View workflow job for this annotation

GitHub Actions / static-check / Static-Check

The function 'organizeAction' is never used.
{
int val = DConfigManager::instance()->value(kConfName, "organizeAction", 0).toInt();
return val == 0 ? kOnTrigger : kAlways;
}

bool ConfigPresenter::organizeOnTriggered() const
{
return OrganizeAction() == kOnTrigger;
}

CollectionStyle ConfigPresenter::normalStyle(const QString &key) const
{
if (key.isEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ class ConfigPresenter : public QObject
public:
ItemCategories enabledTypeCategories() const;
void setEnabledTypeCategories(ItemCategories flags);

OrganizeAction organizeAction() const;
bool organizeOnTriggered() const;

signals:
// use Qt::QueuedConnection
void changeEnableState(bool e);
Expand All @@ -71,6 +75,8 @@ class ConfigPresenter : public QObject
void changeDisplaySize(int);
void newCollection(const QList<QUrl> &);
void showOptionWindow();
void reorganizeDesktop();

public slots:
protected:
explicit ConfigPresenter(QObject *parent = nullptr);
Expand Down
40 changes: 32 additions & 8 deletions src/plugins/desktop/ddplugin-organizer/menus/extendcanvasscene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ ExtendCanvasScenePrivate::ExtendCanvasScenePrivate(ExtendCanvasScene *qq)

void ExtendCanvasScenePrivate::emptyMenu(QMenu *parent)
{
QAction *tempAction = parent->addAction(predicateName.value(ActionID::kOrganizeDesktop));
predicateAction[ActionID::kOrganizeDesktop] = tempAction;
tempAction->setProperty(ActionPropertyKey::kActionID, QString(ActionID::kOrganizeDesktop));
tempAction->setCheckable(true);
tempAction->setChecked(turnOn);
QAction *tempAction = nullptr;
// tempAction = parent->addAction(predicateName.value(ActionID::kOrganizeEnable));
// predicateAction[ActionID::kOrganizeEnable] = tempAction;
// tempAction->setProperty(ActionPropertyKey::kActionID, QString(ActionID::kOrganizeEnable));
// tempAction->setCheckable(true);
// tempAction->setChecked(turnOn);

if (turnOn) {
#ifdef EnableCollectionModeMenu
Expand All @@ -46,6 +47,11 @@ void ExtendCanvasScenePrivate::emptyMenu(QMenu *parent)
predicateAction[ActionID::kOrganizeBy] = tempAction;
tempAction->setProperty(ActionPropertyKey::kActionID, QString(ActionID::kOrganizeBy));
#endif
if (ConfigPresenter::instance()->organizeOnTriggered()) {
tempAction = new QAction(predicateName.value(ActionID::kOrganizeTrigger), parent);
predicateAction[ActionID::kOrganizeTrigger] = tempAction;
tempAction->setProperty(ActionPropertyKey::kActionID, QString(ActionID::kOrganizeTrigger));
}
}

tempAction = parent->addAction(predicateName.value(ActionID::kOrganizeOptions));
Expand Down Expand Up @@ -84,7 +90,7 @@ void ExtendCanvasScenePrivate::updateEmptyMenu(QMenu *parent)
<< "display-settings";
} else {
QAction *indexAction = actions[pos];
parent->insertAction(indexAction, predicateAction[ActionID::kOrganizeDesktop]);
parent->insertAction(indexAction, predicateAction[ActionID::kOrganizeEnable]);
if (turnOn) {
parent->insertAction(indexAction, predicateAction[ActionID::kOrganizeBy]);
parent->insertAction(indexAction, predicateAction[ActionID::kOrganizeOptions]);
Expand All @@ -104,6 +110,21 @@ void ExtendCanvasScenePrivate::updateEmptyMenu(QMenu *parent)
parent->insertAction(indexAction, predicateAction[ActionID::kOrganizeOptions]);
}
}

if (turnOn) {
auto refreshPos = std::find_if(actions.begin(), actions.end(), [](QAction *action) {
return action->property(ActionPropertyKey::kActionID).toString() == "refresh";
});
if (refreshPos == actions.end()) {
parent->addAction(predicateAction[ActionID::kOrganizeTrigger]);
} else {
int idx = int(std::distance(actions.begin(), refreshPos)) + 1;
if (idx < actions.count()) {
auto act = actions.at(idx);
parent->insertAction(act, predicateAction[ActionID::kOrganizeTrigger]);
}
}
}
}
}

Expand Down Expand Up @@ -206,7 +227,8 @@ bool ExtendCanvasScenePrivate::triggerSortby(const QString &actionId)
ExtendCanvasScene::ExtendCanvasScene(QObject *parent)
: AbstractMenuScene(parent), d(new ExtendCanvasScenePrivate(this))
{
d->predicateName[ActionID::kOrganizeDesktop] = tr("Organize desktop");
d->predicateName[ActionID::kOrganizeEnable] = tr("Enable desktop organization");
d->predicateName[ActionID::kOrganizeTrigger] = tr("Organize desktop");
d->predicateName[ActionID::kOrganizeOptions] = tr("View options");
d->predicateName[ActionID::kOrganizeBy] = tr("Organize by");

Expand Down Expand Up @@ -283,7 +305,7 @@ bool ExtendCanvasScene::triggered(QAction *action)
auto actionId = action->property(ActionPropertyKey::kActionID).toString();
if (d->predicateAction.values().contains(action)) {
fmDebug() << "organizer for canvas:" << actionId;
if (actionId == ActionID::kOrganizeDesktop) {
if (actionId == ActionID::kOrganizeEnable) {
emit CfgPresenter->changeEnableState(action->isChecked());
} else if (actionId == ActionID::kOrganizeByCustom) {
emit CfgPresenter->switchToCustom();
Expand All @@ -299,6 +321,8 @@ bool ExtendCanvasScene::triggered(QAction *action)
emit CfgPresenter->newCollection(d->selectFiles);
} else if (actionId == ActionID::kOrganizeOptions) {
emit CfgPresenter->showOptionWindow();
} else if (actionId == ActionID::kOrganizeTrigger) {
emit CfgPresenter->reorganizeDesktop();
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
namespace ddplugin_organizer {

namespace ActionID {
inline constexpr char kOrganizeDesktop[] = "organize-desktop";
inline constexpr char kOrganizeEnable[] = "organize-enable";
inline constexpr char kOrganizeTrigger[] = "organize-trigger";
inline constexpr char kOrganizeOptions[] = "organize-options";
inline constexpr char kOrganizeBy[] = "organize-by";
inline constexpr char kOrganizeByType[] = "organize-by-type";
Expand All @@ -19,12 +20,12 @@ inline constexpr char kOrganizeByTimeModified[] = "organize-by-time-modified";
inline constexpr char kOrganizeByTimeCreated[] = "organize-by-time-created";
inline constexpr char kOrganizeByCustom[] = "custom-collection";
inline constexpr char kCreateACollection[] = "create-a-collection";
} // namespace ActionID
} // namespace ActionID

namespace CollectionMenuParams {
inline constexpr char kOnColletion[] = "OnColletion";
inline constexpr char kColletionView[] = "ColletionView";
}
}

#endif // ORGANIZERMENU_DEFINES_H
#endif // ORGANIZERMENU_DEFINES_H
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class CollectionDataProvider : public QObject
virtual void addPreItems(const QString &targetKey, const QList<QUrl> &urls, int targetIndex);
virtual bool checkPreItem(const QUrl &url, QString &key, int &index);
virtual bool takePreItem(const QUrl &url, QString &key, int &index);
protected:
virtual QString replace(const QUrl &oldUrl, const QUrl &newUrl) = 0;
virtual QString append(const QUrl &) = 0;
virtual QString prepend(const QUrl &) = 0;
Expand All @@ -40,11 +39,12 @@ class CollectionDataProvider : public QObject
signals:
void nameChanged(const QString &key, const QString &name);
void itemsChanged(const QString &key);

protected:
QHash<QString, CollectionBaseDataPtr> collections;
QHash<QString, QPair<int, QList<QUrl>>> preCollectionItems;
};

}

#endif // COLLECTIONDATAPROVIDER_H
#endif // COLLECTIONDATAPROVIDER_H
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public slots:
void updateHolderSurfaceIndex(QWidget *surface);

public:
void restore(const QList<CollectionBaseDataPtr> &cfgs);
void restore(const QList<CollectionBaseDataPtr> &cfgs, bool reorganized = false);
FileClassifier *classifier = nullptr;
QHash<QString, CollectionHolderPointer> holders;
NormalizedModeBroker *broker = nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,18 @@ inline const char kTypeSuffixApp[] = "desktop";
*tablePtr = tablePtr->fromList(QString(suffix).split(',')); \
}
TypeClassifierPrivate::TypeClassifierPrivate(TypeClassifier *qq)
: q(qq) {
//todo(zy) 类型后缀支持可配置
InitSuffixTable(docSuffix, kTypeSuffixDoc)
InitSuffixTable(picSuffix, kTypeSuffixPic)
InitSuffixTable(muzSuffix, kTypeSuffixMuz)
InitSuffixTable(vidSuffix, kTypeSuffixVid)
InitSuffixTable(appSuffix, kTypeSuffixApp)
//InitSuffixTable(appMimeType, kTypeMimeApp)
}

TypeClassifierPrivate::~TypeClassifierPrivate()
: q(qq)
{
//todo(zy) 类型后缀支持可配置
InitSuffixTable(docSuffix, kTypeSuffixDoc);
InitSuffixTable(picSuffix, kTypeSuffixPic);
InitSuffixTable(muzSuffix, kTypeSuffixMuz);
InitSuffixTable(vidSuffix, kTypeSuffixVid);
InitSuffixTable(appSuffix, kTypeSuffixApp);
//InitSuffixTable(appMimeType, kTypeMimeApp);
}

TypeClassifierPrivate::~TypeClassifierPrivate()
{
}

Expand Down
Loading

0 comments on commit 06d2b53

Please sign in to comment.