diff options
author | Eike Rathke <erack@redhat.com> | 2016-07-28 00:43:03 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2016-07-28 00:50:15 +0200 |
commit | 4f719263ae8dc44eabfba4654f9dbed92a9c5360 (patch) | |
tree | 58082e261d0b9175ac42c873e5379c7bebc4ee86 | |
parent | d4cb9c3a8851cb874fd8b6c77d4d7521da7579b7 (diff) |
display the SearchAll() and ReplaceAll() results for notes, tdf#65334 related
Change-Id: Ib9ff40b26526efdf242db2ef1804e54611f16b0e
-rw-r--r-- | sc/source/ui/dialogs/searchresults.cxx | 55 | ||||
-rw-r--r-- | sc/source/ui/inc/searchresults.hxx | 2 | ||||
-rw-r--r-- | sc/source/ui/view/viewfun2.cxx | 3 |
3 files changed, 47 insertions, 13 deletions
diff --git a/sc/source/ui/dialogs/searchresults.cxx b/sc/source/ui/dialogs/searchresults.cxx index 225fb2f0318b..c6e747084a6f 100644 --- a/sc/source/ui/dialogs/searchresults.cxx +++ b/sc/source/ui/dialogs/searchresults.cxx @@ -50,24 +50,57 @@ void SearchResultsDlg::dispose() ModelessDialog::dispose(); } -void SearchResultsDlg::FillResults( ScDocument* pDoc, const ScRangeList &rMatchedRanges ) +void SearchResultsDlg::FillResults( ScDocument* pDoc, const ScRangeList &rMatchedRanges, bool bCellNotes ) { mpList->Clear(); mpList->SetUpdateMode(false); std::vector<OUString> aTabNames = pDoc->GetAllTableNames(); SCTAB nTabCount = aTabNames.size(); - for (size_t i = 0, n = rMatchedRanges.size(); i < n; ++i) + if (bCellNotes) { - ScCellIterator aIter(pDoc, *rMatchedRanges[i]); - for (bool bHas = aIter.first(); bHas; bHas = aIter.next()) + for (size_t i = 0, n = rMatchedRanges.size(); i < n; ++i) { - ScAddress aPos = aIter.GetPos(); - if (aPos.Tab() >= nTabCount) - // Out-of-bound sheet index. - continue; - - OUString aPosStr = aPos.Format(ScRefFlags::ADDR_ABS, nullptr, pDoc->GetAddressConvention()); - mpList->InsertEntry(aTabNames[aPos.Tab()] + "\t" + aPosStr + "\t" + pDoc->GetString(aPos)); + /* TODO: a CellNotes iterator would come handy and migt speed + * things up a little, though we only loop through the + * search/replace result positions here. */ + ScRange aRange( *rMatchedRanges[i] ); + // Bear in mind that mostly the range is one address position + // or a column or a row joined. + ScAddress aPos( aRange.aStart ); + for ( ; aPos.Tab() <= aRange.aEnd.Tab(); aPos.IncTab()) + { + if (aPos.Tab() >= nTabCount) + break; // can this even happen? we just searched on existing sheets ... + for (aPos.SetCol( aRange.aStart.Col()); aPos.Col() <= aRange.aEnd.Col(); aPos.IncCol()) + { + for (aPos.SetRow( aRange.aStart.Row()); aPos.Row() <= aRange.aEnd.Row(); aPos.IncRow()) + { + const ScPostIt* pNote = pDoc->GetNote( aPos); + if (pNote) + { + OUString aPosStr = aPos.Format(ScRefFlags::ADDR_ABS, nullptr, pDoc->GetAddressConvention()); + mpList->InsertEntry(aTabNames[aPos.Tab()] + "\t" + aPosStr + "\t" + pNote->GetText()); + } + } + } + } + } + } + else + { + for (size_t i = 0, n = rMatchedRanges.size(); i < n; ++i) + { + ScCellIterator aIter(pDoc, *rMatchedRanges[i]); + for (bool bHas = aIter.first(); bHas; bHas = aIter.next()) + { + ScAddress aPos = aIter.GetPos(); + if (aPos.Tab() >= nTabCount) + // Out-of-bound sheet index. + continue; + + OUString aPosStr = aPos.Format(ScRefFlags::ADDR_ABS, nullptr, pDoc->GetAddressConvention()); + mpList->InsertEntry(aTabNames[aPos.Tab()] + "\t" + aPosStr + "\t" + pDoc->GetString(aPos)); + } } } mpList->SetUpdateMode(true); diff --git a/sc/source/ui/inc/searchresults.hxx b/sc/source/ui/inc/searchresults.hxx index 8143c48d56b6..776a23f66df1 100644 --- a/sc/source/ui/inc/searchresults.hxx +++ b/sc/source/ui/inc/searchresults.hxx @@ -32,7 +32,7 @@ public: virtual ~SearchResultsDlg(); virtual void dispose() override; - void FillResults( ScDocument* pDoc, const ScRangeList& rMatchedRanges ); + void FillResults( ScDocument* pDoc, const ScRangeList& rMatchedRanges, bool bCellNotes ); virtual bool Close() override; }; diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx index 6a7a7e887e12..c6e2a9459e78 100644 --- a/sc/source/ui/view/viewfun2.cxx +++ b/sc/source/ui/view/viewfun2.cxx @@ -1748,7 +1748,8 @@ bool ScViewFunc::SearchAndReplace( const SvxSearchItem* pSearchItem, { sc::SearchResultsDlg* pDlg = static_cast<sc::SearchResultsDlg*>(pWnd->GetWindow()); if (pDlg) - pDlg->FillResults(&rDoc, aMatchedRanges); + pDlg->FillResults(&rDoc, aMatchedRanges, + pSearchItem->GetCellType() == SvxSearchCellType::NOTE); } } |