diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2023-01-19 08:19:46 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2023-01-19 15:48:33 +0000 |
commit | 22f3aff3a1582f17f314e13f2685fefddccfae4a (patch) | |
tree | ee8aaf4e558380f7f8e603defceeee79b172ed52 | |
parent | 13594ec9080912f59a0700fed603022138c5f806 (diff) |
sw, .uno:InsertField: handle Endnote as a value for the Wrapper parameter
This is similar to commit 43d80906c8693ca27c5b3077fbaa259df4004924 (sw:
.uno:TextFormField: handle Endnote as a value for the Wrapper parameter,
2023-01-17), but that was for fieldmarks & endnotes, this is for
refmarks & endnotes.
(cherry picked from commit 04d988d3c368fe07ae3c44c536a4513e424f104e)
Change-Id: I46512dd973508f51f7093521c40ad4100dd39ae6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145773
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Justin Luth <jluth@mail.com>
-rw-r--r-- | sw/qa/uibase/shells/textfld.cxx | 28 | ||||
-rw-r--r-- | sw/source/uibase/shells/textfld.cxx | 8 |
2 files changed, 34 insertions, 2 deletions
diff --git a/sw/qa/uibase/shells/textfld.cxx b/sw/qa/uibase/shells/textfld.cxx index 7799063a016c..1ef61b658c4a 100644 --- a/sw/qa/uibase/shells/textfld.cxx +++ b/sw/qa/uibase/shells/textfld.cxx @@ -57,4 +57,32 @@ CPPUNIT_TEST_FIXTURE(Test, testInsertRefmarkFootnote) CPPUNIT_ASSERT_EQUAL(OUString("content"), rFormatNote.GetFootnoteText(*pWrtShell->GetLayout())); } +CPPUNIT_TEST_FIXTURE(Test, testInsertRefmarkEndnote) +{ + // Given an empty document: + SwDoc* pDoc = createSwDoc(); + + // When inserting a refmark inside an endnote: + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("TypeName", uno::Any(OUString("SetRef"))), + comphelper::makePropertyValue("Name", uno::Any(OUString("myref"))), + comphelper::makePropertyValue("Content", uno::Any(OUString("content"))), + comphelper::makePropertyValue("Wrapper", uno::Any(OUString("Endnote"))), + }; + dispatchCommand(mxComponent, ".uno:InsertField", aArgs); + + // Then make sure that the note body contains the refmark: + SwFootnoteIdxs& rNotes = pDoc->GetFootnoteIdxs(); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1 + // - Actual : 0 + // i.e. no endnote was inserted. + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rNotes.size()); + SwTextFootnote* pNote = rNotes[0]; + const SwFormatFootnote& rNote = pNote->GetFootnote(); + CPPUNIT_ASSERT(rNote.IsEndNote()); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + CPPUNIT_ASSERT_EQUAL(OUString("content"), rNote.GetFootnoteText(*pWrtShell->GetLayout())); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/shells/textfld.cxx b/sw/source/uibase/shells/textfld.cxx index a68b17124d2b..a59a5616ffcf 100644 --- a/sw/source/uibase/shells/textfld.cxx +++ b/sw/source/uibase/shells/textfld.cxx @@ -292,13 +292,17 @@ void SwTextShell::ExecField(SfxRequest &rReq) } if (pArgs->GetItemState(FN_PARAM_5, false, &pItem) == SfxItemState::SET) { + // Wrap the field in the requested container instead of inserting it + // directly at the cursor position. const OUString& rWrapper = static_cast<const SfxStringItem *>(pItem)->GetValue(); if (rWrapper == "Footnote") { - // Wrap the field in the requested container instead of inserting it - // directly at the cursor position. GetShellPtr()->InsertFootnote(OUString()); } + else if (rWrapper == "Endnote") + { + GetShellPtr()->InsertFootnote(OUString(), /*bEndNote=*/true); + } } SwInsertField_Data aData(nType, nSubType, aPar1, aPar2, nFormat, GetShellPtr(), cSeparator ); bRes = aFieldMgr.InsertField( aData ); |