From 4b7f659b36d474ec2dbc5b4ddbe3e577dab8c1bf Mon Sep 17 00:00:00 2001 From: Michael Meeks Date: Fri, 4 Nov 2016 20:19:12 +0000 Subject: tdf#92160 - sc: limit search results to 1000 entries. Very large replace results give huge space consumption in the display widget, and are of dubious usefulness. Change-Id: Ib8ad01a673ea52976befaf958f8f695aca2190ae Reviewed-on: https://gerrit.libreoffice.org/30574 Reviewed-by: Michael Meeks Tested-by: Michael Meeks --- sc/source/ui/dialogs/searchresults.cxx | 73 ++++++++++++++++++++++++++++++---- sc/source/ui/inc/searchresults.hxx | 1 + sc/uiconfig/scalc/ui/searchresults.ui | 7 ++++ 3 files changed, 74 insertions(+), 7 deletions(-) diff --git a/sc/source/ui/dialogs/searchresults.cxx b/sc/source/ui/dialogs/searchresults.cxx index 9f6b54777b53..742c4724f2df 100644 --- a/sc/source/ui/dialogs/searchresults.cxx +++ b/sc/source/ui/dialogs/searchresults.cxx @@ -26,6 +26,8 @@ SearchResultsDlg::SearchResultsDlg( SfxBindings* _pBindings, vcl::Window* pParen ModelessDialog(pParent, "SearchResultsDialog", "modules/scalc/ui/searchresults.ui"), mpBindings(_pBindings), mpDoc(nullptr) { + get(mpLabel, "skipped"); + SvSimpleTableContainer *pContainer = get("results"); Size aControlSize(150, 120); aControlSize = pContainer->LogicToPixel(aControlSize, MAP_APPFONT); @@ -47,16 +49,73 @@ SearchResultsDlg::~SearchResultsDlg() void SearchResultsDlg::dispose() { mpList.disposeAndClear(); + mpLabel.disposeAndClear(); ModelessDialog::dispose(); } +namespace +{ + class ListWrapper { + size_t mnCount; + const size_t mnMaximum; + OUStringBuffer maName; + VclPtr mpLabel; + VclPtr mpList; + public: + ListWrapper(const VclPtr &pList, + const VclPtr &pLabel) : + mnCount(0), + mnMaximum(1000), + mpLabel(pLabel), + mpList(pList) + { + mpList->Clear(); + mpList->SetUpdateMode(false); + } + void Insert(const OUString &aTabName, + const ScAddress &rPos, + formula::FormulaGrammar::AddressConvention eConvention, + const OUString &aText) + { + if (mnCount++ < mnMaximum) + { + maName.append(aTabName); + maName.append("\t"); + maName.append(rPos.Format(SCA_ABS, nullptr, eConvention)); + maName.append("\t"); + maName.append(aText); + mpList->InsertEntry(maName.makeStringAndClear()); + } + } + void Update() + { + if (mnCount > mnMaximum) + { + if (mpLabel) + { + size_t nSkipped = mnCount - mnMaximum; + OUString aSkipped(mpLabel->GetText()); + mpList->InsertEntry( + aSkipped.replaceFirst("$1", OUString::number(nSkipped))); + } + } + mpList->SetUpdateMode(true); + } + }; +} + void SearchResultsDlg::FillResults( ScDocument* pDoc, const ScRangeList &rMatchedRanges ) { - mpList->Clear(); - mpList->SetUpdateMode(false); + ListWrapper aList(mpList, mpLabel); std::vector aTabNames = pDoc->GetAllTableNames(); SCTAB nTabCount = aTabNames.size(); - for (size_t i = 0, n = rMatchedRanges.size(); i < n; ++i) + + // tdf#92160 - too many results blow the widget's mind + size_t nMatchMax = rMatchedRanges.size(); + if (nMatchMax > 1000) + nMatchMax = 1000; + + for (size_t i = 0, n = nMatchMax; i < n; ++i) { ScCellIterator aIter(pDoc, *rMatchedRanges[i]); for (bool bHas = aIter.first(); bHas; bHas = aIter.next()) @@ -66,12 +125,12 @@ void SearchResultsDlg::FillResults( ScDocument* pDoc, const ScRangeList &rMatche // Out-of-bound sheet index. continue; - OUString aPosStr = aPos.Format(SCA_ABS, nullptr, pDoc->GetAddressConvention()); - mpList->InsertEntry(aTabNames[aPos.Tab()] + "\t" + aPosStr + "\t" + pDoc->GetString(aPos)); + aList.Insert(aTabNames[aPos.Tab()], aPos, + pDoc->GetAddressConvention(), + pDoc->GetString(aPos)); } } - mpList->SetUpdateMode(true); - + aList.Update(); mpDoc = pDoc; } diff --git a/sc/source/ui/inc/searchresults.hxx b/sc/source/ui/inc/searchresults.hxx index 8143c48d56b6..ea3a91bf6691 100644 --- a/sc/source/ui/inc/searchresults.hxx +++ b/sc/source/ui/inc/searchresults.hxx @@ -23,6 +23,7 @@ namespace sc { class SearchResultsDlg : public ModelessDialog { VclPtr mpList; + VclPtr mpLabel; SfxBindings* mpBindings; ScDocument* mpDoc; diff --git a/sc/uiconfig/scalc/ui/searchresults.ui b/sc/uiconfig/scalc/ui/searchresults.ui index c39408aa2a31..9ae863770ba7 100644 --- a/sc/uiconfig/scalc/ui/searchresults.ui +++ b/sc/uiconfig/scalc/ui/searchresults.ui @@ -53,6 +53,13 @@ 1 + + + False + False + skipped $1 ... + + -- cgit