Commit 8b703d00 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇
Browse files

[Notifications] Add "Move to Trash" and "Delete" actions to file menu

So one can, for instance, quickly delete an unwanted screenshot.
It follows the usual Trash context menu actions, i.e. move to trash is only
shown for local files and locations that support moving, Delete is shown for
remote locations or when enabled in settings.

Swapping of the action when holding Shift is not implemented.

BUG: 428159
FIXED-IN: 5.21.0
parent f93d2b55
......@@ -14,6 +14,7 @@ kcoreaddons_desktop_to_json(plasma_applet_notifications package/metadata.desktop
target_link_libraries(plasma_applet_notifications
Qt5::Gui
Qt5::Quick # for QQmlParserStatus
KF5::ConfigWidgets # for KStandardAction
KF5::I18n
KF5::Plasma
KF5::PlasmaQuick
......
......@@ -27,13 +27,20 @@
#include <QTimer>
#include <QQuickWindow>
#include <KConfigGroup>
#include <KFileItemActions>
#include <KFileItemListProperties>
#include <KLocalizedString>
#include <KProtocolManager>
#include <KPropertiesDialog>
#include <KSharedConfig>
#include <KStandardAction>
#include <KUrlMimeData>
#include <KIO/CopyJob> // for KIO::trash
#include <KIO/DeleteJob>
#include <KIO/FileUndoManager>
#include <KIO/JobUiDelegate>
#include <KIO/OpenFileManagerWindowJob>
FileMenu::FileMenu(QObject *parent) : QObject(parent)
......@@ -138,6 +145,44 @@ void FileMenu::open(int x, int y)
QApplication::clipboard()->setMimeData(data);
});
menu->addSeparator();
const bool canTrash = itemProperties.isLocal() && itemProperties.supportsMoving();
if (canTrash) {
QAction *moveToTrashAction = KStandardAction::moveToTrash(this, [this] {
const QList<QUrl> urls{m_url};
KIO::JobUiDelegate uiDelegate;
if (uiDelegate.askDeleteConfirmation(urls, KIO::JobUiDelegate::Trash, KIO::JobUiDelegate::DefaultConfirmation)) {
auto *job = KIO::trash(urls);
job->uiDelegate()->setAutoErrorHandlingEnabled(true);
KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Trash, urls,
QUrl(QStringLiteral("trash:/")), job);
}
}, menu);
moveToTrashAction->setShortcut({}); // Can't focus notification to press Delete
menu->addAction(moveToTrashAction);
}
KConfigGroup cg(KSharedConfig::openConfig(), "KDE");
const bool showDeleteCommand = cg.readEntry("ShowDeleteCommand", false);
if (itemProperties.supportsDeleting() && (!canTrash || showDeleteCommand)) {
QAction *deleteAction = KStandardAction::deleteFile(this, [this] {
const QList<QUrl> urls{m_url};
KIO::JobUiDelegate uiDelegate;
if (uiDelegate.askDeleteConfirmation(urls, KIO::JobUiDelegate::Delete, KIO::JobUiDelegate::DefaultConfirmation)) {
auto *job = KIO::del(urls);
job->uiDelegate()->setAutoErrorHandlingEnabled(true);
}
}, menu);
deleteAction->setShortcut({});
menu->addAction(deleteAction);
}
menu->addSeparator();
actions->addServiceActionsTo(menu);
actions->addPluginActionsTo(menu);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment