[Libreoffice-commits] core.git: sc/source

Eike Rathke erack at redhat.com
Wed Jul 27 22:50:42 UTC 2016


 sc/source/ui/dialogs/searchresults.cxx |   55 ++++++++++++++++++++++++++-------
 sc/source/ui/inc/searchresults.hxx     |    2 -
 sc/source/ui/view/viewfun2.cxx         |    3 +
 3 files changed, 47 insertions(+), 13 deletions(-)

New commits:
commit 4f719263ae8dc44eabfba4654f9dbed92a9c5360
Author: Eike Rathke <erack at redhat.com>
Date:   Thu Jul 28 00:43:03 2016 +0200

    display the SearchAll() and ReplaceAll() results for notes, tdf#65334 related
    
    Change-Id: Ib9ff40b26526efdf242db2ef1804e54611f16b0e

diff --git a/sc/source/ui/dialogs/searchresults.cxx b/sc/source/ui/dialogs/searchresults.cxx
index 225fb2f..c6e7470 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 8143c48..776a23f 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 6a7a7e8..c6e2a94 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);
                     }
                 }
 


More information about the Libreoffice-commits mailing list