Blame SOURCES/0185-sw-extract-lcl_emitSearchResultCallbacks-from-SwView.patch

135360
From 5a52abcc97428423885cb144e5380e825e082abb Mon Sep 17 00:00:00 2001
135360
From: Miklos Vajna <vmiklos@collabora.co.uk>
135360
Date: Tue, 6 Oct 2015 12:29:33 +0200
135360
Subject: [PATCH 185/398] sw: extract lcl_emitSearchResultCallbacks() from
135360
 SwView::ExecSearch()
135360
135360
Change-Id: I9c6b7540bcae85d6529e5cc195a7e86f58ee5713
135360
(cherry picked from commit ca8016c3a317a7ba1f03e117d575fb78a572b4b3)
135360
---
135360
 sw/source/uibase/uiview/viewsrch.cxx | 88 +++++++++++++++++++-----------------
135360
 1 file changed, 46 insertions(+), 42 deletions(-)
135360
135360
diff --git a/sw/source/uibase/uiview/viewsrch.cxx b/sw/source/uibase/uiview/viewsrch.cxx
135360
index 570fadeb561a..a22cbdb6528f 100644
135360
--- a/sw/source/uibase/uiview/viewsrch.cxx
135360
+++ b/sw/source/uibase/uiview/viewsrch.cxx
135360
@@ -102,6 +102,51 @@ static void lcl_addContainerToJson(boost::property_tree::ptree& rTree, const OSt
135360
     rTree.add_child(rKey.getStr(), aChildren);
135360
 }
135360
 
135360
+/// Emits LOK callbacks (count, selection) for search results.
135360
+static void lcl_emitSearchResultCallbacks(sal_uInt16 nFound, SvxSearchItem* pSearchItem, SwWrtShell* pWrtShell)
135360
+{
135360
+    OString aPayload = OString::number(nFound) + ";" + pSearchItem->GetSearchString().toUtf8();
135360
+    pWrtShell->libreOfficeKitCallback(LOK_CALLBACK_SEARCH_RESULT_COUNT, aPayload.getStr());
135360
+
135360
+    // Emit a callback also about the selection rectangles, grouped by matches.
135360
+    if (SwPaM* pPaM = pWrtShell->GetCrsr())
135360
+    {
135360
+        std::vector<OString> aMatches;
135360
+        for (SwPaM& rPaM : pPaM->GetRingContainer())
135360
+        {
135360
+            if (SwShellCrsr* pShellCrsr = dynamic_cast<SwShellCrsr*>(&rPaM))
135360
+            {
135360
+                std::vector<OString> aSelectionRectangles;
135360
+                pShellCrsr->SwSelPaintRects::Show(&aSelectionRectangles);
135360
+                std::stringstream ss;
135360
+                bool bFirst = true;
135360
+                for (size_t i = 0; i < aSelectionRectangles.size(); ++i)
135360
+                {
135360
+                    const OString& rSelectionRectangle = aSelectionRectangles[i];
135360
+                    if (rSelectionRectangle.isEmpty())
135360
+                        continue;
135360
+                    if (bFirst)
135360
+                        bFirst = false;
135360
+                    else
135360
+                        ss << "; ";
135360
+                    ss << rSelectionRectangle.getStr();
135360
+                }
135360
+                OString sRect = ss.str().c_str();
135360
+                aMatches.push_back(sRect);
135360
+            }
135360
+        }
135360
+        boost::property_tree::ptree aTree;
135360
+        aTree.put("searchString", pSearchItem->GetSearchString().toUtf8().getStr());
135360
+        lcl_addContainerToJson(aTree, "searchResultSelection", aMatches);
135360
+
135360
+        std::stringstream aStream;
135360
+        boost::property_tree::write_json(aStream, aTree);
135360
+        aPayload = aStream.str().c_str();
135360
+
135360
+        pWrtShell->libreOfficeKitCallback(LOK_CALLBACK_SEARCH_RESULT_SELECTION, aPayload.getStr());
135360
+    }
135360
+}
135360
+
135360
 void SwView::ExecSearch(SfxRequest& rReq, bool bNoMessage)
135360
 {
135360
     const SfxItemSet* pArgs = rReq.GetArgs();
135360
@@ -241,48 +286,7 @@ void SwView::ExecSearch(SfxRequest& rReq, bool bNoMessage)
135360
                     m_bFound = false;
135360
                 }
135360
                 else if (comphelper::LibreOfficeKit::isActive())
135360
-                {
135360
-                    OString aPayload = OString::number(nFound) + ";" + m_pSrchItem->GetSearchString().toUtf8();
135360
-                    m_pWrtShell->libreOfficeKitCallback(LOK_CALLBACK_SEARCH_RESULT_COUNT, aPayload.getStr());
135360
-
135360
-                    // Emit a callback also about the selection rectangles, grouped by matches.
135360
-                    if (SwPaM* pPaM = m_pWrtShell->GetCrsr())
135360
-                    {
135360
-                        std::vector<OString> aMatches;
135360
-                        for (SwPaM& rPaM : pPaM->GetRingContainer())
135360
-                        {
135360
-                            if (SwShellCrsr* pShellCrsr = dynamic_cast<SwShellCrsr*>(&rPaM))
135360
-                            {
135360
-                                std::vector<OString> aSelectionRectangles;
135360
-                                pShellCrsr->SwSelPaintRects::Show(&aSelectionRectangles);
135360
-                                std::stringstream ss;
135360
-                                bool bFirst = true;
135360
-                                for (size_t i = 0; i < aSelectionRectangles.size(); ++i)
135360
-                                {
135360
-                                    const OString& rSelectionRectangle = aSelectionRectangles[i];
135360
-                                    if (rSelectionRectangle.isEmpty())
135360
-                                        continue;
135360
-                                    if (bFirst)
135360
-                                        bFirst = false;
135360
-                                    else
135360
-                                        ss << "; ";
135360
-                                    ss << rSelectionRectangle.getStr();
135360
-                                }
135360
-                                OString sRect = ss.str().c_str();
135360
-                                aMatches.push_back(sRect);
135360
-                            }
135360
-                        }
135360
-                        boost::property_tree::ptree aTree;
135360
-                        aTree.put("searchString", m_pSrchItem->GetSearchString().toUtf8().getStr());
135360
-                        lcl_addContainerToJson(aTree, "searchResultSelection", aMatches);
135360
-
135360
-                        std::stringstream aStream;
135360
-                        boost::property_tree::write_json(aStream, aTree);
135360
-                        aPayload = aStream.str().c_str();
135360
-
135360
-                        m_pWrtShell->libreOfficeKitCallback(LOK_CALLBACK_SEARCH_RESULT_SELECTION, aPayload.getStr());
135360
-                    }
135360
-                }
135360
+                    lcl_emitSearchResultCallbacks(nFound, m_pSrchItem, m_pWrtShell);
135360
                 rReq.SetReturnValue(SfxBoolItem(nSlot, bRet));
135360
 #if HAVE_FEATURE_DESKTOP
135360
                 {
135360
-- 
135360
2.12.0
135360