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 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'src/dolphinmainwindow.cpp') 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()); -- cgit v1.3