diff options
author | Michael Stahl <michael.stahl@allotropia.de> | 2021-08-26 17:09:22 +0200 |
---|---|---|
committer | Michael Stahl <michael.stahl@allotropia.de> | 2021-08-27 17:09:13 +0200 |
commit | 3608de9a3647294361c64b923b1ae413ad9755df (patch) | |
tree | df3edfd1de702a039dd0be258ae959dd3e0f5551 /sw | |
parent | e4a3c4ba511724bcc8997249a921da609345410b (diff) |
tdf#128106 sw: copy bookmarks in SwDoc::SplitDoc()
Change-Id: Id35b8771b456b162ca653423d02788275a79443f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121146
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/uiwriter/data/cross_reference_demo_bmk.odt | bin | 0 -> 8443 bytes | |||
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter3.cxx | 73 | ||||
-rw-r--r-- | sw/source/core/doc/docglbl.cxx | 9 |
3 files changed, 75 insertions, 7 deletions
diff --git a/sw/qa/extras/uiwriter/data/cross_reference_demo_bmk.odt b/sw/qa/extras/uiwriter/data/cross_reference_demo_bmk.odt Binary files differnew file mode 100644 index 000000000000..df8d95f912c4 --- /dev/null +++ b/sw/qa/extras/uiwriter/data/cross_reference_demo_bmk.odt diff --git a/sw/qa/extras/uiwriter/uiwriter3.cxx b/sw/qa/extras/uiwriter/uiwriter3.cxx index 72b715051cce..64e3c8fb61cb 100644 --- a/sw/qa/extras/uiwriter/uiwriter3.cxx +++ b/sw/qa/extras/uiwriter/uiwriter3.cxx @@ -28,6 +28,7 @@ #include <o3tl/safeint.hxx> #include <tools/json_writer.hxx> #include <unotools/streamwrap.hxx> +#include <sfx2/linkmgr.hxx> #include <fmtinfmt.hxx> #include <view.hxx> @@ -38,6 +39,9 @@ #include <dcontact.hxx> #include <svx/svdpage.hxx> #include <ndtxt.hxx> +#include <txtfld.hxx> +#include <IDocumentFieldsAccess.hxx> +#include <IDocumentLinksAdministration.hxx> #include <IDocumentRedlineAccess.hxx> namespace @@ -2615,6 +2619,75 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf136740) CPPUNIT_ASSERT_EQUAL(aNewCorrected, xTextDefaults->getPropertyValue("TabStopDistance")); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf128106) +{ + SwWrtShell* pWrtShell + = createSwDoc(DATA_DIRECTORY, "cross_reference_demo_bmk.odt")->GetDocShell()->GetWrtShell(); + + utl::TempFile tempDir(nullptr, true); + + const auto aPropertyValues = comphelper::InitPropertySequence( + { { "FileName", css::uno::Any(tempDir.GetURL() + "/test.odm") } }); + dispatchCommand(mxComponent, ".uno:NewGlobalDoc", aPropertyValues); + + // new document now! + mxComponent.set(pWrtShell->GetDoc()->GetDocShell()->GetModel()); + CPPUNIT_ASSERT(mxComponent.is()); + + SwDoc* const pMasterDoc(pWrtShell->GetDoc()); + CPPUNIT_ASSERT_EQUAL( + size_t(2), + pMasterDoc->getIDocumentLinksAdministration().GetLinkManager().GetLinks().size()); + // no way to set SwDocShell::m_nUpdateDocMode away from NO_UPDATE ? + // pMasterDoc->getIDocumentLinksAdministration().UpdateLinks(); + pMasterDoc->getIDocumentLinksAdministration().GetLinkManager().UpdateAllLinks(false, false, + nullptr); + // note: this has called SwGetRefFieldType::UpdateGetReferences() + SwFieldType const* const pType( + pMasterDoc->getIDocumentFieldsAccess().GetSysFieldType(SwFieldIds::GetRef)); + std::vector<SwFormatField*> fields; + pType->GatherFields(fields); + CPPUNIT_ASSERT_EQUAL(size_t(6), fields.size()); + std::sort(fields.begin(), fields.end(), [](auto const* const pA, auto const* const pB) { + SwTextField const* const pHintA(pA->GetTextField()); + SwTextField const* const pHintB(pB->GetTextField()); + // in this document: only 1 field per node + CPPUNIT_ASSERT(pA == pB || &pHintA->GetTextNode() != &pHintB->GetTextNode()); + return pHintA->GetTextNode().GetIndex() < pHintB->GetTextNode().GetIndex(); + }); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_BOOKMARK), fields[0]->GetField()->GetSubType()); + CPPUNIT_ASSERT_EQUAL(OUString("bookmarkchapter1_text"), + static_cast<SwGetRefField const*>(fields[0]->GetField())->GetSetRefName()); + CPPUNIT_ASSERT_EQUAL(OUString("Text"), + static_cast<SwGetRefField const*>(fields[0]->GetField()) + ->GetExpandedTextOfReferencedTextNode(*pWrtShell->GetLayout())); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_BOOKMARK), fields[1]->GetField()->GetSubType()); + CPPUNIT_ASSERT( + static_cast<SwGetRefField const*>(fields[1]->GetField())->IsRefToHeadingCrossRefBookmark()); + // CPPUNIT_ASSERT_EQUAL(OUString("Chapter 2"), static_cast<SwGetRefField const*>(fields[1]->GetField())->GetPar2()); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_BOOKMARK), fields[2]->GetField()->GetSubType()); + CPPUNIT_ASSERT_EQUAL(OUString("Bookmarkchapter1"), + static_cast<SwGetRefField const*>(fields[2]->GetField())->GetSetRefName()); + CPPUNIT_ASSERT_EQUAL(OUString("Chapter 1"), + static_cast<SwGetRefField const*>(fields[2]->GetField())->GetPar2()); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_BOOKMARK), fields[3]->GetField()->GetSubType()); + CPPUNIT_ASSERT_EQUAL(OUString("bookmarkchapter1_text"), + static_cast<SwGetRefField const*>(fields[3]->GetField())->GetSetRefName()); + CPPUNIT_ASSERT_EQUAL(OUString("Text"), + static_cast<SwGetRefField const*>(fields[3]->GetField())->GetPar2()); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_BOOKMARK), fields[4]->GetField()->GetSubType()); + CPPUNIT_ASSERT( + static_cast<SwGetRefField const*>(fields[4]->GetField())->IsRefToHeadingCrossRefBookmark()); + CPPUNIT_ASSERT_EQUAL(OUString("Chapter 1.1"), + static_cast<SwGetRefField const*>(fields[4]->GetField())->GetPar2()); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_BOOKMARK), fields[5]->GetField()->GetSubType()); + CPPUNIT_ASSERT( + static_cast<SwGetRefField const*>(fields[5]->GetField())->IsRefToHeadingCrossRefBookmark()); + // CPPUNIT_ASSERT_EQUAL(OUString("Chapter 2"), static_cast<SwGetRefField const*>(fields[5]->GetField())->GetPar2()); + + tempDir.EnableKillingFile(); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/doc/docglbl.cxx b/sw/source/core/doc/docglbl.cxx index 176a1a2a443c..a9ab35670ed1 100644 --- a/sw/source/core/doc/docglbl.cxx +++ b/sw/source/core/doc/docglbl.cxx @@ -307,7 +307,8 @@ bool SwDoc::SplitDoc( sal_uInt16 eDocType, const OUString& rPath, bool bOutline, SwNodeRange aRg( *pStartNd, 0, aEndIdx.GetNode() ); SwNodeIndex aTmpIdx( pDoc->GetNodes().GetEndOfContent() ); - GetNodes().Copy_( aRg, aTmpIdx, false ); + GetDocumentContentOperationsManager().CopyWithFlyInFly( + aRg, aTmpIdx, nullptr, false, false); // Delete the initial TextNode SwNodeIndex aIdx( pDoc->GetNodes().GetEndOfExtras(), 2 ); @@ -315,12 +316,6 @@ bool SwDoc::SplitDoc( sal_uInt16 eDocType, const OUString& rPath, bool bOutline, pDoc->GetNodes().GetEndOfContent().GetIndex() ) pDoc->GetNodes().Delete( aIdx ); - // All Flys in the section - GetDocumentContentOperationsManager().CopyFlyInFlyImpl(aRg, nullptr, aIdx); - - // And what's with all the Bookmarks? - // ????? - utl::TempFile aTempFile2(sLeading, true, &sExt, &sPath); sFileName = aTempFile2.GetURL(); SfxMedium* pTmpMed = new SfxMedium( sFileName, |