From 7592e048ce2cfd83c28a16321a37b0fbf4b27b4b Mon Sep 17 00:00:00 2001 From: kateleet Date: Sun, 26 Dec 2021 17:14:45 +0800 Subject: [PATCH] feat(short): support undo --- helper/shortcut.cpp | 2 ++ helper/shortcut.h | 1 + model/foldermodel.cpp | 7 +++++++ model/foldermodel.h | 1 + qml/Desktop/Main.qml | 3 +++ qml/FolderPage.qml | 3 +++ 6 files changed, 17 insertions(+) diff --git a/helper/shortcut.cpp b/helper/shortcut.cpp index 1ef47a7..c5ed6bb 100644 --- a/helper/shortcut.cpp +++ b/helper/shortcut.cpp @@ -73,6 +73,8 @@ bool ShortCut::eventFilter(QObject *obj, QEvent *e) emit refresh(); } else if (keyEvent->key() == Qt::Key_H && keyEvent->modifiers() & Qt::ControlModifier) { emit showHidden(); + } else if (keyEvent->key() == Qt::Key_Z && keyEvent->modifiers() & Qt::ControlModifier) { + emit undo(); } else if (keyEvent->key() >= Qt::Key_A && keyEvent->key() <= Qt::Key_Z) { // Handle select // KeyboardSearchManager::self()->addKeys(keyEvent->text()); diff --git a/helper/shortcut.h b/helper/shortcut.h index 2efb7d5..9d9dfbf 100644 --- a/helper/shortcut.h +++ b/helper/shortcut.h @@ -47,6 +47,7 @@ signals: void showHidden(); void keyPressed(const QString &text); void close(); + void undo(); protected: bool eventFilter(QObject *obj, QEvent *e) override; diff --git a/model/foldermodel.cpp b/model/foldermodel.cpp index f7e2644..b9522fb 100644 --- a/model/foldermodel.cpp +++ b/model/foldermodel.cpp @@ -729,6 +729,13 @@ void FolderModel::refresh() m_dirModel->dirLister()->updateDirectory(m_dirModel->dirLister()->url()); } +void FolderModel::undo() +{ + if (KIO::FileUndoManager::self()->undoAvailable()) { + KIO::FileUndoManager::self()->undo(); + } +} + bool FolderModel::supportSetAsWallpaper(const QString &mimeType) { if (mimeType == "image/jpeg" || mimeType == "image/png") diff --git a/model/foldermodel.h b/model/foldermodel.h index 13bd6b3..9e4817a 100644 --- a/model/foldermodel.h +++ b/model/foldermodel.h @@ -166,6 +166,7 @@ public: Q_INVOKABLE void goBack(); Q_INVOKABLE void goForward(); Q_INVOKABLE void refresh(); + Q_INVOKABLE void undo(); Q_INVOKABLE bool supportSetAsWallpaper(const QString &mimeType); Q_INVOKABLE int fileExtensionBoundary(int row); diff --git a/qml/Desktop/Main.qml b/qml/Desktop/Main.qml index 7d86be9..c3c4fc5 100644 --- a/qml/Desktop/Main.qml +++ b/qml/Desktop/Main.qml @@ -141,6 +141,9 @@ Item { onShowHidden: { dirModel.showHiddenFiles = !dirModel.showHiddenFiles } + onUndo: { + dirModel.undo() + } } Component { diff --git a/qml/FolderPage.qml b/qml/FolderPage.qml index 42f02a4..821d859 100644 --- a/qml/FolderPage.qml +++ b/qml/FolderPage.qml @@ -431,6 +431,9 @@ Item { onClose: { root.close() } + onUndo: { + dirModel.undo() + } } function openUrl(url) {