sw/qa/uibase/shells/shells.cxx | 25 +++++++++++++++++++++++++ sw/sdi/swriter.sdi | 2 +- sw/source/uibase/shells/textfld.cxx | 12 ++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-)
New commits: commit b09b29073f0802cc7e30c9455e2c8d6ac1ea6c63 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Mon Jan 16 16:34:40 2023 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Tue Jan 17 13:05:29 2023 +0000 sw: .uno:TextFormField: add new Wrapper parameter Currently all fieldmarks are inserted into the document body unconditionally when this UNO command is dispatched. Inserting at the current cursor position makes sense, but some citation styles want to insert the actual citation as footnotes, and only have the footnote anchor at the cursor position. Fix the problem by adding a new Wrapper parameter to this UNO command: currently the only interesting value it may have is Footnote, if this is specified then first we insert a footnote and the footnote content will host the fieldmark, not the original body text. The same will be wanted for endnotes as well, but that's not yet done in this commit. (cherry picked from commit ceea8f3924f26d5f10adc41b9ea587c77c2fda74) Change-Id: I5c96c7dc9ddaace09b1dbc21b8f12005a2934d04 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145661 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Justin Luth <jl...@mail.com> diff --git a/sw/qa/uibase/shells/shells.cxx b/sw/qa/uibase/shells/shells.cxx index b031874c11c6..f4fcbd8eeb7e 100644 --- a/sw/qa/uibase/shells/shells.cxx +++ b/sw/qa/uibase/shells/shells.cxx @@ -39,6 +39,7 @@ #include <docsh.hxx> #include <bookmark.hxx> #include <ndtxt.hxx> +#include <ftnidx.hxx> constexpr OUStringLiteral DATA_DIRECTORY = u"/sw/qa/uibase/shells/data/"; @@ -865,6 +866,30 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testDeleteFields) CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(0), pDoc->GetRefMarks()); } +CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testInsertTextFormFieldFootnote) +{ + // Given an empty document: + SwDoc* pDoc = createSwDoc(); + + // When inserting an ODF_UNHANDLED fieldmark inside a footnote: + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("FieldType", uno::Any(OUString(ODF_UNHANDLED))), + comphelper::makePropertyValue("FieldCommand", + uno::Any(OUString("ADDIN ZOTERO_BIBL foo bar"))), + comphelper::makePropertyValue("FieldResult", uno::Any(OUString("result"))), + comphelper::makePropertyValue("Wrapper", uno::Any(OUString("Footnote"))), + }; + dispatchCommand(mxComponent, ".uno:TextFormField", aArgs); + + // Then make sure that the footnote is created: + SwFootnoteIdxs& rFootnotes = pDoc->GetFootnoteIdxs(); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1 + // - Actual : 0 + // i.e. no footnote was created. + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rFootnotes.size()); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/sdi/swriter.sdi b/sw/sdi/swriter.sdi index 391582c02d64..64da3512ef94 100644 --- a/sw/sdi/swriter.sdi +++ b/sw/sdi/swriter.sdi @@ -8322,7 +8322,7 @@ SfxBoolItem ShowInlineTooltips FN_SHOW_INLINETOOLTIPS ] SfxVoidItem TextFormField FN_INSERT_TEXT_FORMFIELD -(SfxStringItem FieldType FN_PARAM_1, SfxStringItem FieldCommand FN_PARAM_2, SfxStringItem FieldResult FN_PARAM_3) +(SfxStringItem FieldType FN_PARAM_1, SfxStringItem FieldCommand FN_PARAM_2, SfxStringItem FieldResult FN_PARAM_3, SfxStringItem Wrapper FN_PARAM_4) [ AutoUpdate = TRUE, FastCall = FALSE, diff --git a/sw/source/uibase/shells/textfld.cxx b/sw/source/uibase/shells/textfld.cxx index c464ae31f528..cd9d1f61ebf6 100644 --- a/sw/source/uibase/shells/textfld.cxx +++ b/sw/source/uibase/shells/textfld.cxx @@ -739,6 +739,18 @@ FIELD_INSERT: aFieldResult = pFieldResult->GetValue(); } + const SfxStringItem* pWrapper = rReq.GetArg<SfxStringItem>(FN_PARAM_4); + if (pWrapper) + { + // Wrap the fieldmark in the requested container instead of inserting it + // directly at the cursor position. + OUString aWrapper = pWrapper->GetValue(); + if (aWrapper == "Footnote") + { + rSh.InsertFootnote(OUString()); + } + } + // Split node to remember where the start position is. bool bSuccess = rSh.GetDoc()->getIDocumentContentOperations().SplitNode( *pCursorPos->GetPoint(), false);