sw/qa/uibase/uno/uno.cxx          |   28 ++++++++++++++++++++++++++
 sw/source/uibase/inc/frmpage.hxx  |    2 +
 sw/source/uibase/uno/loktxdoc.cxx |   40 ++++++++++++++++++++++++++++++++++++--
 3 files changed, 68 insertions(+), 2 deletions(-)

New commits:
commit 2ddd41b420cea7f1b988f0b8acbca564b2811382
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Mon Jan 9 13:53:35 2023 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue Jan 10 07:06:00 2023 +0000

    sw, lok: implement a getCommandValues(Sections)
    
    There was no LOK API to get a list of all sections where the name
    matches a certain prefix.
    
    This is useful in case the API client wants to know what previously
    inserted sections were deleted by the user as part of deleting text
    content.
    
    Add a new getCommandValues(".uno:Sections") that returns the names of
    matching sections. Do not return the section text, assuming that would
    be updated by the API client anyway.
    
    In practice this is needed by Zotero in case it wants to model its
    bibliography items with sections.
    
    Change-Id: If4f02d2a27f2328020934b319d30561aeaaf6612
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145207
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/qa/uibase/uno/uno.cxx b/sw/qa/uibase/uno/uno.cxx
index a23f6e0f4968..b9158c44426d 100644
--- a/sw/qa/uibase/uno/uno.cxx
+++ b/sw/qa/uibase/uno/uno.cxx
@@ -413,6 +413,34 @@ CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testGetTextFormField)
                          aTree.get<std::string>("command"));
 }
 
+CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testGetSections)
+{
+    // Given a document with a section:
+    createSwDoc();
+    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);
+
+    // When asking for a list of section names:
+    tools::JsonWriter aJsonWriter;
+    std::string_view aCommand(".uno:Sections?namePrefix=ZOTERO_BIBL");
+    auto pXTextDocument = dynamic_cast<SwXTextDocument*>(mxComponent.get());
+    pXTextDocument->getCommandValues(aJsonWriter, aCommand);
+
+    // Make sure we find our just inserted section:
+    std::unique_ptr<char[], o3tl::free_delete> 
pJSON(aJsonWriter.extractData());
+    std::stringstream aStream(pJSON.get());
+    boost::property_tree::ptree aTree;
+    boost::property_tree::read_json(aStream, aTree);
+    // Without the accompanying fix in place, this test would have failed with:
+    // - No such node (sections)
+    // i.e. the returned JSON was an empty object.
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), 
aTree.get_child("sections").count(""));
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/uno/loktxdoc.cxx 
b/sw/source/uibase/uno/loktxdoc.cxx
index ec0e9303527d..9c92d071e27e 100644
--- a/sw/source/uibase/uno/loktxdoc.cxx
+++ b/sw/source/uibase/uno/loktxdoc.cxx
@@ -289,13 +289,44 @@ void GetFields(tools::JsonWriter& rJsonWriter, 
SwDocShell* pDocShell,
         rJsonWriter.put("name", pRefMark->GetRefName());
     }
 }
+
+/// Implements getCommandValues(".uno:Sections").
+///
+/// Parameters:
+///
+/// - namePrefix: field name prefix to not return all sections
+void GetSections(tools::JsonWriter& rJsonWriter, SwDocShell* pDocShell,
+                 const std::map<OUString, OUString>& rArguments)
+{
+    OUString aNamePrefix;
+    {
+        auto it = rArguments.find("namePrefix");
+        if (it != rArguments.end())
+        {
+            aNamePrefix = it->second;
+        }
+    }
+
+    SwDoc* pDoc = pDocShell->GetDoc();
+    tools::ScopedJsonWriterArray aBookmarks = 
rJsonWriter.startArray("sections");
+    for (const auto& pSection : pDoc->GetSections())
+    {
+        if (!pSection->GetName().startsWith(aNamePrefix))
+        {
+            continue;
+        }
+
+        tools::ScopedJsonWriterStruct aProperty = rJsonWriter.startStruct();
+        rJsonWriter.put("name", pSection->GetName());
+    }
+}
 }
 
 bool SwXTextDocument::supportsCommandValues(std::u16string_view rCommand)
 {
     static const std::initializer_list<std::u16string_view> vForward
-        = { u"TextFormFields", u"TextFormField", u"SetDocumentProperties", 
u"Bookmarks",
-            u"Fields" };
+        = { u"TextFormFields", u"TextFormField", u"SetDocumentProperties",
+            u"Bookmarks",      u"Fields",        u"Sections" };
 
     return std::find(vForward.begin(), vForward.end(), rCommand) != 
vForward.end();
 }
@@ -309,6 +340,7 @@ void SwXTextDocument::getCommandValues(tools::JsonWriter& 
rJsonWriter, std::stri
     static constexpr OStringLiteral 
aSetDocumentProperties(".uno:SetDocumentProperties");
     static constexpr OStringLiteral aBookmarks(".uno:Bookmarks");
     static constexpr OStringLiteral aFields(".uno:Fields");
+    static constexpr OStringLiteral aSections(".uno:Sections");
 
     INetURLObject aParser(OUString::fromUtf8(rCommand));
     OUString aArguments = aParser.GetParam();
@@ -352,6 +384,10 @@ void SwXTextDocument::getCommandValues(tools::JsonWriter& 
rJsonWriter, std::stri
     {
         GetFields(rJsonWriter, m_pDocShell, aMap);
     }
+    else if (o3tl::starts_with(rCommand, aSections))
+    {
+        GetSections(rJsonWriter, m_pDocShell, aMap);
+    }
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 42238045c24f51fa1013f4bfe444c31455edda3e
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Mon Jan 9 20:47:13 2023 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue Jan 10 07:05:46 2023 +0000

    sw: document SwGrfExtPage
    
    It's created by SwFrameDlg and this is one of the tabpages which are
    only there for images, not for frames.
    
    Change-Id: I1f3740e683413a2dad2bb124c843b170b45c90e4
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145242
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/source/uibase/inc/frmpage.hxx b/sw/source/uibase/inc/frmpage.hxx
index db74d967ae3e..8aca87d35293 100644
--- a/sw/source/uibase/inc/frmpage.hxx
+++ b/sw/source/uibase/inc/frmpage.hxx
@@ -192,6 +192,8 @@ public:
     void            EnableVerticalPositioning( bool bEnable );
 };
 
+/// Tabpage providing the functionality behind Format -> Image -> Properties 
and then the Rotation
+/// tabpage.
 class SwGrfExtPage final : public SfxTabPage
 {
     OUString        m_aFilterName;

Reply via email to