[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - sd/inc sd/source

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Tue Jun 9 12:01:35 UTC 2020


 sd/inc/Outliner.hxx            |    4 +
 sd/source/ui/view/Outliner.cxx |  110 ++++++++++++++++++++++-------------------
 2 files changed, 65 insertions(+), 49 deletions(-)

New commits:
commit 6eec4e40f6f8ea88d3136295d5485ee73ef7bf2c
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Wed May 27 14:07:10 2020 +0200
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Tue Jun 9 14:01:04 2020 +0200

    sd: move LOK search result logic to it's own method
    
    Change-Id: I67cbe4d3d63bffdab72c09b3a956f67806588348
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95306
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
    (cherry picked from commit e9dbdc9fc6ff943650e6e18986ed1cce913971ef)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95917
    Tested-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/sd/inc/Outliner.hxx b/sd/inc/Outliner.hxx
index d935d6f1d6a8..39e2720f6a01 100644
--- a/sd/inc/Outliner.hxx
+++ b/sd/inc/Outliner.hxx
@@ -355,6 +355,10 @@ private:
     */
     bool SearchAndReplaceOnce(std::vector<::sd::SearchSelection>* pSelections = nullptr);
 
+    void sendLOKSearchResultCallback(std::shared_ptr<sd::ViewShell>& pViewShell,
+                                     OutlinerView* pOutlinerView,
+                                     std::vector<sd::SearchSelection>* pSelections);
+
     /** Detect changes of the document or view and react accordingly.  Such
         changes may occur because different calls to
         <member>SearchAndReplace()</member> there usually is user
diff --git a/sd/source/ui/view/Outliner.cxx b/sd/source/ui/view/Outliner.cxx
index e7f676f43e4e..6e982f3d25f7 100644
--- a/sd/source/ui/view/Outliner.cxx
+++ b/sd/source/ui/view/Outliner.cxx
@@ -673,6 +673,66 @@ bool SdOutliner::SearchAndReplaceAll()
     return bRet;
 }
 
+void SdOutliner::sendLOKSearchResultCallback(std::shared_ptr<sd::ViewShell> & pViewShell,
+                                             OutlinerView* pOutlinerView,
+                                             std::vector<sd::SearchSelection>* pSelections)
+{
+    std::vector<::tools::Rectangle> aLogicRects;
+    pOutlinerView->GetSelectionRectangles(aLogicRects);
+
+    // convert to twips if in 100thmm (seems as if LibreOfficeKit is based on twips?). Do this
+    // here where we have the only place needing this, *not* in ImpEditView::GetSelectionRectangles
+    // which makes that method unusable for others
+    if (pOutlinerView->GetWindow() && MapUnit::Map100thMM == pOutlinerView->GetWindow()->GetMapMode().GetMapUnit())
+    {
+        for (tools::Rectangle& rRectangle : aLogicRects)
+        {
+            rRectangle = OutputDevice::LogicToLogic(rRectangle, MapMode(MapUnit::Map100thMM), MapMode(MapUnit::MapTwip));
+        }
+    }
+
+    std::vector<OString> aLogicRectStrings;
+    std::transform(aLogicRects.begin(), aLogicRects.end(), std::back_inserter(aLogicRectStrings),
+        [](const ::tools::Rectangle& rRectangle)
+    {
+        return rRectangle.toString();
+    });
+
+    OString sRectangles = comphelper::string::join("; ", aLogicRectStrings);
+
+    if (!pSelections)
+    {
+        // notify LibreOfficeKit about changed page
+        OString aPayload = OString::number(maCurrentPosition.mnPageIndex);
+        SfxViewShell& rSfxViewShell = pViewShell->GetViewShellBase();
+        rSfxViewShell.libreOfficeKitViewCallback(LOK_CALLBACK_SET_PART, aPayload.getStr());
+
+        // also about search result selections
+        boost::property_tree::ptree aTree;
+        aTree.put("searchString", mpSearchItem->GetSearchString().toUtf8().getStr());
+        aTree.put("highlightAll", false);
+
+        boost::property_tree::ptree aChildren;
+        boost::property_tree::ptree aChild;
+        aChild.put("part", OString::number(maCurrentPosition.mnPageIndex).getStr());
+        aChild.put("rectangles", sRectangles.getStr());
+        aChildren.push_back(std::make_pair("", aChild));
+        aTree.add_child("searchResultSelection", aChildren);
+
+        std::stringstream aStream;
+        boost::property_tree::write_json(aStream, aTree);
+        aPayload = aStream.str().c_str();
+        rSfxViewShell.libreOfficeKitViewCallback(LOK_CALLBACK_SEARCH_RESULT_SELECTION, aPayload.getStr());
+    }
+    else
+    {
+        sd::SearchSelection aSelection(maCurrentPosition.mnPageIndex, sRectangles);
+        bool bDuplicate = !pSelections->empty() && pSelections->back() == aSelection;
+        if (!bDuplicate)
+            pSelections->push_back(aSelection);
+    }
+}
+
 bool SdOutliner::SearchAndReplaceOnce(std::vector<sd::SearchSelection>* pSelections)
 {
     DetectChange ();
@@ -764,55 +824,7 @@ bool SdOutliner::SearchAndReplaceOnce(std::vector<sd::SearchSelection>* pSelecti
 
     if (pViewShell && comphelper::LibreOfficeKit::isActive() && mbStringFound)
     {
-        std::vector<::tools::Rectangle> aLogicRects;
-        pOutlinerView->GetSelectionRectangles(aLogicRects);
-
-        // convert to twips if in 100thmm (seems as if LibreOfficeKit is based on twips?). Do this
-        // here where we have the only place needing this, *not* in ImpEditView::GetSelectionRectangles
-        // which makes that method unusable for others
-        if (pOutlinerView->GetWindow() && MapUnit::Map100thMM == pOutlinerView->GetWindow()->GetMapMode().GetMapUnit())
-        {
-            for (tools::Rectangle& rRectangle : aLogicRects)
-            {
-                rRectangle = OutputDevice::LogicToLogic(rRectangle, MapMode(MapUnit::Map100thMM), MapMode(MapUnit::MapTwip));
-            }
-        }
-
-        std::vector<OString> aLogicRectStrings;
-        std::transform(aLogicRects.begin(), aLogicRects.end(), std::back_inserter(aLogicRectStrings), [](const ::tools::Rectangle& rRectangle) { return rRectangle.toString(); });
-        OString sRectangles = comphelper::string::join("; ", aLogicRectStrings);
-
-        if (!pSelections)
-        {
-            // notify LibreOfficeKit about changed page
-            OString aPayload = OString::number(maCurrentPosition.mnPageIndex);
-            SfxViewShell& rSfxViewShell = pViewShell->GetViewShellBase();
-            rSfxViewShell.libreOfficeKitViewCallback(LOK_CALLBACK_SET_PART, aPayload.getStr());
-
-            // also about search result selections
-            boost::property_tree::ptree aTree;
-            aTree.put("searchString", mpSearchItem->GetSearchString().toUtf8().getStr());
-            aTree.put("highlightAll", false);
-
-            boost::property_tree::ptree aChildren;
-            boost::property_tree::ptree aChild;
-            aChild.put("part", OString::number(maCurrentPosition.mnPageIndex).getStr());
-            aChild.put("rectangles", sRectangles.getStr());
-            aChildren.push_back(std::make_pair("", aChild));
-            aTree.add_child("searchResultSelection", aChildren);
-
-            std::stringstream aStream;
-            boost::property_tree::write_json(aStream, aTree);
-            aPayload = aStream.str().c_str();
-            rSfxViewShell.libreOfficeKitViewCallback(LOK_CALLBACK_SEARCH_RESULT_SELECTION, aPayload.getStr());
-        }
-        else
-        {
-            sd::SearchSelection aSelection(maCurrentPosition.mnPageIndex, sRectangles);
-            bool bDuplicate = !pSelections->empty() && pSelections->back() == aSelection;
-            if (!bDuplicate)
-                pSelections->push_back(aSelection);
-        }
+        sendLOKSearchResultCallback(pViewShell, pOutlinerView, pSelections);
     }
 
     return mbEndOfSearch;


More information about the Libreoffice-commits mailing list