[Libreoffice-commits] core.git: sw/CppunitTest_sw_uibase_fldui.mk sw/Module_sw.mk sw/qa sw/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Wed Apr 21 10:01:39 UTC 2021


 sw/CppunitTest_sw_uibase_fldui.mk |   74 ++++++++++++++++++++++++++++
 sw/Module_sw.mk                   |    1 
 sw/qa/uibase/fldui/fldui.cxx      |   98 ++++++++++++++++++++++++++++++++++++++
 sw/source/uibase/fldui/fldmgr.cxx |   33 ++++++++++++
 4 files changed, 206 insertions(+)

New commits:
commit adea8835d417379447cb8de6f30e959808b8db91
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Wed Apr 21 10:51:05 2021 +0200
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Wed Apr 21 12:00:47 2021 +0200

    sw bibliography, refer to a page: edit the page number of individual entries
    
    Usually it's handy that editing a bibliography entry field updates all
    other fields referring to the same source. But avoid doing this in case
    only the page number changes, that's typically specific to that field.
    
    Change-Id: I2b2608c6c4fdb859c430294eaecdadfeb1c802a2
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114380
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
    Tested-by: Jenkins

diff --git a/sw/CppunitTest_sw_uibase_fldui.mk b/sw/CppunitTest_sw_uibase_fldui.mk
new file mode 100644
index 000000000000..613161a21be4
--- /dev/null
+++ b/sw/CppunitTest_sw_uibase_fldui.mk
@@ -0,0 +1,74 @@
+# -*- 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_fldui))
+
+$(eval $(call gb_CppunitTest_use_common_precompiled_header,sw_uibase_fldui))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,sw_uibase_fldui, \
+    sw/qa/uibase/fldui/fldui \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,sw_uibase_fldui, \
+    comphelper \
+    cppu \
+    cppuhelper \
+    sal \
+    sfx \
+    svxcore \
+    sw \
+    swqahelper \
+    test \
+    unotest \
+    utl \
+    vcl \
+    svt \
+    tl \
+    svl \
+))
+
+$(eval $(call gb_CppunitTest_use_externals,sw_uibase_fldui,\
+    boost_headers \
+    libxml2 \
+))
+
+$(eval $(call gb_CppunitTest_set_include,sw_uibase_fldui,\
+    -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_fldui,\
+    udkapi \
+    offapi \
+    oovbaapi \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,sw_uibase_fldui))
+$(eval $(call gb_CppunitTest_use_vcl,sw_uibase_fldui))
+
+$(eval $(call gb_CppunitTest_use_rdb,sw_uibase_fldui,services))
+
+$(eval $(call gb_CppunitTest_use_custom_headers,sw_uibase_fldui,\
+    officecfg/registry \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,sw_uibase_fldui))
+
+$(eval $(call gb_CppunitTest_use_uiconfigs,sw_uibase_fldui, \
+    modules/swriter \
+))
+
+$(eval $(call gb_CppunitTest_use_more_fonts,sw_uibase_fldui))
+
+# vim: set noet sw=4 ts=4:
diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk
index 07a79c3ad951..793ed739daa4 100644
--- a/sw/Module_sw.mk
+++ b/sw/Module_sw.mk
@@ -131,6 +131,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\
     CppunitTest_sw_core_undo \
     CppunitTest_sw_uibase_uiview \
     CppunitTest_sw_core_draw \
+    CppunitTest_sw_uibase_fldui \
 ))
 
 ifneq ($(DISABLE_GUI),TRUE)
diff --git a/sw/qa/uibase/fldui/fldui.cxx b/sw/qa/uibase/fldui/fldui.cxx
new file mode 100644
index 000000000000..b3785f5ee072
--- /dev/null
+++ b/sw/qa/uibase/fldui/fldui.cxx
@@ -0,0 +1,98 @@
+/* -*- 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 <com/sun/star/text/BibliographyDataType.hpp>
+#include <com/sun/star/text/XTextDocument.hpp>
+
+#include <rtl/ustrbuf.hxx>
+#include <comphelper/propertyvalue.hxx>
+
+#include <docsh.hxx>
+#include <wrtsh.hxx>
+#include <fldmgr.hxx>
+#include <authfld.hxx>
+
+using namespace com::sun::star;
+
+namespace
+{
+/// Covers sw/source/uibase/fldui/ fixes.
+class Test : public SwModelTestBase
+{
+};
+
+CPPUNIT_TEST_FIXTURE(Test, testBiblioPageNumberUpdate)
+{
+    // Given a document with 2 biblio fields, same properties, but different page number in the URL:
+    SwDoc* pDoc = createSwDoc();
+    uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY);
+    uno::Reference<beans::XPropertySet> xField(
+        xFactory->createInstance("com.sun.star.text.TextField.Bibliography"), uno::UNO_QUERY);
+    uno::Sequence<beans::PropertyValue> aFields = {
+        comphelper::makePropertyValue("BibiliographicType", text::BibliographyDataType::WWW),
+        comphelper::makePropertyValue("Identifier", OUString("AT")),
+        comphelper::makePropertyValue("Author", OUString("Author")),
+        comphelper::makePropertyValue("Title", OUString("Title")),
+        comphelper::makePropertyValue("URL", OUString("http://www.example.com/test.pdf#page=1")),
+    };
+    xField->setPropertyValue("Fields", uno::makeAny(aFields));
+    uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
+    uno::Reference<text::XText> xText = xTextDocument->getText();
+    uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor();
+    uno::Reference<text::XTextContent> xContent(xField, uno::UNO_QUERY);
+    xText->insertTextContent(xCursor, xContent, /*bAbsorb=*/false);
+    xField.set(xFactory->createInstance("com.sun.star.text.TextField.Bibliography"),
+               uno::UNO_QUERY);
+    aFields = {
+        comphelper::makePropertyValue("BibiliographicType", text::BibliographyDataType::WWW),
+        comphelper::makePropertyValue("Identifier", OUString("AT")),
+        comphelper::makePropertyValue("Author", OUString("Author")),
+        comphelper::makePropertyValue("Title", OUString("Title")),
+        comphelper::makePropertyValue("URL", OUString("http://www.example.com/test.pdf#page=2")),
+    };
+    xField->setPropertyValue("Fields", uno::makeAny(aFields));
+    xContent.set(xField, uno::UNO_QUERY);
+    xText->insertTextContent(xCursor, xContent, /*bAbsorb=*/false);
+
+    // When changing the page number in the second field's URL:
+    SwDocShell* pDocShell = pDoc->GetDocShell();
+    SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
+    pWrtShell->SttEndDoc(/*bStt=*/false);
+    pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/false, 1, /*bBasicCall=*/false);
+    OUString aCoreFields[AUTH_FIELD_END];
+    aCoreFields[AUTH_FIELD_AUTHORITY_TYPE] = OUString::number(text::BibliographyDataType::WWW);
+    aCoreFields[AUTH_FIELD_IDENTIFIER] = "AT";
+    aCoreFields[AUTH_FIELD_AUTHOR] = "Author";
+    aCoreFields[AUTH_FIELD_TITLE] = "Title";
+    OUString aNewUrl = "http://www.example.com/test.pdf#page=42";
+    aCoreFields[AUTH_FIELD_URL] = aNewUrl;
+    OUStringBuffer aFieldBuffer;
+    for (const auto& rField : aCoreFields)
+    {
+        aFieldBuffer.append(rField).append(TOX_STYLE_DELIMITER);
+    }
+    SwFieldMgr aMgr(pWrtShell);
+    aMgr.UpdateCurField(0, aFieldBuffer.makeStringAndClear(), OUString());
+
+    // Then make sure that the second field's URL is updated:
+    auto pField = static_cast<SwAuthorityField*>(pWrtShell->GetCurField());
+    const SwAuthEntry* pEntry = pField->GetAuthEntry();
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: http://www.example.com/test.pdf#page=42
+    // - Actual  : http://www.example.com/test.pdf#page=2
+    // i.e. the second biblio field's URL was not updated.
+    CPPUNIT_ASSERT_EQUAL(aNewUrl, pEntry->GetAuthorField(AUTH_FIELD_URL));
+}
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/fldui/fldmgr.cxx b/sw/source/uibase/fldui/fldmgr.cxx
index 6609c454038a..90b12e34c32d 100644
--- a/sw/source/uibase/fldui/fldmgr.cxx
+++ b/sw/source/uibase/fldui/fldmgr.cxx
@@ -67,6 +67,7 @@
 #include <strings.hrc>
 #include <tox.hxx>
 #include <viewopt.hxx>
+#include <txmsrt.hxx>
 #include <unotools/useroptions.hxx>
 
 using namespace com::sun::star::uno;
@@ -1644,6 +1645,38 @@ void SwFieldMgr::UpdateCurField(sal_uInt32 nFormat,
             for( sal_Int32 i = 0, nIdx = 0; i < AUTH_FIELD_END; ++i )
                 xTempEntry->SetAuthorField( static_cast<ToxAuthorityField>(i),
                                 rPar1.getToken( 0, TOX_STYLE_DELIMITER, nIdx ));
+
+            // If just the page number of the URL changed, then update the current field and not
+            // others.
+            bool bEquivalent = true;
+            for (int i = 0; i < AUTH_FIELD_END; ++i)
+            {
+                auto eField = static_cast<ToxAuthorityField>(i);
+                if (eField == AUTH_FIELD_URL)
+                {
+                    if (SwTOXAuthority::GetSourceURL(xTempEntry->GetAuthorField(AUTH_FIELD_URL))
+                        != SwTOXAuthority::GetSourceURL(
+                               pAuthorityField->GetFieldText(AUTH_FIELD_URL)))
+                    {
+                        bEquivalent = false;
+                        break;
+                    }
+                }
+                else
+                {
+                    if (xTempEntry->GetAuthorField(eField) != pAuthorityField->GetFieldText(eField))
+                    {
+                        bEquivalent = false;
+                        break;
+                    }
+                }
+            }
+
+            if (bEquivalent)
+            {
+                break;
+            }
+
             if( pAuthorityType->ChangeEntryContent( xTempEntry.get() ) )
             {
                 pType->UpdateFields();


More information about the Libreoffice-commits mailing list