From bfa9c13cb24da62bea8d45f9f99a884a50a039a3 Mon Sep 17 00:00:00 2001 From: Gleb Kasachou Date: Sun, 7 Sep 2025 13:24:28 +0300 Subject: Add support for Redo operations This MR updates Dolphin to support redo functionality added in KIO's FileUndoManager. It enables triggering redo operations from the user interface and ensures appropriate integration with the undo/redo command flow. Require: [!1941](https://invent.kde.org/frameworks/kio/-/merge_requests/1941) BUG: 451746 --- src/dolphinmainwindow.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/dolphinmainwindow.h | 14 ++++++++++++++ src/dolphinui.rc | 4 +--- src/dolphinuiforphones.rc | 4 +--- 4 files changed, 63 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 917aa42ce..f7ca69553 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -156,6 +156,10 @@ DolphinMainWindow::DolphinMainWindow() connect(undoManager, &KIO::FileUndoManager::undoAvailable, this, &DolphinMainWindow::slotUndoAvailable); connect(undoManager, &KIO::FileUndoManager::undoTextChanged, this, &DolphinMainWindow::slotUndoTextChanged); +#if KIO_VERSION >= QT_VERSION_CHECK(6, 17, 0) + connect(undoManager, &KIO::FileUndoManager::redoAvailable, this, &DolphinMainWindow::slotRedoAvailable); + connect(undoManager, &KIO::FileUndoManager::redoTextChanged, this, &DolphinMainWindow::slotRedoTextChanged); +#endif connect(undoManager, &KIO::FileUndoManager::jobRecordingStarted, this, &DolphinMainWindow::clearStatusBar); connect(undoManager, &KIO::FileUndoManager::jobRecordingFinished, this, &DolphinMainWindow::showCommand); @@ -891,6 +895,31 @@ void DolphinMainWindow::undo() KIO::FileUndoManager::self()->undo(); } +#if KIO_VERSION >= QT_VERSION_CHECK(6, 17, 0) +void DolphinMainWindow::slotRedoAvailable(bool available) +{ + QAction *redoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Redo)); + if (redoAction) { + redoAction->setEnabled(available); + } +} + +void DolphinMainWindow::slotRedoTextChanged(const QString &text) +{ + QAction *redoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Redo)); + if (redoAction) { + redoAction->setText(text); + } +} + +void DolphinMainWindow::redo() +{ + clearStatusBar(); + KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this); + KIO::FileUndoManager::self()->redo(); +} +#endif + void DolphinMainWindow::cut() { if (m_activeViewContainer->view()->selectedItems().isEmpty()) { @@ -1554,6 +1583,9 @@ void DolphinMainWindow::updateHamburgerMenu() } menu->addAction(ac->action(QStringLiteral("basic_actions"))); menu->addAction(ac->action(KStandardAction::name(KStandardAction::Undo))); +#if KIO_VERSION >= QT_VERSION_CHECK(6, 17, 0) + menu->addAction(ac->action(KStandardAction::name(KStandardAction::Redo))); +#endif if (!toolBar()->isVisible() || (!toolbarActions.contains(ac->action(QStringLiteral("toggle_search"))) && !toolbarActions.contains(ac->action(QStringLiteral("open_preferred_search_tool"))))) { @@ -1813,6 +1845,9 @@ void DolphinMainWindow::setupActions() // setup 'Edit' menu KStandardAction::undo(this, &DolphinMainWindow::undo, actionCollection()); +#if KIO_VERSION >= QT_VERSION_CHECK(6, 17, 0) + KStandardAction::redo(this, &DolphinMainWindow::redo, actionCollection()); +#endif // i18n: This will be the last paragraph for the whatsthis for all three: // Cut, Copy and Paste @@ -2094,6 +2129,18 @@ void DolphinMainWindow::setupActions() "will ask for your confirmation beforehand.")); undoAction->setEnabled(false); // undo should be disabled by default +#if KIO_VERSION >= QT_VERSION_CHECK(6, 17, 0) + auto redoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Redo)); + redoAction->setWhatsThis(xi18nc("@info:whatsthis", + "This redoes " + "the last change you undid." + "Such changes include creating, renaming " + "and moving files or folders to a different location " + "or to the Trash.Any changes that cannot be undone " + "will ask for your confirmation beforehand.")); + redoAction->setEnabled(false); // redo should be disabled by default +#endif + { QScopedPointer forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr)); m_forwardAction = new KToolBarPopupAction(forwardAction->icon(), forwardAction->text(), actionCollection()); diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index 4952085f0..2c8d444ad 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -314,6 +314,20 @@ private Q_SLOTS: /** Performs the current undo operation. */ void undo(); +#if KIO_VERSION >= QT_VERSION_CHECK(6, 17, 0) + /** + * Updates the state of the 'Redo' menu action dependent + * on the parameter \a available. + */ + void slotRedoAvailable(bool available); + + /** Sets the text of the 'Redo' menu action to \a text. */ + void slotRedoTextChanged(const QString &text); + + /** Performs the current redo operation. */ + void redo(); +#endif + /** * Copies all selected items to the clipboard and marks * the items as cut. diff --git a/src/dolphinui.rc b/src/dolphinui.rc index 6bac6a193..93666b6bb 100644 --- a/src/dolphinui.rc +++ b/src/dolphinui.rc @@ -1,6 +1,6 @@ - + @@ -21,8 +21,6 @@ - - diff --git a/src/dolphinuiforphones.rc b/src/dolphinuiforphones.rc index 7e9d72c8e..b2a9fc6fe 100644 --- a/src/dolphinuiforphones.rc +++ b/src/dolphinuiforphones.rc @@ -1,6 +1,6 @@ - + @@ -21,8 +21,6 @@ - - -- cgit v1.3