[Libreoffice-commits] core.git: sc/inc sc/source
Eike Rathke (via logerrit)
logerrit at kemper.freedesktop.org
Mon Aug 9 00:25:32 UTC 2021
sc/inc/document.hxx | 1 +
sc/source/core/data/documen3.cxx | 8 ++++++++
sc/source/core/data/table6.cxx | 11 +++++------
sc/source/ui/dialogs/searchresults.cxx | 25 ++++++++++++++++---------
sc/source/ui/inc/searchresults.hxx | 2 +-
sc/source/ui/view/viewfun2.cxx | 13 +++++++++++--
6 files changed, 42 insertions(+), 18 deletions(-)
New commits:
commit 1c5b3cb3dd4dab6b0db409b6cc75b3111103820f
Author: Eike Rathke <erack at redhat.com>
AuthorDate: Mon Aug 9 01:04:56 2021 +0200
Commit: Eike Rathke <erack at redhat.com>
CommitDate: Mon Aug 9 02:24:54 2021 +0200
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 at redhat.com>
Tested-by: Jenkins
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);
+ }
}
}
More information about the Libreoffice-commits
mailing list