[pim/kmail] src: continue to implement undo/redo support
Laurent Montel <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit bff2d9c4013622a91989cf0cc9202f2fecb99686 by Laurent Montel.
Committed on 27/07/2026 at 11:23.
Pushed by mlaurent into branch 'master'.
continue to implement undo/redo support
M +19 -15 src/kmmainwidget.cpp
M +2 -1 src/kmmainwidget.h
M +5 -0 src/kmundoredomanager.cpp
M +1 -0 src/kmundoredomanager.h
https://invent.kde.org/pim/kmail/-/commit/bff2d9c4013622a91989cf0cc9202f2fecb99686
diff --git a/src/kmmainwidget.cpp b/src/kmmainwidget.cpp
index a6def3c56..45e5af087 100644
--- a/src/kmmainwidget.cpp
+++ b/src/kmmainwidget.cpp
@@ -2244,14 +2244,12 @@ void KMMainWidget::slotCcFilter()
//-----------------------------------------------------------------------------
void KMMainWidget::slotUndo()
{
- // TODO kmkernel->undoStack()->undo();
updateMessageActions();
updateFolderMenu();
}
void KMMainWidget::slotRedo()
{
- // TODO
updateMessageActions();
updateFolderMenu();
}
@@ -3571,16 +3569,13 @@ void KMMainWidget::setupActions()
connect(action, &QAction::triggered, this, &KMMainWidget::slotCreateAddressBookContact);
}
-#if 0 // TODO
QAction *undoAct = actionCollection()->addAction(QStringLiteral("kmail_undo"), KMKernel::self()->undoRedoManager()->undoStack()->createUndoAction(this));
+ actionCollection()->setDefaultShortcuts(undoAct, KStandardShortcut::undo());
connect(undoAct, &QAction::triggered, this, &KMMainWidget::slotUndo);
QAction *redoAct = actionCollection()->addAction(QStringLiteral("kmail_redo"), KMKernel::self()->undoRedoManager()->undoStack()->createRedoAction(this));
+ actionCollection()->setDefaultShortcuts(redoAct, KStandardShortcut::redo());
connect(redoAct, &QAction::triggered, this, &KMMainWidget::slotRedo);
-#endif
-
- QAction *act = actionCollection()->addAction(KStandardAction::Undo, QStringLiteral("kmail_undo"));
- connect(act, &QAction::triggered, this, &KMMainWidget::slotUndo);
mAccountSettings = new QAction(QIcon::fromTheme(QStringLiteral("configure")), i18n("Account &Settings"), this);
actionCollection()->addAction(QStringLiteral("resource_settings"), mAccountSettings);
@@ -3594,7 +3589,8 @@ void KMMainWidget::setupActions()
menutimer->setObjectName(QLatin1StringView("menutimer"));
menutimer->setSingleShot(true);
connect(menutimer, &QTimer::timeout, this, &KMMainWidget::updateMessageActionsDelayed);
- // TODO connect(kmkernel->undoStack(), &KMail::UndoStack::undoStackChanged, this, &KMMainWidget::slotUpdateUndo);
+ connect(kmkernel->undoRedoManager()->undoStack(), &QUndoStack::undoTextChanged, this, &KMMainWidget::slotUpdateUndoText);
+ connect(kmkernel->undoRedoManager()->undoStack(), &QUndoStack::redoTextChanged, this, &KMMainWidget::slotUpdateRedoText);
updateMessageActions();
updateFolderMenu();
@@ -4283,20 +4279,28 @@ QList<KActionCollection *> KMMainWidget::actionCollections() const
}
//-----------------------------------------------------------------------------
-void KMMainWidget::slotUpdateUndo()
+void KMMainWidget::slotUpdateUndoText(const QString &text)
{
-#if 0 // TODO
if (actionCollection()->action(QStringLiteral("kmail_undo"))) {
QAction *act = actionCollection()->action(QStringLiteral("kmail_undo"));
- act->setEnabled(!kmkernel->undoStack()->isEmpty());
- const QString infoStr = kmkernel->undoStack()->undoInfo();
- if (infoStr.isEmpty()) {
+ if (text.isEmpty()) {
act->setText(i18n("&Undo"));
} else {
- act->setText(i18n("&Undo: \"%1\"", kmkernel->undoStack()->undoInfo()));
+ act->setText(i18n("&Undo: \"%1\"", text));
+ }
+ }
+}
+
+void KMMainWidget::slotUpdateRedoText(const QString &text)
+{
+ if (actionCollection()->action(QStringLiteral("kmail_redo"))) {
+ QAction *act = actionCollection()->action(QStringLiteral("kmail_redo"));
+ if (text.isEmpty()) {
+ act->setText(i18n("&Redo"));
+ } else {
+ act->setText(i18n("&Redo: \"%1\"", text));
}
}
-#endif
}
//-----------------------------------------------------------------------------
diff --git a/src/kmmainwidget.h b/src/kmmainwidget.h
index a5ea096f9..bb8ba3145 100644
--- a/src/kmmainwidget.h
+++ b/src/kmmainwidget.h
@@ -434,7 +434,8 @@ private Q_SLOTS:
KMAIL_NO_EXPORT void slotNewFromTemplate(QAction *);
/** Update the undo action */
- KMAIL_NO_EXPORT void slotUpdateUndo();
+ KMAIL_NO_EXPORT void slotUpdateUndoText(const QString &text);
+ KMAIL_NO_EXPORT void slotUpdateRedoText(const QString &text);
/** Update html and threaded messages preferences in Folder menu. */
KMAIL_NO_EXPORT void updateFolderMenu();
diff --git a/src/kmundoredomanager.cpp b/src/kmundoredomanager.cpp
index d4bd7e648..a28a8ab70 100644
--- a/src/kmundoredomanager.cpp
+++ b/src/kmundoredomanager.cpp
@@ -116,3 +116,8 @@ void KMUndoInfoMoveItems::setMoveToTrash(bool newMoveToTrash)
{
mMoveToTrash = newMoveToTrash;
}
+
+QString KMUndoInfoMoveItems::actionText() const
+{
+ return i18n("Move messages");
+}
diff --git a/src/kmundoredomanager.h b/src/kmundoredomanager.h
index 758aa169e..05b368b51 100644
--- a/src/kmundoredomanager.h
+++ b/src/kmundoredomanager.h
@@ -38,6 +38,7 @@ public:
void undo() override;
void redo() override;
+ [[nodiscard]] QString actionText() const;
[[nodiscard]] Akonadi::Item::List items() const;
void setItems(const Akonadi::Item::List &newItems);