sw/CppunitTest_sw_uibase_dialog.mk   |   76 +++++++++++++++++++++++++++++++++++
 sw/Module_sw.mk                      |    1 
 sw/qa/uibase/dialog/dialog.cxx       |   59 +++++++++++++++++++++++++++
 sw/qa/uibase/shells/shells.cxx       |    9 +++-
 sw/qa/uibase/uno/uno.cxx             |    5 +-
 sw/sdi/swriter.sdi                   |    2 
 sw/source/uibase/dialog/regionsw.cxx |   27 ++++++++++++
 sw/source/uibase/shells/textfld.cxx  |    3 +
 sw/source/uibase/shells/textsh1.cxx  |    2 
 sw/source/uibase/uno/loktxdoc.cxx    |    1 
 10 files changed, 179 insertions(+), 6 deletions(-)

New commits:
commit df5bd99aff6162b8c6a4e3cfcbed30bc5b3638c0
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Mon Jan 9 16:27:15 2023 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue Jan 31 08:41:19 2023 +0100

    sw, UpdateBookmarks: support renaming bookmarks
    
    The problem was that the LOK API client wanted to change the name of the
    bookmark, but nothing happened, because we had a sanity check that made
    sure the provided vs existing bookmark names match.
    
    The intention was that the bookmark name is just an ID (you can store
    additional properties in per-doc custom properties, those can change),
    so we can require that bookmarks never get renamed when using this
    command.
    
    Fix the problem by dropping this requirement and rather use renameMark()
    to adjust the in-doc bookmark name if needed.
    
    This also handles undo/redo for us.
    
    (cherry picked from commit d2318503d559c3797965da777627e4ee45143043)
    
    Change-Id: I7a426c865ddf24f13741c0369fb3991da2e881b2

diff --git a/sw/qa/uibase/shells/shells.cxx b/sw/qa/uibase/shells/shells.cxx
index 610890c15312..7457c62806c1 100644
--- a/sw/qa/uibase/shells/shells.cxx
+++ b/sw/qa/uibase/shells/shells.cxx
@@ -552,7 +552,7 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, 
testUpdateBookmarks)
             {
                 "Bookmark": {
                     "type": "string",
-                    "value": "ZOTERO_BREF_GiQ7DAWQYWLy"
+                    "value": "ZOTERO_BREF_new1"
                 },
                 "BookmarkText": {
                     "type": "string",
@@ -562,7 +562,7 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, 
testUpdateBookmarks)
             {
                 "Bookmark": {
                     "type": "string",
-                    "value": "ZOTERO_BREF_PRxDGUb4SWXF"
+                    "value": "ZOTERO_BREF_new2"
                 },
                 "BookmarkText": {
                     "type": "string",
@@ -584,6 +584,11 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, 
testUpdateBookmarks)
     // - Actual  : ABCDE
     // i.e. the content was not updated.
     CPPUNIT_ASSERT_EQUAL(OUString("Anew result 1Cnew result 2E"), aActual);
+
+    // Without the accompanying fix in place, this test would have failed, 
ZOTERO_BREF_GiQ7DAWQYWLy
+    // was not renamed to ZOTERO_BREF_new1.
+    auto it = pDoc->getIDocumentMarkAccess()->findMark("ZOTERO_BREF_new1");
+    CPPUNIT_ASSERT(it != pDoc->getIDocumentMarkAccess()->getAllMarksEnd());
 }
 
 CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testUpdateFieldmark)
diff --git a/sw/source/uibase/shells/textsh1.cxx 
b/sw/source/uibase/shells/textsh1.cxx
index d136c80d2d07..a33f23ed9d2f 100644
--- a/sw/source/uibase/shells/textsh1.cxx
+++ b/sw/source/uibase/shells/textsh1.cxx
@@ -425,7 +425,7 @@ void UpdateBookmarks(SfxRequest& rReq, SwWrtShell& rWrtSh)
         comphelper::SequenceAsHashMap aMap(aBookmarks[nBookmarkIndex++]);
         if (aMap["Bookmark"].get<OUString>() != pMark->GetName())
         {
-            continue;
+            rIDMA.renameMark(pMark, aMap["Bookmark"].get<OUString>());
         }
 
         OUString aBookmarkText = aMap["BookmarkText"].get<OUString>();
commit 2e4b3359f3bf5c29a817209c5df7506fc94cbba0
Author:     Pranam Lashkari <lpra...@collabora.com>
AuthorDate: Tue Jan 10 11:24:56 2023 +0530
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue Jan 31 08:40:21 2023 +0100

    sw: return field under cursor inside field node
    
    Having values inside field node makes it easier to detect which commands 
value
    is being returned in online. otherwise its impossible to predict the 
command from "type" and "command"
    as "command" can be anything and "type" is very generic
    
    this also makes output more consistent with "GetTextFormFields"
    
    (cherry picked from commit 5dd5011eabc755d4ea8d282c32dd4854d532849a)
    
    Change-Id: I1b8b39bfd0de6d7b19c2944bd42f7031d60518af

diff --git a/sw/qa/uibase/uno/uno.cxx b/sw/qa/uibase/uno/uno.cxx
index 3eb830ec8c55..b89b129100cd 100644
--- a/sw/qa/uibase/uno/uno.cxx
+++ b/sw/qa/uibase/uno/uno.cxx
@@ -407,10 +407,11 @@ CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, 
testGetTextFormField)
     // Without the accompanying fix in place, this test would have failed with:
     // - No such node (type)
     // i.e. the returned JSON was just an empty object.
+    auto field = aTree.get_child("field");
     CPPUNIT_ASSERT_EQUAL(std::string("vnd.oasis.opendocument.field.UNHANDLED"),
-                         aTree.get<std::string>("type"));
+                         field.get<std::string>("type"));
     CPPUNIT_ASSERT_EQUAL(std::string("ADDIN ZOTERO_ITEM foo bar"),
-                         aTree.get<std::string>("command"));
+                         field.get<std::string>("command"));
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/uibase/uno/loktxdoc.cxx 
b/sw/source/uibase/uno/loktxdoc.cxx
index 62e6244bd4a4..623da5f049e8 100644
--- a/sw/source/uibase/uno/loktxdoc.cxx
+++ b/sw/source/uibase/uno/loktxdoc.cxx
@@ -126,6 +126,7 @@ void GetTextFormField(tools::JsonWriter& rJsonWriter, 
SwDocShell* pDocShell,
     SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
     SwPosition& rCursor = *pWrtShell->GetCursor()->GetPoint();
     sw::mark::IFieldmark* pFieldmark = rIDMA.getFieldmarkFor(rCursor);
+    auto typeNode = rJsonWriter.startNode("field");
     if (!pFieldmark)
     {
         return;
commit 98ccd42e59efa689561fffccd7cbb46d25ce9cf5
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Mon Jan 9 09:52:32 2023 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue Jan 31 08:39:16 2023 +0100

    sw: document FN_UPDATE_TEXT_FORMFIELD and FN_UPDATE_TEXT_FORMFIELDS
    
    If you don't read the commit message or the code, it wasn't really
    obvious that FN_UPDATE_TEXT_FORMFIELD works based on the current cursor.
    
    (cherry picked from commit 8336c61ba059551cb74df5ec53d2b45a3cf41814)
    
    Change-Id: Icd8bc856e5d50b995fa92559c873a50b48b98ba8

diff --git a/sw/source/uibase/shells/textfld.cxx 
b/sw/source/uibase/shells/textfld.cxx
index dffea8e924ee..71e57ba0ae47 100644
--- a/sw/source/uibase/shells/textfld.cxx
+++ b/sw/source/uibase/shells/textfld.cxx
@@ -862,6 +862,8 @@ FIELD_INSERT:
     break;
     case FN_UPDATE_TEXT_FORMFIELDS:
     {
+        // This updates multiple fieldmarks in a document, based on their 
field name & field command
+        // prefix.
         OUString aFieldType;
         const SfxStringItem* pFieldType = 
rReq.GetArg<SfxStringItem>(FN_PARAM_1);
         if (pFieldType)
@@ -1013,6 +1015,7 @@ FIELD_INSERT:
     break;
     case FN_UPDATE_TEXT_FORMFIELD:
     {
+        // This updates a single fieldmarks under the current cursor.
         OUString aFieldType;
         const SfxStringItem* pFieldType = 
rReq.GetArg<SfxStringItem>(FN_PARAM_1);
         if (pFieldType)
commit 5d2e09f4e840ad499cfd16653e690f6c96be0116
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Mon Jan 9 11:08:42 2023 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue Jan 31 08:37:48 2023 +0100

    sw, .uno:InsertSection: add a new Content parameter and accept HTML there
    
    When Zotero uses refmarks to represent citations, then a section is used
    for the bibliography. While it was possible to insert refmarks with a
    given name & content, inserting a section with a provided HTML content
    was not possible.
    
    A section (and not a refmark) is needed for the bibliography, as a
    refmark is a text attribute, so it must start and end in the same
    paragraph.
    
    Fix this by adding a new, optional Content parameter to
    .uno:InsertSection, which allows providing multi-paragraph, formatted
    text.
    
    This is somewhat similar to what commit
    fa82e151d80d15eeb6dfae434f1dbb3b68907188 (sw, .uno:InsertBookmark: add a
    new BookmarkText parameter and accept HTML there, 2022-12-06) did for
    the bookmark case.
    
    (cherry picked from commit dd775cd630c907bc7d8bcd6f57ffd3f66115a5ba)
    
    Change-Id: I0ccbc8a765fed4e019783d0b743c1cd2d0596093

diff --git a/sw/CppunitTest_sw_uibase_dialog.mk 
b/sw/CppunitTest_sw_uibase_dialog.mk
new file mode 100644
index 000000000000..eaecfc5abeb6
--- /dev/null
+++ b/sw/CppunitTest_sw_uibase_dialog.mk
@@ -0,0 +1,76 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#*************************************************************************
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#*************************************************************************
+
+$(eval $(call gb_CppunitTest_CppunitTest,sw_uibase_dialog))
+
+$(eval $(call gb_CppunitTest_use_common_precompiled_header,sw_uibase_dialog))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,sw_uibase_dialog, \
+    sw/qa/uibase/dialog/dialog \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,sw_uibase_dialog, \
+    comphelper \
+    cppu \
+    cppuhelper \
+    editeng \
+    sal \
+    sfx \
+    subsequenttest \
+    svl \
+    svx \
+    svxcore \
+    sw \
+       swqahelper \
+    test \
+    unotest \
+    utl \
+    vcl \
+    tl \
+))
+
+$(eval $(call gb_CppunitTest_use_externals,sw_uibase_dialog,\
+    boost_headers \
+    libxml2 \
+))
+
+$(eval $(call gb_CppunitTest_set_include,sw_uibase_dialog,\
+    -I$(SRCDIR)/sw/inc \
+    -I$(SRCDIR)/sw/source/core/inc \
+    -I$(SRCDIR)/sw/source/uibase/inc \
+    -I$(SRCDIR)/sw/qa/inc \
+    $$(INCLUDE) \
+))
+
+$(eval $(call gb_CppunitTest_use_api,sw_uibase_dialog,\
+       udkapi \
+       offapi \
+       oovbaapi \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,sw_uibase_dialog))
+$(eval $(call gb_CppunitTest_use_vcl,sw_uibase_dialog))
+
+$(eval $(call gb_CppunitTest_use_rdb,sw_uibase_dialog,services))
+
+$(eval $(call gb_CppunitTest_use_custom_headers,sw_uibase_dialog,\
+    officecfg/registry \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,sw_uibase_dialog))
+
+$(eval $(call gb_CppunitTest_use_uiconfigs,sw_uibase_dialog, \
+    modules/swriter \
+))
+
+$(eval $(call gb_CppunitTest_use_more_fonts,sw_uibase_dialog))
+
+# vim: set noet sw=4 ts=4:
diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk
index a15763330763..44d5bc4e8d22 100644
--- a/sw/Module_sw.mk
+++ b/sw/Module_sw.mk
@@ -134,6 +134,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\
     CppunitTest_sw_uibase_docvw \
     CppunitTest_sw_uibase_frmdlg \
     CppunitTest_sw_uibase_uno \
+    CppunitTest_sw_uibase_dialog \
     CppunitTest_sw_uibase_wrtsh \
     CppunitTest_sw_core_accessibilitycheck \
     CppunitTest_sw_core_layout \
diff --git a/sw/qa/uibase/dialog/dialog.cxx b/sw/qa/uibase/dialog/dialog.cxx
new file mode 100644
index 000000000000..b7c1f766c3f0
--- /dev/null
+++ b/sw/qa/uibase/dialog/dialog.cxx
@@ -0,0 +1,59 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <swmodeltestbase.hxx>
+
+#include <comphelper/propertyvalue.hxx>
+
+#include <wrtsh.hxx>
+#include <docsh.hxx>
+
+namespace
+{
+/// Covers sw/source/uibase/dialog/ fixes.
+class Test : public SwModelTestBase
+{
+public:
+    Test()
+        : SwModelTestBase("/sw/qa/uibase/dialog/data/")
+    {
+    }
+};
+}
+
+CPPUNIT_TEST_FIXTURE(Test, testInsertSection)
+{
+    // Given an empty document:
+    createSwDoc();
+    SwDoc* pDoc = getSwDoc();
+
+    // When inserting a section with text:
+    uno::Sequence<css::beans::PropertyValue> aArgs = {
+        comphelper::makePropertyValue(
+            "RegionName", uno::Any(OUString("ZOTERO_BIBL {} CSL_BIBLIOGRAPHY 
RNDRfiit6mXBc"))),
+        comphelper::makePropertyValue("Content", 
uno::Any(OUString("<p>aaa</p><p>bbb</p>"))),
+    };
+    dispatchCommand(mxComponent, ".uno:InsertSection", aArgs);
+
+    // Then make sure that we created a section that covers that text:
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+    pWrtShell->SttEndDoc(/*bStt=*/true);
+    pWrtShell->EndOfSection(/*bSelect=*/true);
+    SwCursor* pCursor = pWrtShell->GetCursor();
+    OUString aActualResult = pCursor->GetText();
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: aaa\nbbb
+    // - Actual  :
+    // i.e. the value of the Content parameter was ignored.
+    CPPUNIT_ASSERT_EQUAL(OUString("aaa\nbbb"), aActualResult);
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/sdi/swriter.sdi b/sw/sdi/swriter.sdi
index 72330e643039..d4521ac148b1 100644
--- a/sw/sdi/swriter.sdi
+++ b/sw/sdi/swriter.sdi
@@ -2799,7 +2799,7 @@ SfxVoidItem PasteColumnsBefore FN_TABLE_PASTE_COL_BEFORE
 ]
 
 SfxUInt16Item InsertSection FN_INSERT_REGION
-(SfxUInt16Item Columns SID_ATTR_COLUMNS,SfxStringItem RegionName 
FN_PARAM_REGION_NAME,SfxStringItem RegionCondition 
FN_PARAM_REGION_CONDITION,SfxBoolItem RegionHidden 
FN_PARAM_REGION_HIDDEN,SfxBoolItem RegionProtect 
FN_PARAM_REGION_PROTECT,SfxStringItem LinkName FN_PARAM_1,SfxStringItem 
FilterName FN_PARAM_2,SfxStringItem SubRegion FN_PARAM_3)
+(SfxUInt16Item Columns SID_ATTR_COLUMNS,SfxStringItem RegionName 
FN_PARAM_REGION_NAME,SfxStringItem RegionCondition 
FN_PARAM_REGION_CONDITION,SfxBoolItem RegionHidden 
FN_PARAM_REGION_HIDDEN,SfxBoolItem RegionProtect 
FN_PARAM_REGION_PROTECT,SfxStringItem LinkName FN_PARAM_1,SfxStringItem 
FilterName FN_PARAM_2,SfxStringItem SubRegion FN_PARAM_3, SfxStringItem Content 
FN_PARAM_4)
 [
     AutoUpdate = FALSE,
     FastCall = FALSE,
diff --git a/sw/source/uibase/dialog/regionsw.cxx 
b/sw/source/uibase/dialog/regionsw.cxx
index dbc331c6ea88..834f1b332bc5 100644
--- a/sw/source/uibase/dialog/regionsw.cxx
+++ b/sw/source/uibase/dialog/regionsw.cxx
@@ -32,6 +32,9 @@
 #include <fmtfsize.hxx>
 #include <cmdid.h>
 #include <swabstdlg.hxx>
+#include <IDocumentContentOperations.hxx>
+#include <translatehelper.hxx>
+#include <IDocumentUndoRedo.hxx>
 
 void SwBaseShell::InsertRegionDialog(SfxRequest& rReq)
 {
@@ -147,7 +150,31 @@ void SwBaseShell::InsertRegionDialog(SfxRequest& rReq)
             aSection.SetType( SectionType::FileLink );
             aSection.SetLinkFileName(sLinkFileName);
         }
+        rSh.GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::INSSECTION, 
nullptr);
+        rSh.StartAction();
         rSh.InsertSection(aSection, aSet.Count() ? &aSet : nullptr);
+
+        const SfxStringItem* pSectionContent = 
rReq.GetArg<SfxStringItem>(FN_PARAM_4);
+        if (pSectionContent)
+        {
+            OUString aSectionContent = pSectionContent->GetValue();
+            SwPaM* pCursorPos = rSh.GetCursor();
+            pCursorPos->Move(fnMoveBackward, GoInContent);
+            // Paste HTML content.
+            SwTranslateHelper::PasteHTMLToPaM(rSh, pCursorPos, 
aSectionContent.toUtf8(),
+                                              /*bSetSelection=*/true);
+            if (pCursorPos->GetPoint()->GetContentIndex() == 0)
+            {
+                // The paste created a last empty text node, remove it.
+                SwPaM aPam(*pCursorPos->GetPoint());
+                aPam.SetMark();
+                aPam.Move(fnMoveBackward, GoInContent);
+                
rSh.GetDoc()->getIDocumentContentOperations().DeleteAndJoin(aPam);
+            }
+        }
+        rSh.EndAction();
+        rSh.GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::INSSECTION, 
nullptr);
+
         rReq.Done();
     }
 }

Reply via email to