summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sw/inc/doc.hxx2
-rw-r--r--sw/source/core/doc/doc.cxx14
-rw-r--r--sw/source/core/inc/SwUndoTOXChange.hxx10
-rw-r--r--sw/source/core/undo/SwUndoTOXChange.cxx56
-rw-r--r--sw/source/uibase/index/toxmgr.cxx2
5 files changed, 46 insertions, 38 deletions
diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index fd8ab6c58fdd..1e78ee0aea40 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -1559,7 +1559,7 @@ public:
bool bBroadcast = false);
// Change a TOX undoable.
- void ChangeTOX(SwTOXBase & rTOX, const SwTOXBase & rNew, SwRootFrame const& rLayout);
+ void ChangeTOX(SwTOXBase & rTOX, const SwTOXBase & rNew);
/**
Returns a textual description of a PaM.
diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx
index cee2e7745278..2da307cfd267 100644
--- a/sw/source/core/doc/doc.cxx
+++ b/sw/source/core/doc/doc.cxx
@@ -1728,22 +1728,20 @@ void SwDoc::AppendUndoForInsertFromDB( const SwPaM& rPam, bool bIsTable )
}
}
-void SwDoc::ChangeTOX(SwTOXBase & rTOX, const SwTOXBase & rNew,
- SwRootFrame const& rLayout)
+void SwDoc::ChangeTOX(SwTOXBase & rTOX, const SwTOXBase & rNew)
{
+ assert(dynamic_cast<const SwTOXBaseSection*>(&rTOX));
+ SwTOXBaseSection& rTOXSect(static_cast<SwTOXBaseSection&>(rTOX));
+
if (GetIDocumentUndoRedo().DoesUndo())
{
GetIDocumentUndoRedo().AppendUndo(
- std::make_unique<SwUndoTOXChange>(this, &rTOX, rNew));
+ std::make_unique<SwUndoTOXChange>(this, rTOXSect, rNew));
}
rTOX = rNew;
- if (dynamic_cast<const SwTOXBaseSection*>( &rTOX) != nullptr)
- {
- static_cast<SwTOXBaseSection &>(rTOX).Update(nullptr, &rLayout);
- static_cast<SwTOXBaseSection &>(rTOX).UpdatePageNum();
- }
+ // note: do not Update the ToX here - the caller will do it, with a ViewShell!
}
OUString SwDoc::GetPaMDescr(const SwPaM & rPam)
diff --git a/sw/source/core/inc/SwUndoTOXChange.hxx b/sw/source/core/inc/SwUndoTOXChange.hxx
index d78b17e9b8bb..a593bfd6da0a 100644
--- a/sw/source/core/inc/SwUndoTOXChange.hxx
+++ b/sw/source/core/inc/SwUndoTOXChange.hxx
@@ -24,16 +24,18 @@
#include <tox.hxx>
class SwDoc;
+class SwTOXBaseSection;
class SwUndoTOXChange : public SwUndo
{
- SwTOXBase * pTOX, aOld, aNew;
+private:
+ SwTOXBase m_Old;
+ SwTOXBase m_New;
- void UpdateTOXBaseSection();
- void DoImpl();
+ sal_uLong const m_nNodeIndex;
public:
- SwUndoTOXChange(const SwDoc* pDoc, SwTOXBase * pTOX, const SwTOXBase & rNew);
+ SwUndoTOXChange(const SwDoc* pDoc, SwTOXBaseSection const& rTOX, const SwTOXBase & rNew);
virtual ~SwUndoTOXChange() override;
virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
diff --git a/sw/source/core/undo/SwUndoTOXChange.cxx b/sw/source/core/undo/SwUndoTOXChange.cxx
index 5b69ab91abe0..4296aa23d35f 100644
--- a/sw/source/core/undo/SwUndoTOXChange.cxx
+++ b/sw/source/core/undo/SwUndoTOXChange.cxx
@@ -19,10 +19,17 @@
#include <SwUndoTOXChange.hxx>
#include <swundo.hxx>
+#include <UndoCore.hxx>
#include <doctxm.hxx>
+#include <doc.hxx>
+#include <node.hxx>
-SwUndoTOXChange::SwUndoTOXChange(const SwDoc *pDoc, SwTOXBase * _pTOX, const SwTOXBase & rNew)
- : SwUndo(SwUndoId::TOXCHANGE, pDoc), pTOX(_pTOX), aOld(*_pTOX), aNew(rNew)
+SwUndoTOXChange::SwUndoTOXChange(const SwDoc *pDoc,
+ SwTOXBaseSection const& rTOX, SwTOXBase const& rNew)
+ : SwUndo(SwUndoId::TOXCHANGE, pDoc)
+ , m_Old(rTOX)
+ , m_New(rNew)
+ , m_nNodeIndex(rTOX.GetFormat()->GetSectionNode()->GetIndex())
{
}
@@ -30,38 +37,39 @@ SwUndoTOXChange::~SwUndoTOXChange()
{
}
-void SwUndoTOXChange::UpdateTOXBaseSection()
+// get the current ToXBase, which is not necessarily the same instance that existed there before
+static SwTOXBase & GetTOX(SwDoc & rDoc, sal_uLong const nNodeIndex)
{
- if ( dynamic_cast< const SwTOXBaseSection *>( pTOX ) != nullptr )
- {
- SwTOXBaseSection * pTOXBase = static_cast<SwTOXBaseSection *>(pTOX);
- pTOXBase->Update();
- pTOXBase->UpdatePageNum();
- }
+ SwSectionNode *const pNode(rDoc.GetNodes()[nNodeIndex]->GetSectionNode());
+ assert(pNode);
+ assert(dynamic_cast<SwTOXBaseSection*>(&pNode->GetSection()));
+ auto & rTOX(static_cast<SwTOXBaseSection&>(pNode->GetSection()));
+ return rTOX;
}
-void SwUndoTOXChange::UndoImpl(::sw::UndoRedoContext &)
+void SwUndoTOXChange::UndoImpl(::sw::UndoRedoContext & rContext)
{
- *pTOX = aOld;
-
- UpdateTOXBaseSection();
+ SwDoc & rDoc(rContext.GetDoc());
+ SwTOXBase & rTOX(GetTOX(rDoc, m_nNodeIndex));
+ rTOX = m_Old;
}
-void SwUndoTOXChange::DoImpl()
+void SwUndoTOXChange::RedoImpl(::sw::UndoRedoContext & rContext)
{
- *pTOX = aNew;
-
- UpdateTOXBaseSection();
+ SwDoc & rDoc(rContext.GetDoc());
+ SwTOXBase & rTOX(GetTOX(rDoc, m_nNodeIndex));
+ rTOX = m_New;
}
-void SwUndoTOXChange::RedoImpl(::sw::UndoRedoContext &)
+void SwUndoTOXChange::RepeatImpl(::sw::RepeatContext & rContext)
{
- DoImpl();
-}
-
-void SwUndoTOXChange::RepeatImpl(::sw::RepeatContext &)
-{
- DoImpl();
+ SwDoc & rDoc(rContext.GetDoc());
+ SwTOXBase *const pTOX(SwDoc::GetCurTOX(*rContext.GetRepeatPaM().GetPoint()));
+ if (pTOX)
+ {
+ rDoc.ChangeTOX(*pTOX, m_New);
+ // intentionally limited to not Update because we'd need layout
+ }
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/index/toxmgr.cxx b/sw/source/uibase/index/toxmgr.cxx
index d2ed262f00b2..0c594c51e0cc 100644
--- a/sw/source/uibase/index/toxmgr.cxx
+++ b/sw/source/uibase/index/toxmgr.cxx
@@ -439,7 +439,7 @@ bool SwTOXMgr::UpdateOrInsertTOX(const SwTOXDescription& rDesc,
pDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::TOXCHANGE, nullptr);
}
- pDoc->ChangeTOX(*pTOX, *pNewTOX, *pSh->GetLayout());
+ pDoc->ChangeTOX(*pTOX, *pNewTOX);
pTOX->DisableKeepExpression();
pSh->UpdateTableOf(*pTOX, pSet);