┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGleb Kasachou <[email protected]>2025-09-07 13:24:28 +0300
committerMéven Car <[email protected]>2025-09-07 10:24:28 +0000
commitbfa9c13cb24da62bea8d45f9f99a884a50a039a3 (patch)
treee6e416358149fc2ea97578d426182df1ae7361ea /src
parent5d66b4f5ecce950cd6f643fa27463b733bfc5c66 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/dolphinmainwindow.cpp47
-rw-r--r--src/dolphinmainwindow.h14
-rw-r--r--src/dolphinui.rc4
-rw-r--r--src/dolphinuiforphones.rc4
4 files changed, 63 insertions, 6 deletions
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.<nl/>"
+ "Such changes include <interface>creating</interface>, <interface>renaming</interface> "
+ "and <interface>moving</interface> files or folders to a different location "
+ "or to the <filename>Trash</filename>.<nl/>Any changes that cannot be undone "
+ "will ask for your confirmation beforehand."));
+ redoAction->setEnabled(false); // redo should be disabled by default
+#endif
+
{
QScopedPointer<QAction> 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 @@
<?xml version="1.0"?>
<!DOCTYPE gui SYSTEM "kpartgui.dtd">
-<gui name="dolphin" version="47">
+<gui name="dolphin" version="48">
<MenuBar>
<Menu name="file">
<Action name="new_menu" />
@@ -21,8 +21,6 @@
<Action name="properties" />
</Menu>
<Menu name="edit">
- <Action name="edit_undo" />
- <Separator />
<Action name="edit_cut" />
<Action name="edit_copy" />
<Action name="copy_location" />
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 @@
<?xml version="1.0"?>
<!DOCTYPE gui SYSTEM "kpartgui.dtd">
-<gui name="dolphin" version="4">
+<gui name="dolphin" version="5">
<MenuBar>
<Menu name="file">
<Action name="new_menu" />
@@ -21,8 +21,6 @@
<Action name="properties" />
</Menu>
<Menu name="edit">
- <Action name="edit_undo" />
- <Separator />
<Action name="edit_cut" />
<Action name="edit_copy" />
<Action name="copy_location" />