summaryrefslogtreecommitdiff
path: root/svl
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2024-02-29 17:03:31 +0600
committerMiklos Vajna <vmiklos@collabora.com>2024-03-18 14:34:28 +0100
commit62cda8b744caaa49a831b3a8a35734bb019886c2 (patch)
tree7d998b59a8973bf66e7df9991c68886f13f9bfdf /svl
parentfa93750070793cd548d028feb39e4d0e0e61ae5a (diff)
cool#8443 let Insert Chart dialog to undo out of order on Cancel
Change-Id: I66d749362c9fb5f2c228f0f5d2c927cc0cf3f89f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164179 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164834 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'svl')
-rw-r--r--svl/source/undo/undo.cxx40
1 files changed, 36 insertions, 4 deletions
diff --git a/svl/source/undo/undo.cxx b/svl/source/undo/undo.cxx
index 9b90495d593a..96c937c037ad 100644
--- a/svl/source/undo/undo.cxx
+++ b/svl/source/undo/undo.cxx
@@ -34,6 +34,26 @@
#include <limits.h>
#include <algorithm>
+namespace
+{
+class SfxMarkedUndoContext final : public SfxUndoContext
+{
+public:
+ SfxMarkedUndoContext(SfxUndoManager& manager, UndoStackMark mark)
+ {
+ m_offset = manager.RemoveMark(mark);
+ size_t count = manager.GetUndoActionCount();
+ if (m_offset < count)
+ m_offset = count - m_offset - 1;
+ else
+ m_offset = std::numeric_limits<size_t>::max();
+ }
+ size_t GetUndoOffset() override { return m_offset; }
+
+private:
+ size_t m_offset;
+};
+}
SfxRepeatTarget::~SfxRepeatTarget()
{
@@ -1086,18 +1106,18 @@ UndoStackMark SfxUndoManager::MarkTopUndoAction()
return m_xData->mnMarks;
}
-void SfxUndoManager::RemoveMark( UndoStackMark const i_mark )
+size_t SfxUndoManager::RemoveMark(UndoStackMark i_mark)
{
UndoManagerGuard aGuard( *m_xData );
if ((m_xData->mnEmptyMark < i_mark) || (MARK_INVALID == i_mark))
{
- return; // nothing to remove
+ return std::numeric_limits<size_t>::max(); // nothing to remove
}
else if (i_mark == m_xData->mnEmptyMark)
{
--m_xData->mnEmptyMark; // never returned from MarkTop => invalid
- return;
+ return std::numeric_limits<size_t>::max();
}
for ( size_t i=0; i<m_xData->maUndoArray.maUndoActions.size(); ++i )
@@ -1107,13 +1127,15 @@ void SfxUndoManager::RemoveMark( UndoStackMark const i_mark )
if (markPos != rAction.aMarks.end())
{
rAction.aMarks.erase( markPos );
- return;
+ return i;
}
}
SAL_WARN("svl", "SfxUndoManager::RemoveMark: mark not found!");
// TODO: this might be too offensive. There are situations where we implicitly remove marks
// without our clients, in particular the client which created the mark, having a chance to know
// about this.
+
+ return std::numeric_limits<size_t>::max();
}
bool SfxUndoManager::HasTopUndoActionMark( UndoStackMark const i_mark )
@@ -1133,6 +1155,16 @@ bool SfxUndoManager::HasTopUndoActionMark( UndoStackMark const i_mark )
}
+void SfxUndoManager::UndoMark(UndoStackMark i_mark)
+{
+ SfxMarkedUndoContext context(*this, i_mark); // Removes the mark
+ if (context.GetUndoOffset() == std::numeric_limits<size_t>::max())
+ return; // nothing to undo
+
+ UndoWithContext(context);
+}
+
+
void SfxUndoManager::RemoveOldestUndoAction()
{
UndoManagerGuard aGuard( *m_xData );