summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2021-08-09 01:04:56 +0200
committerEike Rathke <erack@redhat.com>2021-08-09 02:24:54 +0200
commit1c5b3cb3dd4dab6b0db409b6cc75b3111103820f (patch)
tree11e63b9c6974879ad0c1206e752bc263648cc293
parentd1f1f546b212ecd651146addeb328806bb270d5f (diff)
Related: tdf#143759 Display results of find empty or replace to empty
Searching for empty cells or replacing to empty cells didn't list the results because ScCellIterator iterates over cells with content only. Change-Id: If6ea65f853cae621e54ce545fe7fbed2b445fd14 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120189 Reviewed-by: Eike Rathke <erack@redhat.com> Tested-by: Jenkins
-rw-r--r--sc/inc/document.hxx1
-rw-r--r--sc/source/core/data/documen3.cxx8
-rw-r--r--sc/source/core/data/table6.cxx11
-rw-r--r--sc/source/ui/dialogs/searchresults.cxx25
-rw-r--r--sc/source/ui/inc/searchresults.hxx2
-rw-r--r--sc/source/ui/view/viewfun2.cxx13
6 files changed, 42 insertions, 18 deletions
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 0706cd2b4a07..2038e9d59725 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -1862,6 +1862,7 @@ public:
SCCOL& rCol, SCROW& rRow, SCTAB& rTab,
const ScMarkData& rMark, ScRangeList& rMatchedRanges,
OUString& rUndoStr, ScDocument* pUndoDoc = nullptr );
+ static bool IsEmptyCellSearch( const SvxSearchItem& rSearchItem );
// determine Col/Row of subsequent calls
// (e.g. not found from the beginning, or subsequent tables)
diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx
index 8d6f6a2baadf..6ab518566663 100644
--- a/sc/source/core/data/documen3.cxx
+++ b/sc/source/core/data/documen3.cxx
@@ -1297,6 +1297,14 @@ void ScDocument::GetSearchAndReplaceStart( const SvxSearchItem& rSearchItem,
}
}
+// static
+bool ScDocument::IsEmptyCellSearch( const SvxSearchItem& rSearchItem )
+{
+ return !rSearchItem.GetPattern() && (rSearchItem.GetCellType() != SvxSearchCellType::NOTE)
+ && (rSearchItem.GetSearchOptions().searchString.isEmpty()
+ || (rSearchItem.GetRegExp() && rSearchItem.GetSearchOptions().searchString == "^$"));
+}
+
bool ScDocument::SearchAndReplace(
const SvxSearchItem& rSearchItem, SCCOL& rCol, SCROW& rRow, SCTAB& rTab,
const ScMarkData& rMark, ScRangeList& rMatchedRanges,
diff --git a/sc/source/core/data/table6.cxx b/sc/source/core/data/table6.cxx
index fca6dea1c61b..6b3321d2440c 100644
--- a/sc/source/core/data/table6.cxx
+++ b/sc/source/core/data/table6.cxx
@@ -817,18 +817,17 @@ bool ScTable::SearchAndReplace(
else if (nCommand == SvxSearchCmd::REPLACE_ALL)
bFound = ReplaceAllStyle(rSearchItem, rMark, rMatchedRanges, pUndoDoc);
}
+ else if (ScDocument::IsEmptyCellSearch( rSearchItem))
+ {
+ // Search for empty cells.
+ bFound = SearchAndReplaceEmptyCells(rSearchItem, rCol, rRow, rMark, rMatchedRanges, rUndoStr, pUndoDoc);
+ }
else
{
// SearchParam no longer needed - SearchOptions contains all settings
i18nutil::SearchOptions2 aSearchOptions = rSearchItem.GetSearchOptions();
aSearchOptions.Locale = *ScGlobal::GetLocale();
- if (aSearchOptions.searchString.isEmpty() || ( rSearchItem.GetRegExp() && aSearchOptions.searchString == "^$" ) )
- {
- // Search for empty cells.
- return SearchAndReplaceEmptyCells(rSearchItem, rCol, rRow, rMark, rMatchedRanges, rUndoStr, pUndoDoc);
- }
-
// reflect UseAsianOptions flag in SearchOptions
// (use only ignore case and width if asian options are disabled).
// This is also done in SvxSearchDialog CommandHdl, but not in API object.
diff --git a/sc/source/ui/dialogs/searchresults.cxx b/sc/source/ui/dialogs/searchresults.cxx
index c9558c5376f3..db9dae68bfc8 100644
--- a/sc/source/ui/dialogs/searchresults.cxx
+++ b/sc/source/ui/dialogs/searchresults.cxx
@@ -92,7 +92,8 @@ namespace
};
}
-void SearchResultsDlg::FillResults( ScDocument& rDoc, const ScRangeList &rMatchedRanges, bool bCellNotes )
+void SearchResultsDlg::FillResults( ScDocument& rDoc, const ScRangeList &rMatchedRanges, bool bCellNotes,
+ bool bEmptyCells )
{
ListWrapper aList(*mxList);
std::vector<OUString> aTabNames = rDoc.GetAllTableNames();
@@ -103,13 +104,10 @@ void SearchResultsDlg::FillResults( ScDocument& rDoc, const ScRangeList &rMatche
if (nMatchMax > ListWrapper::mnMaximum)
nMatchMax = ListWrapper::mnMaximum;
- if (bCellNotes)
+ if (bCellNotes || bEmptyCells)
{
for (size_t i = 0, n = nMatchMax; i < n; ++i)
{
- /* TODO: a CellNotes iterator would come handy and might speed
- * things up a little, though we only loop through the
- * search/replace result positions here. */
ScRange const & rRange( rMatchedRanges[i] );
// Bear in mind that mostly the range is one address position
// or a column or a row joined.
@@ -122,11 +120,20 @@ void SearchResultsDlg::FillResults( ScDocument& rDoc, const ScRangeList &rMatche
{
for (aPos.SetRow( rRange.aStart.Row()); aPos.Row() <= rRange.aEnd.Row(); aPos.IncRow())
{
- const ScPostIt* pNote = rDoc.GetNote( aPos);
- if (pNote)
+ if (bCellNotes)
+ {
+ const ScPostIt* pNote = rDoc.GetNote( aPos);
+ if (pNote)
+ aList.Insert(aTabNames[aPos.Tab()], aPos,
+ rDoc.GetAddressConvention(),
+ pNote->GetText());
+ }
+ else // bEmptyCells
+ {
aList.Insert(aTabNames[aPos.Tab()], aPos,
- rDoc.GetAddressConvention(),
- pNote->GetText());
+ rDoc.GetAddressConvention(),
+ rDoc.GetString(aPos));
+ }
}
}
}
diff --git a/sc/source/ui/inc/searchresults.hxx b/sc/source/ui/inc/searchresults.hxx
index 54d40a39de1e..c10e6014342a 100644
--- a/sc/source/ui/inc/searchresults.hxx
+++ b/sc/source/ui/inc/searchresults.hxx
@@ -37,7 +37,7 @@ public:
virtual void Close() override;
- void FillResults( ScDocument& rDoc, const ScRangeList& rMatchedRanges, bool bCellNotes );
+ void FillResults( ScDocument& rDoc, const ScRangeList& rMatchedRanges, bool bCellNotes, bool bEmptyCells );
};
class SearchResultsDlgWrapper : public SfxChildWindow
diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx
index 293199e4c455..88291959d9d7 100644
--- a/sc/source/ui/view/viewfun2.cxx
+++ b/sc/source/ui/view/viewfun2.cxx
@@ -2012,8 +2012,17 @@ bool ScViewFunc::SearchAndReplace( const SvxSearchItem* pSearchItem,
{
sc::SearchResultsDlg* pDlg = static_cast<sc::SearchResultsDlg*>(pWnd->GetController().get());
if (pDlg)
- pDlg->FillResults(rDoc, aMatchedRanges,
- pSearchItem->GetCellType() == SvxSearchCellType::NOTE);
+ {
+ const bool bCellNotes = (pSearchItem->GetCellType() == SvxSearchCellType::NOTE);
+ // ScCellIterator iterates over cells with content,
+ // for empty cells iterate over match positions.
+ const bool bEmptyCells = (!bCellNotes
+ && ((nCommand == SvxSearchCmd::FIND_ALL
+ && ScDocument::IsEmptyCellSearch(*pSearchItem))
+ || (nCommand == SvxSearchCmd::REPLACE_ALL
+ && pSearchItem->GetReplaceString().isEmpty())));
+ pDlg->FillResults(rDoc, aMatchedRanges, bCellNotes, bEmptyCells);
+ }
}
}