summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-11-15 09:53:20 +0100
committerMiklos Vajna <vmiklos@collabora.com>2022-11-15 11:34:49 +0100
commit6870c0c3385bf5d19e9c80bf973fca255ae38c08 (patch)
tree9abcb20a38b24b620b3380c053ae0aa47bc7172e
parent1caf3f2554ffac3624d43defb4252a5b40945bbc (diff)
sw: add new FieldCode parameter for the .uno:TextFormField command
The field code/command is the input of the field expand. Also allow setting a field result, given that the entire point of "unhandled" fieldmarks is that Writer itself doesn't know how to compute the field result / expanded string. Note that a field result can be a multi-paragraph and formatted content, so far we only allow single-paragraph plain text. Change-Id: I1739cb985d1d4ed8e45068f15a4e0d82fd118d83 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142726 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
-rw-r--r--sw/qa/uibase/shells/shells.cxx13
-rw-r--r--sw/sdi/swriter.sdi2
-rw-r--r--sw/source/uibase/shells/textfld.cxx29
3 files changed, 39 insertions, 5 deletions
diff --git a/sw/qa/uibase/shells/shells.cxx b/sw/qa/uibase/shells/shells.cxx
index c107913e6469..803c41657e89 100644
--- a/sw/qa/uibase/shells/shells.cxx
+++ b/sw/qa/uibase/shells/shells.cxx
@@ -277,8 +277,12 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testInsertTextFormField)
SwDoc* pDoc = getSwDoc();
// When inserting an ODF_UNHANDLED fieldmark:
+ OUString aExpectedCommand("ADDIN ZOTERO_BIBL foo bar");
+ OUString aExpectedResult("(Abrikosov, n.d.)");
uno::Sequence<css::beans::PropertyValue> aArgs = {
comphelper::makePropertyValue("FieldType", uno::Any(OUString(ODF_UNHANDLED))),
+ comphelper::makePropertyValue("FieldCommand", uno::Any(aExpectedCommand)),
+ comphelper::makePropertyValue("FieldResult", uno::Any(aExpectedResult)),
};
dispatchCommand(mxComponent, ".uno:TextFormField", aArgs);
@@ -294,6 +298,15 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testInsertTextFormField)
// - Actual : vnd.oasis.opendocument.field.FORMTEXT
// i.e. the custom type parameter was ignored.
CPPUNIT_ASSERT_EQUAL(OUString(ODF_UNHANDLED), pFieldmark->GetFieldname());
+
+ auto it = pFieldmark->GetParameters()->find(ODF_CODE_PARAM);
+ CPPUNIT_ASSERT(it != pFieldmark->GetParameters()->end());
+ OUString aActualCommand;
+ it->second >>= aActualCommand;
+ CPPUNIT_ASSERT_EQUAL(aExpectedCommand, aActualCommand);
+
+ OUString aActualResult = pFieldmark->GetContent();
+ CPPUNIT_ASSERT_EQUAL(aExpectedResult, aActualResult);
}
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/sdi/swriter.sdi b/sw/sdi/swriter.sdi
index 61e38bfe7f78..48328375735c 100644
--- a/sw/sdi/swriter.sdi
+++ b/sw/sdi/swriter.sdi
@@ -8238,7 +8238,7 @@ SfxBoolItem ShowInlineTooltips FN_SHOW_INLINETOOLTIPS
]
SfxVoidItem TextFormField FN_INSERT_TEXT_FORMFIELD
-(SfxStringItem FieldType FN_PARAM_1)
+(SfxStringItem FieldType FN_PARAM_1, SfxStringItem FieldCommand FN_PARAM_2, SfxStringItem FieldResult FN_PARAM_3)
[
AutoUpdate = TRUE,
FastCall = FALSE,
diff --git a/sw/source/uibase/shells/textfld.cxx b/sw/source/uibase/shells/textfld.cxx
index 54e19d7ec8c4..85dffcd7affc 100644
--- a/sw/source/uibase/shells/textfld.cxx
+++ b/sw/source/uibase/shells/textfld.cxx
@@ -694,6 +694,14 @@ FIELD_INSERT:
aFieldType = pFieldType->GetValue();
}
+ OUString aFieldCode;
+ const SfxStringItem* pFieldCode = rReq.GetArg<SfxStringItem>(FN_PARAM_2);
+ if (pFieldCode)
+ {
+ // Allow specifying a field code/command.
+ aFieldCode = pFieldCode->GetValue();
+ }
+
rSh.GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::INSERT_FORM_FIELD, nullptr);
SwPaM* pCursorPos = rSh.GetCursor();
@@ -701,14 +709,27 @@ FIELD_INSERT:
{
// Insert five En Space into the text field so the field has extent
static constexpr OUStringLiteral vEnSpaces = u"\u2002\u2002\u2002\u2002\u2002";
- bool bSuccess = rSh.GetDoc()->getIDocumentContentOperations().InsertString(*pCursorPos, vEnSpaces);
+ OUString aFieldResult(vEnSpaces);
+ const SfxStringItem* pFieldResult = rReq.GetArg<SfxStringItem>(FN_PARAM_3);
+ if (pFieldResult)
+ {
+ // Allow specifying a field result / expanded value.
+ aFieldResult = pFieldResult->GetValue();
+ }
+
+ bool bSuccess = rSh.GetDoc()->getIDocumentContentOperations().InsertString(*pCursorPos, aFieldResult);
if(bSuccess)
{
IDocumentMarkAccess* pMarksAccess = rSh.GetDoc()->getIDocumentMarkAccess();
- SwPaM aFieldPam(pCursorPos->GetPoint()->GetNode(), pCursorPos->GetPoint()->GetContentIndex() - vEnSpaces.getLength(),
+ SwPaM aFieldPam(pCursorPos->GetPoint()->GetNode(), pCursorPos->GetPoint()->GetContentIndex() - aFieldResult.getLength(),
pCursorPos->GetPoint()->GetNode(), pCursorPos->GetPoint()->GetContentIndex());
- pMarksAccess->makeFieldBookmark(aFieldPam, OUString(), aFieldType,
- aFieldPam.Start());
+ sw::mark::IFieldmark* pFieldmark = pMarksAccess->makeFieldBookmark(
+ aFieldPam, OUString(), aFieldType, aFieldPam.Start());
+ if (pFieldmark && !aFieldCode.isEmpty())
+ {
+ pFieldmark->GetParameters()->insert(
+ std::pair<OUString, uno::Any>(ODF_CODE_PARAM, uno::Any(aFieldCode)));
+ }
}
}