sw/qa/uibase/shells/shells.cxx      |   26 ++++++++++++++++++++++++++
 sw/sdi/swriter.sdi                  |    2 +-
 sw/source/uibase/shells/textfld.cxx |   12 ++++++++++++
 3 files changed, 39 insertions(+), 1 deletion(-)

New commits:
commit ceea8f3924f26d5f10adc41b9ea587c77c2fda74
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 08:30:47 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.
    
    Change-Id: I5c96c7dc9ddaace09b1dbc21b8f12005a2934d04
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145602
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/qa/uibase/shells/shells.cxx b/sw/qa/uibase/shells/shells.cxx
index 8ed71760baa7..6dfc6ed6e9da 100644
--- a/sw/qa/uibase/shells/shells.cxx
+++ b/sw/qa/uibase/shells/shells.cxx
@@ -39,6 +39,7 @@
 #include <drawdoc.hxx>
 #include <docsh.hxx>
 #include <ndtxt.hxx>
+#include <ftnidx.hxx>
 
 /// Covers sw/source/uibase/shells/ fixes.
 class SwUibaseShellsTest : public SwModelTestBase
@@ -935,6 +936,31 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testDeleteFields)
     CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(0), pDoc->GetRefMarks());
 }
 
+CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testInsertTextFormFieldFootnote)
+{
+    // Given an empty document:
+    createSwDoc();
+    SwDoc* pDoc = getSwDoc();
+
+    // 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 bc1b52b92b43..b974614b1e01 100644
--- a/sw/sdi/swriter.sdi
+++ b/sw/sdi/swriter.sdi
@@ -8354,7 +8354,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 = FALSE,
     FastCall = FALSE,
diff --git a/sw/source/uibase/shells/textfld.cxx 
b/sw/source/uibase/shells/textfld.cxx
index 77d68cddf3d7..239e4a076812 100644
--- a/sw/source/uibase/shells/textfld.cxx
+++ b/sw/source/uibase/shells/textfld.cxx
@@ -748,6 +748,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);

Reply via email to