Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

桌面整理快捷键调整,以及 dock 插件图标出走问题修复 #2091

Merged
merged 3 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"visibility": "public"
},
"hideAllKeySeq" : {
"value": "Meta+O",
"value": "Alt+O",
"serial": 0,
"flags": [],
"name": "Hide All KeySeq",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ DiskMountPlugin::DiskMountPlugin(QObject *parent)
diskPluginItem(new DiskPluginItem)
{
loadTranslator();
diskPluginItem->setVisible(true);
diskPluginItem->setVisible(false);
tipsLabel->setObjectName("diskmount");
tipsLabel->setVisible(false);
tipsLabel->setText(tr("Disk"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class ConfigPresenter : public QObject
void changeEnableVisibilityState(bool v);
void changeHideAllKeySequence(const QKeySequence &);
void switchToNormalized(int);
void releaseCollection(int category);
void switchToCustom();
void changeDisplaySize(int);
void newCollection(const QList<QUrl> &);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class FileClassifier : public CollectionDataProvider, public ModelDataHandler
virtual QString classify(const QUrl &) const = 0;
virtual QString className(const QString &) const = 0;
virtual void reset(const QList<QUrl> &);
virtual void updateClassifier() = 0;

public:
CollectionBaseDataPtr baseData(const QString &key) const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public slots:
void updateHolderSurfaceIndex(QWidget *surface);
bool batchRenameFiles();

bool moveFilesToCanvas(int viewIndex, const QMimeData *mimeData, const QPoint &viewPoint);
bool moveFilesToCanvas(int viewIndex, const QList<QUrl> &urls, const QPoint &viewPoint);

public:
void restore(const QList<CollectionBaseDataPtr> &cfgs, bool reorganized = false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ using namespace ddplugin_organizer;
DFMBASE_USE_NAMESPACE

namespace {
inline const char kTypeKeyApp[] = "Type_Apps";
inline const char kTypeKeyDoc[] = "Type_Documents";
inline const char kTypeKeyPic[] = "Type_Pictures";
inline const char kTypeKeyVid[] = "Type_Videos";
inline const char kTypeKeyMuz[] = "Type_Music";
inline const char kTypeKeyFld[] = "Type_Folders";
inline const char kTypeKeyOth[] = "Type_Other";

inline const char kTypeSuffixDoc[] = "pdf,txt,doc,docx,dot,dotx,ppt,pptx,"
"pot,potx,xls,xlsx,xlt,xltx,wps,wpt,rtf,"
Expand Down Expand Up @@ -67,18 +60,7 @@ TypeClassifier::TypeClassifier(QObject *parent)
{ kTypeKeyOth, tr("Other") }
};
}
{
QHash<ItemCategory, QString> *categoryPtr = const_cast<QHash<ItemCategory, QString> *>(&d->categoryKey);
*categoryPtr = {
{ kCatApplication, kTypeKeyApp },
{ kCatDocument, kTypeKeyDoc },
{ kCatPicture, kTypeKeyPic },
{ kCatVideo, kTypeKeyVid },
{ kCatMusic, kTypeKeyMuz },
{ kCatFolder, kTypeKeyFld },
{ kCatOther, kTypeKeyOth }
};
}

// all datas shoud be accepted.
handler = new GeneralModelFilter();

Expand Down Expand Up @@ -125,8 +107,8 @@ QStringList TypeClassifier::classes() const
for (int i = kCatApplication; i <= kCatEnd; i = i << 1) {
auto cat = static_cast<ItemCategory>(i);
if (d->categories.testFlag(cat)) {
Q_ASSERT(d->categoryKey.contains(cat));
auto key = d->categoryKey.value(cat);
Q_ASSERT(kCategory2Key.contains(cat));
auto key = kCategory2Key.value(cat);
if (d->keyNames.contains(key)) {
Q_ASSERT(!usedKey.contains(key));
usedKey.append(key);
Expand Down Expand Up @@ -184,6 +166,11 @@ QString TypeClassifier::className(const QString &key) const
return d->keyNames.value(key);
}

void TypeClassifier::updateClassifier()
{
d->categories = CfgPresenter->enabledTypeCategories();
}

QString TypeClassifier::replace(const QUrl &oldUrl, const QUrl &newUrl)
{
if (!classes().contains(classify(newUrl)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class TypeClassifier : public FileClassifier
QStringList classes() const override;
QString classify(const QUrl &) const override;
QString className(const QString &key) const override;
void updateClassifier() override;

public:
QString replace(const QUrl &oldUrl, const QUrl &newUrl) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ class TypeClassifierPrivate
public:
explicit TypeClassifierPrivate(TypeClassifier *qq);
~TypeClassifierPrivate();

public:
ItemCategories categories;
const QHash<ItemCategory, QString> categoryKey;
const QHash<QString, QString> keyNames;
const QSet<QString> docSuffix;
const QSet<QString> picSuffix;
Expand All @@ -30,4 +30,4 @@ class TypeClassifierPrivate

}

#endif // TYPECLASSIFIER_P_H
#endif // TYPECLASSIFIER_P_H
32 changes: 23 additions & 9 deletions src/plugins/desktop/ddplugin-organizer/mode/normalizedmode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,8 @@ bool NormalizedModePrivate::batchRenameFiles()
return true;
}

bool NormalizedModePrivate::moveFilesToCanvas(int viewIndex, const QMimeData *mimeData, const QPoint &viewPoint)
bool NormalizedModePrivate::moveFilesToCanvas(int viewIndex, const QList<QUrl> &urls, const QPoint &viewPoint)
{
auto urls = mimeData->urls();
QList<QUrl> collectionItems;
QStringList files;
for (auto url : urls) {
Expand Down Expand Up @@ -451,6 +450,7 @@ bool NormalizedMode::initialize(CollectionModel *m)
connect(model, &CollectionModel::modelReset, this, [this] { rebuild(); }, Qt::QueuedConnection);

connect(CfgPresenter, &ConfigPresenter::reorganizeDesktop, this, &NormalizedMode::onReorganizeDesktop, Qt::QueuedConnection);
connect(CfgPresenter, &ConfigPresenter::releaseCollection, this, &NormalizedMode::releaseCollection, Qt::QueuedConnection);

// creating if there already are files.
if (!model->files().isEmpty())
Expand Down Expand Up @@ -633,12 +633,8 @@ void NormalizedMode::rebuild(bool reorganize)
time.start();
{
auto files = model->files();

if (reorganize) { // classifier's categories should be updated.
QSignalBlocker block(model);
reset(); // classifier will be re-new-ed, which will refresh model and cause rebuild function retriggered. so block signal
}

if (reorganize) // classifier's categories should be updated.
d->classifier->updateClassifier();
d->classifier->reset(files);

// order item as config
Expand Down Expand Up @@ -777,6 +773,24 @@ void NormalizedMode::onReorganizeDesktop()
Q_EMIT d->classifier->itemsChanged(type); // to update the collection view's vertical scroll range.
}

void NormalizedMode::releaseCollection(int category)
{
if (!d->classifier)
return;
QString key = kCategory2Key.value(ItemCategory(category), "");
if (key.isEmpty())
return;

auto files = model->files();
QList<QUrl> releases;
for (auto url : files) {
if (d->classifier->classify(url) == key)
releases << url;
}
if (!releases.isEmpty())
d->moveFilesToCanvas(0, releases, { 0, 0 });
}

void NormalizedMode::onCollectionEditStatusChanged(bool editing)
{
this->editing = editing;
Expand Down Expand Up @@ -819,7 +833,7 @@ bool NormalizedMode::filterDropData(int viewIndex, const QMimeData *mimeData, co
}

if (act == Qt::MoveAction)
return d->moveFilesToCanvas(viewIndex, mimeData, viewPoint);
return d->moveFilesToCanvas(viewIndex, mimeData->urls(), viewPoint);
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public slots:
void onFileAboutToBeRemoved(const QModelIndex &parent, int first, int last);
void onFileDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
void onReorganizeDesktop();
void releaseCollection(int category);

protected slots:
bool filterDropData(int viewIndex, const QMimeData *mimeData, const QPoint &viewPoint, void *extData) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@ void TypeMethodGroup::onChanged(bool on)
flags = OrganizerUtils::buildBitwiseEnabledCategory(flags);
CfgPresenter->setEnabledTypeCategories(flags);
// do not re-layout items if `organizeOnTrigger` and checkbox checked.
if (!on || !CfgPresenter->organizeOnTriggered()) {
// using switch signal to reset the collection.
emit CfgPresenter->switchToNormalized(id());
if (!CfgPresenter->organizeOnTriggered()) {
emit CfgPresenter->reorganizeDesktop();
} else if (!on) {
emit CfgPresenter->releaseCollection(flag);
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/plugins/desktop/ddplugin-organizer/organizer_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ enum ItemCategory {
};
Q_DECLARE_FLAGS(ItemCategories, ItemCategory)

inline const char kTypeKeyApp[] = "Type_Apps";
inline const char kTypeKeyDoc[] = "Type_Documents";
inline const char kTypeKeyPic[] = "Type_Pictures";
inline const char kTypeKeyVid[] = "Type_Videos";
inline const char kTypeKeyMuz[] = "Type_Music";
inline const char kTypeKeyFld[] = "Type_Folders";
inline const char kTypeKeyOth[] = "Type_Other";
inline const QMap<ItemCategory, QString> kCategory2Key {
{ kCatApplication, kTypeKeyApp },
{ kCatDocument, kTypeKeyDoc },
{ kCatPicture, kTypeKeyPic },
{ kCatVideo, kTypeKeyVid },
{ kCatMusic, kTypeKeyMuz },
{ kCatFolder, kTypeKeyFld },
{ kCatOther, kTypeKeyOth }
};

enum CollectionFrameSize {
kMiddle = 0,
kLarge,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,6 @@ CollectionView::CollectionView(const QString &uuid, CollectionDataProvider *data

d->initUI();
d->initConnect();

setObjectName("dd_collection_view");
}

Expand Down
58 changes: 31 additions & 27 deletions tests/plugins/desktop/ddplugin-organizer/mode/ut_fileclassifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@ namespace {
class TestFileClassifier : public FileClassifier, public Test
{
public:
Classifier mode() const {return kName;}
ModelDataHandler *dataHandler() const {return nullptr;}
QStringList classes() const {return ids.keys();}
QString classify(const QUrl &url) const {return ids.key(url.fileName().left(3));}
QString className(const QString &key) const {return ids.value(key);}
Classifier mode() const { return kName; }
ModelDataHandler *dataHandler() const { return nullptr; }
QStringList classes() const { return ids.keys(); }
QString classify(const QUrl &url) const { return ids.key(url.fileName().left(3)); }
QString className(const QString &key) const { return ids.value(key); }
void updateClassifier() {};

public:
void SetUp() override {
void SetUp() override
{

stub.set_lamda(&ConfigPresenter::instance, [this](){
stub.set_lamda(&ConfigPresenter::instance, [this]() {
return cfg;
});

Expand All @@ -36,7 +39,8 @@ class TestFileClassifier : public FileClassifier, public Test
ids.insert("2", "two");
}

void TearDown() override {
void TearDown() override
{
delete cfg;
}

Expand All @@ -49,7 +53,7 @@ class TestFileClassifier : public FileClassifier, public Test

TEST_F(TestFileClassifier, createClassifier)
{
stub.set_lamda(&ConfigPresenter::enabledTypeCategories, [](){
stub.set_lamda(&ConfigPresenter::enabledTypeCategories, []() {
return kCatDefault;
});

Expand All @@ -62,35 +66,35 @@ TEST_F(TestFileClassifier, createClassifier)

TEST_F(TestFileClassifier, construct)
{
CollectionBaseDataPtr dp(new CollectionBaseData);
collections.insert("1", dp);
QList<CollectionBaseDataPtr> in;
stub.set_lamda(&ConfigPresenter::saveNormalProfile,
[&in](ConfigPresenter *, const QList<CollectionBaseDataPtr> &baseDatas){

in = baseDatas;
});

emit this->itemsChanged("1");

ASSERT_EQ(in.size(), 1);
EXPECT_EQ(in.first(), dp);
CollectionBaseDataPtr dp(new CollectionBaseData);
collections.insert("1", dp);
QList<CollectionBaseDataPtr> in;
stub.set_lamda(&ConfigPresenter::saveNormalProfile,
[&in](ConfigPresenter *, const QList<CollectionBaseDataPtr> &baseDatas) {
in = baseDatas;
});

emit this->itemsChanged("1");

ASSERT_EQ(in.size(), 1);
EXPECT_EQ(in.first(), dp);
}

namespace {
class TestFileClassifier2 : public TestFileClassifier
{
public:
void SetUp() override {
void SetUp() override
{
TestFileClassifier::SetUp();
stub.set_lamda(&ConfigPresenter::saveNormalProfile, [](){});
QObject::connect(this, &FileClassifier::itemsChanged, this, [this]
(const QString &t){
stub.set_lamda(&ConfigPresenter::saveNormalProfile, []() {});
QObject::connect(this, &FileClassifier::itemsChanged, this, [this](const QString &t) {
types.append(t);
});
}

void initDP() {
void initDP()
{
dp.reset(new CollectionBaseData);
dp->name = "one";
dp->key = "1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,8 @@ class TestFileClassifier : public FileClassifier
QStringList classes() const { return ids.keys(); }
QString classify(const QUrl &url) const { return ids.key(url.fileName().left(3)); }
QString className(const QString &key) const { return ids.value(key); }
void updateClassifier() {};

QMap<QString, QString> ids;
};

Expand Down
Loading