summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2024-03-17 17:49:25 +0500
committerMike Kaganski <mike.kaganski@collabora.com>2024-03-17 19:28:52 +0100
commit8cce20756857cc3c42a2f9393afe6886c4abc1ea (patch)
treebe92d674109bac6aacc090ed466ee2c4c95104dd
parent144dd13818581e8753c2b0a8707ffe047837f273 (diff)
Move undo info creation logic into ScUndoConditionalFormat
So it is near the code that applies the undo data. This makes it easier to synchronize the logic. Change-Id: If3d41ae6b0afafc81e149756cb327f1fca6f2bb0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164943 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
-rw-r--r--sc/source/ui/docshell/docfunc.cxx22
-rw-r--r--sc/source/ui/inc/undoblk.hxx8
-rw-r--r--sc/source/ui/undo/undoblk.cxx18
3 files changed, 24 insertions, 24 deletions
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx
index 153182419306..ec174d9c1248 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -5629,16 +5629,10 @@ void ScDocFunc::ReplaceConditionalFormat( sal_uLong nOldFormat, std::unique_ptr<
if(rDoc.IsTabProtected(nTab))
return;
- bool bUndo = rDoc.IsUndoEnabled();
- ScDocumentUniquePtr pUndoDoc;
ScRange aCombinedRange = rRanges.Combine();
- if(bUndo)
- {
- pUndoDoc.reset(new ScDocument(SCDOCMODE_UNDO));
- pUndoDoc->InitUndo( rDoc, nTab, nTab );
- if (const auto* pList = rDoc.GetCondFormList(nTab))
- pUndoDoc->SetCondFormList(new ScConditionalFormatList(*pUndoDoc, *pList), nTab);
- }
+ std::unique_ptr<ScUndoConditionalFormat> pUndo;
+ if (rDoc.IsUndoEnabled())
+ pUndo.reset(new ScUndoConditionalFormat(&rDocShell, nTab));
std::unique_ptr<ScRange> pRepaintRange;
if(nOldFormat)
@@ -5666,14 +5660,10 @@ void ScDocFunc::ReplaceConditionalFormat( sal_uLong nOldFormat, std::unique_ptr<
rDoc.SetStreamValid(nTab, false);
}
- if(bUndo)
+ if (pUndo)
{
- ScDocumentUniquePtr pRedoDoc(new ScDocument(SCDOCMODE_UNDO));
- pRedoDoc->InitUndo( rDoc, nTab, nTab );
- if (const auto* pList = rDoc.GetCondFormList(nTab))
- pRedoDoc->SetCondFormList(new ScConditionalFormatList(*pRedoDoc, *pList), nTab);
- rDocShell.GetUndoManager()->AddUndoAction(
- std::make_unique<ScUndoConditionalFormat>(&rDocShell, std::move(pUndoDoc), std::move(pRedoDoc), nTab));
+ pUndo->setRedoData();
+ rDocShell.GetUndoManager()->AddUndoAction(std::move(pUndo));
}
if(pRepaintRange)
diff --git a/sc/source/ui/inc/undoblk.hxx b/sc/source/ui/inc/undoblk.hxx
index d002b248d7ce..6a52ef059b0c 100644
--- a/sc/source/ui/inc/undoblk.hxx
+++ b/sc/source/ui/inc/undoblk.hxx
@@ -619,10 +619,11 @@ private:
class ScUndoConditionalFormat : public ScSimpleUndo
{
public:
- ScUndoConditionalFormat( ScDocShell* pNewDocShell,
- ScDocumentUniquePtr pUndoDoc, ScDocumentUniquePtr pRedoDoc, SCTAB nTab);
+ ScUndoConditionalFormat( ScDocShell* pNewDocShell, SCTAB nTab);
virtual ~ScUndoConditionalFormat() override;
+ void setRedoData() { mpRedoDoc = createUndoRedoData(); }
+
virtual void Undo() override;
virtual void Redo() override;
virtual void Repeat(SfxRepeatTarget& rTarget) override;
@@ -631,10 +632,11 @@ public:
virtual OUString GetComment() const override;
private:
+ ScDocumentUniquePtr createUndoRedoData();
void DoChange(ScDocument* pDoc);
+ SCTAB mnTab;
ScDocumentUniquePtr mpUndoDoc;
ScDocumentUniquePtr mpRedoDoc;
- SCTAB mnTab;
};
class ScUndoConditionalFormatList : public ScSimpleUndo
diff --git a/sc/source/ui/undo/undoblk.cxx b/sc/source/ui/undo/undoblk.cxx
index f07cfd88c46b..33fe76b5baaa 100644
--- a/sc/source/ui/undo/undoblk.cxx
+++ b/sc/source/ui/undo/undoblk.cxx
@@ -1605,12 +1605,10 @@ bool ScUndoListNames::CanRepeat(SfxRepeatTarget& rTarget) const
return dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr;
}
-ScUndoConditionalFormat::ScUndoConditionalFormat(ScDocShell* pNewDocShell,
- ScDocumentUniquePtr pUndoDoc, ScDocumentUniquePtr pRedoDoc, SCTAB nTab):
+ScUndoConditionalFormat::ScUndoConditionalFormat(ScDocShell* pNewDocShell, SCTAB nTab):
ScSimpleUndo( pNewDocShell ),
- mpUndoDoc(std::move(pUndoDoc)),
- mpRedoDoc(std::move(pRedoDoc)),
- mnTab(nTab)
+ mnTab(nTab),
+ mpUndoDoc(createUndoRedoData())
{
}
@@ -1618,6 +1616,16 @@ ScUndoConditionalFormat::~ScUndoConditionalFormat()
{
}
+ScDocumentUniquePtr ScUndoConditionalFormat::createUndoRedoData()
+{
+ ScDocument& rDoc = pDocShell->GetDocument();
+ ScDocumentUniquePtr pUndoRedoDoc(new ScDocument(SCDOCMODE_UNDO));
+ pUndoRedoDoc->InitUndo(rDoc, mnTab, mnTab);
+ if (const auto* pList = rDoc.GetCondFormList(mnTab))
+ pUndoRedoDoc->SetCondFormList(new ScConditionalFormatList(*pUndoRedoDoc, *pList), mnTab);
+ return pUndoRedoDoc;
+}
+
OUString ScUndoConditionalFormat::GetComment() const
{
return ScResId( STR_UNDO_CONDFORMAT );