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

fix: Open multiple trash windows, window A enters the trash folder, window B deletes or restores the folder, window A returns to the computer path #2266

Merged
merged 1 commit into from
Sep 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
1 change: 1 addition & 0 deletions src/dfm-base/utils/fileutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ QUrl FileUtils::trashRootUrl()
QUrl url;
url.setScheme(DFMBASE_NAMESPACE::Global::Scheme::kTrash);
url.setPath("/");
url.setHost("");
return url;
}

Expand Down
1 change: 1 addition & 0 deletions src/plugins/filemanager/core/dfmplugin-trash/trash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ void Trash::followEvents()
dpfHookSequence->follow("dfmplugin_workspace", "hook_Model_FetchCustomColumnRoles", TrashHelper::instance(), &TrashHelper::customColumnRole);
dpfHookSequence->follow("dfmplugin_workspace", "hook_Model_FetchCustomRoleDisplayName", TrashHelper::instance(), &TrashHelper::customRoleDisplayName);
dpfHookSequence->follow("dfmplugin_workspace", "hook_ShortCut_PasteFiles", TrashFileHelper::instance(), &TrashFileHelper::blockPaste);
dpfHookSequence->follow("dfmplugin_workspace", "hook_Tab_FileDeleteNotCdComputer", TrashFileHelper::instance(), &TrashFileHelper::handleNotCdComputer);

// hook events, file operation
dpfHookSequence->follow("dfmplugin_fileoperations", "hook_Operation_CutToFile", TrashFileHelper::instance(), &TrashFileHelper::cutFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,16 @@

return sub.path().contains(parent.path());
}

bool TrashFileHelper::handleNotCdComputer(const QUrl &url, QUrl *cdUrl)

Check warning on line 169 in src/plugins/filemanager/core/dfmplugin-trash/utils/trashfilehelper.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'handleNotCdComputer' is never used.

Check warning on line 169 in src/plugins/filemanager/core/dfmplugin-trash/utils/trashfilehelper.cpp

View workflow job for this annotation

GitHub Actions / static-check / Call-CppCheck

The function 'handleNotCdComputer' is never used.
{
if (url.scheme() != scheme())
return false;

if (!cdUrl)
return false;

// 回收站中只能最上层目录可以删除和还原,那么它们的父目录都是回收站
*cdUrl = FileUtils::trashRootUrl();
return true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ class TrashFileHelper : public QObject
bool disableOpenWidgetWidget(const QUrl &url, bool *result);
bool handleCanTag(const QUrl &url, bool *canTag);
bool handleIsSubFile(const QUrl &parent, const QUrl &sub);
bool handleNotCdComputer(const QUrl &url, QUrl *cdUrl);

private:
explicit TrashFileHelper(QObject *parent = nullptr);
};
DPTRASH_END_NAMESPACE

Q_DECLARE_METATYPE(QUrl *);
#endif // TRASHFILEHELPER_H
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,12 @@ void TabBar::closeTab(quint64 winId, const QUrl &url)
if (closeable || DFMBASE_NAMESPACE::UniversalUtils::urlEquals(curUrl, url) || url.isParentOf(curUrl)) {
if (count() == 1) {
QUrl redirectToWhenDelete;
if (isMountedDevPath(url) || url.scheme() != Global::Scheme::kFile) {
if (isMountedDevPath(url)) {
redirectToWhenDelete = kGotoWhenDevRemoved;
} else { // redirect to upper directory
} else if (dpfHookSequence->run("dfmplugin_workspace", "hook_Tab_FileDeleteNotCdComputer", curUrl, &redirectToWhenDelete)) {
if (!redirectToWhenDelete.isValid())
redirectToWhenDelete = kGotoWhenDevRemoved;
} else if (url.scheme() == Global::Scheme::kFile){ // redirect to upper directory
QString localPath = url.path();
do {
QStringList pathFragment = localPath.split("/");
Expand Down Expand Up @@ -225,6 +228,8 @@ void TabBar::closeTab(quint64 winId, const QUrl &url)
if (kGvfsMpts.contains(localPath))
redirectToWhenDelete = kGotoWhenDevRemoved;
}
} else {
redirectToWhenDelete = kGotoWhenDevRemoved;
}

dpfSignalDispatcher->publish(GlobalEventType::kChangeCurrentUrl, winId, redirectToWhenDelete);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,6 @@ protected slots:

}

Q_DECLARE_METATYPE(QUrl*);

#endif // TABBAR_H
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class Workspace : public dpf::Plugin
DPF_EVENT_REG_HOOK(hook_Tab_SetTabName)
DPF_EVENT_REG_HOOK(hook_Tab_Closeable)
DPF_EVENT_REG_HOOK(hook_Tab_Allow_Repeat_Url)
DPF_EVENT_REG_HOOK(hook_Tab_FileDeleteNotCdComputer)

DPF_EVENT_REG_HOOK(hook_DragDrop_CheckDragDropAction)
DPF_EVENT_REG_HOOK(hook_DragDrop_FileDragMove)
Expand Down
Loading