sw/qa/extras/tiledrendering/tiledrendering.cxx | 7 + sw/source/uibase/uiview/viewsrch.cxx | 92 +++++++++++++------------ 2 files changed, 57 insertions(+), 42 deletions(-)
New commits: commit 58c38e7ea5debc5440f1d81acf38d8d6ad0883d8 Author: Miklos Vajna <vmik...@collabora.co.uk> Date: Tue Oct 6 14:17:43 2015 +0200 sw tiled rendering: emit LOK_CALLBACK_SEARCH_RESULT* for normal search We used to emit these for find-all only, for no good reason. Change-Id: Id07dc7649f9a8528b9d4ec16d5f7c651fd607111 diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index 2fd27dd..1eb57de 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -342,7 +342,10 @@ void lcl_search(bool bBackward) void SwTiledRenderingTest::testSearch() { #if !defined(WNT) && !defined(MACOSX) + comphelper::LibreOfficeKit::setActive(); + SwXTextDocument* pXTextDocument = createDoc("search.odt"); + pXTextDocument->registerCallback(&SwTiledRenderingTest::callback, this); SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell(); size_t nNode = pWrtShell->getShellCrsr(false)->Start()->nNode.GetNode().GetIndex(); @@ -351,6 +354,8 @@ void SwTiledRenderingTest::testSearch() CPPUNIT_ASSERT(!pWrtShell->GetDrawView()->GetTextEditObject()); size_t nActual = pWrtShell->getShellCrsr(false)->Start()->nNode.GetNode().GetIndex(); CPPUNIT_ASSERT_EQUAL(nNode + 1, nActual); + /// Make sure we get search result selection for normal find as well, not only find all. + CPPUNIT_ASSERT(!m_aSearchResultSelection.empty()); // Next hit, in the shape. lcl_search(false); @@ -375,6 +380,8 @@ void SwTiledRenderingTest::testSearch() CPPUNIT_ASSERT(!pWrtShell->GetDrawView()->GetTextEditObject()); nActual = pWrtShell->getShellCrsr(false)->Start()->nNode.GetNode().GetIndex(); CPPUNIT_ASSERT_EQUAL(nNode + 1, nActual); + + comphelper::LibreOfficeKit::setActive(false); #endif } diff --git a/sw/source/uibase/uiview/viewsrch.cxx b/sw/source/uibase/uiview/viewsrch.cxx index 7d34a2a..3427fe4 100644 --- a/sw/source/uibase/uiview/viewsrch.cxx +++ b/sw/source/uibase/uiview/viewsrch.cxx @@ -253,7 +253,11 @@ void SwView::ExecSearch(SfxRequest& rReq, bool bNoMessage) { bool bRet = SearchAndWrap(bApi); if( bRet ) + { Scroll(m_pWrtShell->GetCharRect().SVRect()); + if (comphelper::LibreOfficeKit::isActive()) + lcl_emitSearchResultCallbacks(1, m_pSrchItem, m_pWrtShell); + } rReq.SetReturnValue(SfxBoolItem(nSlot, bRet)); #if HAVE_FEATURE_DESKTOP { commit ca8016c3a317a7ba1f03e117d575fb78a572b4b3 Author: Miklos Vajna <vmik...@collabora.co.uk> Date: Tue Oct 6 12:29:33 2015 +0200 sw: extract lcl_emitSearchResultCallbacks() from SwView::ExecSearch() Change-Id: I9c6b7540bcae85d6529e5cc195a7e86f58ee5713 diff --git a/sw/source/uibase/uiview/viewsrch.cxx b/sw/source/uibase/uiview/viewsrch.cxx index 0b07ce5..7d34a2a 100644 --- a/sw/source/uibase/uiview/viewsrch.cxx +++ b/sw/source/uibase/uiview/viewsrch.cxx @@ -102,6 +102,51 @@ static void lcl_addContainerToJson(boost::property_tree::ptree& rTree, const OSt rTree.add_child(rKey.getStr(), aChildren); } +/// Emits LOK callbacks (count, selection) for search results. +static void lcl_emitSearchResultCallbacks(sal_uInt16 nFound, SvxSearchItem* pSearchItem, SwWrtShell* pWrtShell) +{ + OString aPayload = OString::number(nFound) + ";" + pSearchItem->GetSearchString().toUtf8(); + pWrtShell->libreOfficeKitCallback(LOK_CALLBACK_SEARCH_RESULT_COUNT, aPayload.getStr()); + + // Emit a callback also about the selection rectangles, grouped by matches. + if (SwPaM* pPaM = pWrtShell->GetCrsr()) + { + std::vector<OString> aMatches; + for (SwPaM& rPaM : pPaM->GetRingContainer()) + { + if (SwShellCrsr* pShellCrsr = dynamic_cast<SwShellCrsr*>(&rPaM)) + { + std::vector<OString> aSelectionRectangles; + pShellCrsr->SwSelPaintRects::Show(&aSelectionRectangles); + std::stringstream ss; + bool bFirst = true; + for (size_t i = 0; i < aSelectionRectangles.size(); ++i) + { + const OString& rSelectionRectangle = aSelectionRectangles[i]; + if (rSelectionRectangle.isEmpty()) + continue; + if (bFirst) + bFirst = false; + else + ss << "; "; + ss << rSelectionRectangle.getStr(); + } + OString sRect = ss.str().c_str(); + aMatches.push_back(sRect); + } + } + boost::property_tree::ptree aTree; + aTree.put("searchString", pSearchItem->GetSearchString().toUtf8().getStr()); + lcl_addContainerToJson(aTree, "searchResultSelection", aMatches); + + std::stringstream aStream; + boost::property_tree::write_json(aStream, aTree); + aPayload = aStream.str().c_str(); + + pWrtShell->libreOfficeKitCallback(LOK_CALLBACK_SEARCH_RESULT_SELECTION, aPayload.getStr()); + } +} + void SwView::ExecSearch(SfxRequest& rReq, bool bNoMessage) { const SfxItemSet* pArgs = rReq.GetArgs(); @@ -241,48 +286,7 @@ void SwView::ExecSearch(SfxRequest& rReq, bool bNoMessage) m_bFound = false; } else if (comphelper::LibreOfficeKit::isActive()) - { - OString aPayload = OString::number(nFound) + ";" + m_pSrchItem->GetSearchString().toUtf8(); - m_pWrtShell->libreOfficeKitCallback(LOK_CALLBACK_SEARCH_RESULT_COUNT, aPayload.getStr()); - - // Emit a callback also about the selection rectangles, grouped by matches. - if (SwPaM* pPaM = m_pWrtShell->GetCrsr()) - { - std::vector<OString> aMatches; - for (SwPaM& rPaM : pPaM->GetRingContainer()) - { - if (SwShellCrsr* pShellCrsr = dynamic_cast<SwShellCrsr*>(&rPaM)) - { - std::vector<OString> aSelectionRectangles; - pShellCrsr->SwSelPaintRects::Show(&aSelectionRectangles); - std::stringstream ss; - bool bFirst = true; - for (size_t i = 0; i < aSelectionRectangles.size(); ++i) - { - const OString& rSelectionRectangle = aSelectionRectangles[i]; - if (rSelectionRectangle.isEmpty()) - continue; - if (bFirst) - bFirst = false; - else - ss << "; "; - ss << rSelectionRectangle.getStr(); - } - OString sRect = ss.str().c_str(); - aMatches.push_back(sRect); - } - } - boost::property_tree::ptree aTree; - aTree.put("searchString", m_pSrchItem->GetSearchString().toUtf8().getStr()); - lcl_addContainerToJson(aTree, "searchResultSelection", aMatches); - - std::stringstream aStream; - boost::property_tree::write_json(aStream, aTree); - aPayload = aStream.str().c_str(); - - m_pWrtShell->libreOfficeKitCallback(LOK_CALLBACK_SEARCH_RESULT_SELECTION, aPayload.getStr()); - } - } + lcl_emitSearchResultCallbacks(nFound, m_pSrchItem, m_pWrtShell); rReq.SetReturnValue(SfxBoolItem(nSlot, bRet)); #if HAVE_FEATURE_DESKTOP { _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits