Kaydet (Commit) 6ed1d969 authored tarafından Miklos Vajna's avatar Miklos Vajna

sd tiled rendering: initial search all

Change-Id: Icee3a07103fad1bf70637fbf23299f50b7ad838d
(cherry picked from commit 32d573cd)
üst 675d86e8
...@@ -357,11 +357,14 @@ private: ...@@ -357,11 +357,14 @@ private:
bool SearchAndReplaceAll(); bool SearchAndReplaceAll();
/** Do search and replace for next match. /** Do search and replace for next match.
@param pSelections
When tiled rendering and not 0, then don't emit LOK events, instead
assume the caller will do so.
@return @return
The return value specifies whether the search ended (</sal_True>) or The return value specifies whether the search ended (</sal_True>) or
another call to this method is required (</sal_False>). another call to this method is required (</sal_False>).
*/ */
bool SearchAndReplaceOnce(); bool SearchAndReplaceOnce(std::vector<OString>* pSelections = 0);
/** Detect changes of the document or view and react accordingly. Such /** Detect changes of the document or view and react accordingly. Such
changes may occur because different calls to changes may occur because different calls to
......
...@@ -490,7 +490,7 @@ bool Outliner::StartSearchAndReplace (const SvxSearchItem* pSearchItem) ...@@ -490,7 +490,7 @@ bool Outliner::StartSearchAndReplace (const SvxSearchItem* pSearchItem)
Initialize ( ! mpSearchItem->GetBackward()); Initialize ( ! mpSearchItem->GetBackward());
const SvxSearchCmd nCommand (mpSearchItem->GetCommand()); const SvxSearchCmd nCommand (mpSearchItem->GetCommand());
if (nCommand == SvxSearchCmd::REPLACE_ALL) if (nCommand == SvxSearchCmd::FIND_ALL || nCommand == SvxSearchCmd::REPLACE_ALL)
bEndOfSearch = SearchAndReplaceAll (); bEndOfSearch = SearchAndReplaceAll ();
else else
{ {
...@@ -621,11 +621,32 @@ bool Outliner::SearchAndReplaceAll() ...@@ -621,11 +621,32 @@ bool Outliner::SearchAndReplaceAll()
// Search/replace until the end of the document is reached. // Search/replace until the end of the document is reached.
bool bFoundMatch; bool bFoundMatch;
std::vector<OString> aSelections;
do do
{ {
bFoundMatch = ! SearchAndReplaceOnce(); bFoundMatch = ! SearchAndReplaceOnce(&aSelections);
} }
while (bFoundMatch); while (bFoundMatch);
if (mpSearchItem->GetCommand() == SvxSearchCmd::FIND_ALL && pViewShell->GetDoc()->isTiledRendering() && !aSelections.empty())
{
boost::property_tree::ptree aTree;
aTree.put("searchString", mpSearchItem->GetSearchString().toUtf8().getStr());
boost::property_tree::ptree aChildren;
for (const OString& rSelection : aSelections)
{
boost::property_tree::ptree aChild;
aChild.put("", rSelection.getStr());
aChildren.push_back(std::make_pair("", aChild));
}
aTree.add_child("searchResultSelection", aChildren);
std::stringstream aStream;
boost::property_tree::write_json(aStream, aTree);
OString aPayload = aStream.str().c_str();
pViewShell->GetDoc()->libreOfficeKitCallback(LOK_CALLBACK_SEARCH_RESULT_SELECTION, aPayload.getStr());
}
} }
RestoreStartPosition (); RestoreStartPosition ();
...@@ -634,7 +655,7 @@ bool Outliner::SearchAndReplaceAll() ...@@ -634,7 +655,7 @@ bool Outliner::SearchAndReplaceAll()
return true; return true;
} }
bool Outliner::SearchAndReplaceOnce() bool Outliner::SearchAndReplaceOnce(std::vector<OString>* pSelections)
{ {
DetectChange (); DetectChange ();
...@@ -724,30 +745,38 @@ bool Outliner::SearchAndReplaceOnce() ...@@ -724,30 +745,38 @@ bool Outliner::SearchAndReplaceOnce()
if (pViewShell && pViewShell->GetDoc()->isTiledRendering() && mbStringFound) if (pViewShell && pViewShell->GetDoc()->isTiledRendering() && mbStringFound)
{ {
// notify LibreOfficeKit about changed page
OString aPayload = OString::number(maCurrentPosition.mnPageIndex);
pViewShell->GetDoc()->libreOfficeKitCallback(LOK_CALLBACK_SET_PART, aPayload.getStr());
// also about search result selections
std::vector<Rectangle> aLogicRects; std::vector<Rectangle> aLogicRects;
pOutlinerView->GetSelectionRectangles(aLogicRects); pOutlinerView->GetSelectionRectangles(aLogicRects);
boost::property_tree::ptree aTree;
aTree.put("searchString", mpSearchItem->GetSearchString().toUtf8().getStr());
std::vector<OString> aLogicRectStrings; std::vector<OString> aLogicRectStrings;
std::transform(aLogicRects.begin(), aLogicRects.end(), std::back_inserter(aLogicRectStrings), [](const Rectangle& rRectangle) { return rRectangle.toString(); }); std::transform(aLogicRects.begin(), aLogicRects.end(), std::back_inserter(aLogicRectStrings), [](const Rectangle& rRectangle) { return rRectangle.toString(); });
OString sRectangles = comphelper::string::join("; ", aLogicRectStrings); OString sRectangles = comphelper::string::join("; ", aLogicRectStrings);
boost::property_tree::ptree aChildren;
boost::property_tree::ptree aChild; if (!pSelections)
aChild.put("", sRectangles.getStr()); {
aChildren.push_back(std::make_pair("", aChild)); // notify LibreOfficeKit about changed page
aTree.add_child("searchResultSelection", aChildren); OString aPayload = OString::number(maCurrentPosition.mnPageIndex);
pViewShell->GetDoc()->libreOfficeKitCallback(LOK_CALLBACK_SET_PART, aPayload.getStr());
std::stringstream aStream;
boost::property_tree::write_json(aStream, aTree); // also about search result selections
aPayload = aStream.str().c_str(); boost::property_tree::ptree aTree;
pViewShell->GetDoc()->libreOfficeKitCallback(LOK_CALLBACK_SEARCH_RESULT_SELECTION, aPayload.getStr()); aTree.put("searchString", mpSearchItem->GetSearchString().toUtf8().getStr());
boost::property_tree::ptree aChildren;
boost::property_tree::ptree aChild;
aChild.put("", 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();
pViewShell->GetDoc()->libreOfficeKitCallback(LOK_CALLBACK_SEARCH_RESULT_SELECTION, aPayload.getStr());
}
else
{
pSelections->push_back(sRectangles);
}
} }
return mbEndOfSearch; return mbEndOfSearch;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment