sw/CppunitTest_sw_uibase_dialog.mk   |   76 +++++++++++++++++++++++++++++++++++
 sw/Module_sw.mk                      |    1 
 sw/qa/uibase/dialog/dialog.cxx       |   59 +++++++++++++++++++++++++++
 sw/sdi/swriter.sdi                   |    2 
 sw/source/uibase/dialog/regionsw.cxx |   27 ++++++++++++
 5 files changed, 164 insertions(+), 1 deletion(-)

New commits:
commit dd775cd630c907bc7d8bcd6f57ffd3f66115a5ba
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Mon Jan 9 11:08:42 2023 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon Jan 9 12:25:12 2023 +0000

    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.
    
    Change-Id: I0ccbc8a765fed4e019783d0b743c1cd2d0596093
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145188
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins

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 15760fd72c02..48131d6126f1 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