From f619e602e1d89949d7d22d7102c1a701e1eda2b0 Mon Sep 17 00:00:00 2001 From: liyigang Date: Wed, 19 Jun 2024 14:16:53 +0800 Subject: [PATCH] fix: After enabling the long file name function, delete files to the trash. Right click on the attribute window and there is marked information that can be edited All trash files cannot be marked. Register the hook_cantag function and return a tag that is not allowed Log: After enabling the long file name function, delete files to the trash. Right click on the attribute window and there is marked information that can be edited Bug: https://pms.uniontech.com/bug-view-260621.html --- .../filemanager/core/dfmplugin-trash/trash.cpp | 14 ++++++++++++++ .../core/dfmplugin-trash/utils/trashfilehelper.cpp | 11 +++++++++++ .../core/dfmplugin-trash/utils/trashfilehelper.h | 1 + 3 files changed, 26 insertions(+) diff --git a/src/plugins/filemanager/core/dfmplugin-trash/trash.cpp b/src/plugins/filemanager/core/dfmplugin-trash/trash.cpp index a40283c25d..f12454e5bd 100644 --- a/src/plugins/filemanager/core/dfmplugin-trash/trash.cpp +++ b/src/plugins/filemanager/core/dfmplugin-trash/trash.cpp @@ -168,6 +168,20 @@ void Trash::followEvents() dpfHookSequence->follow("dfmplugin_fileoperations", "hook_Operation_OpenFileInPlugin", TrashFileHelper::instance(), &TrashFileHelper::openFileInPlugin); dpfHookSequence->follow("dfmplugin_utils", "hook_OpenWith_DisabledOpenWithWidget", TrashFileHelper::instance(), &TrashFileHelper::disableOpenWidgetWidget); + + // register to tag + auto searchPlugin { DPF_NAMESPACE::LifeCycle::pluginMetaObj("dfmplugin-tag") }; + if (searchPlugin && searchPlugin->pluginState() == DPF_NAMESPACE::PluginMetaObject::kStarted) { + dpfHookSequence->follow("dfmplugin_tag", "hook_CanTaged", TrashFileHelper::instance(), &TrashFileHelper::handleCanTag); + } else { + connect( + DPF_NAMESPACE::Listener::instance(), &DPF_NAMESPACE::Listener::pluginStarted, this, [](const QString &iid, const QString &name) { + Q_UNUSED(iid) + if (name == "dfmplugin-tag") + dpfHookSequence->follow("dfmplugin_tag", "hook_CanTaged", TrashFileHelper::instance(), &TrashFileHelper::handleCanTag); + }, + Qt::DirectConnection); + } } void Trash::bindWindows() diff --git a/src/plugins/filemanager/core/dfmplugin-trash/utils/trashfilehelper.cpp b/src/plugins/filemanager/core/dfmplugin-trash/utils/trashfilehelper.cpp index 388387309f..01f1881f5e 100644 --- a/src/plugins/filemanager/core/dfmplugin-trash/utils/trashfilehelper.cpp +++ b/src/plugins/filemanager/core/dfmplugin-trash/utils/trashfilehelper.cpp @@ -141,3 +141,14 @@ bool TrashFileHelper::disableOpenWidgetWidget(const QUrl &url, bool *result) return true; } + +bool TrashFileHelper::handleCanTag(const QUrl &url, bool *canTag) +{ + if (url.scheme() == scheme() || FileUtils::isTrashFile(url)) { + if (canTag) + *canTag = false; + return true; + } + + return false; +} diff --git a/src/plugins/filemanager/core/dfmplugin-trash/utils/trashfilehelper.h b/src/plugins/filemanager/core/dfmplugin-trash/utils/trashfilehelper.h index c67c2b7959..9f8d92a2d4 100644 --- a/src/plugins/filemanager/core/dfmplugin-trash/utils/trashfilehelper.h +++ b/src/plugins/filemanager/core/dfmplugin-trash/utils/trashfilehelper.h @@ -37,6 +37,7 @@ class TrashFileHelper : public QObject bool openFileInPlugin(quint64 windowId, const QList urls); bool blockPaste(quint64 winId, const QList &fromUrls, const QUrl &to); bool disableOpenWidgetWidget(const QUrl &url, bool *result); + bool handleCanTag(const QUrl &url, bool *canTag); private: explicit TrashFileHelper(QObject *parent = nullptr);