[PATCH libreoffice-4-0] Delete the correct template from the selected search results...

Rafael Dominguez (via Code Review) gerrit at gerrit.libreoffice.org
Sun Apr 7 11:51:49 PDT 2013


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/3240

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/40/3240/1

Delete the correct template from the selected search results.

Change-Id: I4a594e3c35d4c68da51421c92247b6687d163fe5
---
M sfx2/inc/sfx2/templatelocalview.hxx
M sfx2/source/control/templatelocalview.cxx
M sfx2/source/control/templatesearchview.cxx
M sfx2/source/doc/templatedlg.cxx
M sfx2/source/inc/templatesearchview.hxx
M sfx2/source/inc/templatesearchviewitem.hxx
6 files changed, 62 insertions(+), 64 deletions(-)



diff --git a/sfx2/inc/sfx2/templatelocalview.hxx b/sfx2/inc/sfx2/templatelocalview.hxx
index 6d6beb1..9dccf51 100644
--- a/sfx2/inc/sfx2/templatelocalview.hxx
+++ b/sfx2/inc/sfx2/templatelocalview.hxx
@@ -46,6 +46,8 @@
 
     sal_uInt16 getRegionId (size_t pos) const;
 
+    OUString getRegionName(const sal_uInt16 nRegionId) const;
+
     std::vector<OUString> getFolderNames ();
 
     std::vector<TemplateItemProperties>
diff --git a/sfx2/source/control/templatelocalview.cxx b/sfx2/source/control/templatelocalview.cxx
index d435f3d..e7eaa98 100644
--- a/sfx2/source/control/templatelocalview.cxx
+++ b/sfx2/source/control/templatelocalview.cxx
@@ -177,6 +177,11 @@
     return maRegions[pos]->mnId;
 }
 
+OUString TemplateLocalView::getRegionName(const sal_uInt16 nRegionId) const
+{
+    return mpDocTemplates->GetRegionName(nRegionId);
+}
+
 std::vector<OUString> TemplateLocalView::getFolderNames()
 {
     size_t n = maRegions.size();
@@ -193,9 +198,9 @@
 {
     std::vector<TemplateItemProperties> aItems;
 
-    for (size_t i = 0; i < maRegions.size(); ++i)
+    if (mnCurRegionId)
     {
-        TemplateContainerItem *pFolderItem = static_cast<TemplateContainerItem*>(maRegions[i]);
+        TemplateContainerItem *pFolderItem = maRegions[mnCurRegionId-1];
 
         for (size_t j = 0; j < pFolderItem->maTemplates.size(); ++j)
         {
@@ -203,6 +208,19 @@
                 aItems.push_back(pFolderItem->maTemplates[j]);
         }
     }
+    else
+    {
+        for (size_t i = 0; i < maRegions.size(); ++i)
+        {
+            TemplateContainerItem *pFolderItem = maRegions[i];
+
+            for (size_t j = 0; j < pFolderItem->maTemplates.size(); ++j)
+            {
+                if (rFunc(pFolderItem->maTemplates[j]))
+                    aItems.push_back(pFolderItem->maTemplates[j]);
+            }
+        }
+    }
 
     return aItems;
 }
diff --git a/sfx2/source/control/templatesearchview.cxx b/sfx2/source/control/templatesearchview.cxx
index 775abbc..eaec8dc 100644
--- a/sfx2/source/control/templatesearchview.cxx
+++ b/sfx2/source/control/templatesearchview.cxx
@@ -20,14 +20,15 @@
 {
 }
 
-void TemplateSearchView::AppendItem(sal_uInt16 nItemId, sal_uInt16 nRegionId, sal_uInt16 nIdx,
+void TemplateSearchView::AppendItem(sal_uInt16 nAssocItemId, sal_uInt16 nRegionId, sal_uInt16 nIdx,
                                     const OUString &rTitle, const OUString &rSubtitle,
                                     const OUString &rPath,
                                     const BitmapEx &rImage)
 {
     TemplateSearchViewItem *pItem = new TemplateSearchViewItem(*this);
-    pItem->mnId = nItemId;
-    pItem->mnIdx = nIdx;
+    pItem->mnId = getNextItemId();
+    pItem->mnAssocId = nAssocItemId;
+    pItem->mnDocId = nIdx;
     pItem->mnRegionId = nRegionId;
     pItem->maPreview1 = rImage;
     pItem->maTitle = rTitle;
diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx
index 75449d0..f5d5bd6 100644
--- a/sfx2/source/doc/templatedlg.cxx
+++ b/sfx2/source/doc/templatedlg.cxx
@@ -649,56 +649,47 @@
 
 IMPL_LINK_NOARG(SfxTemplateManagerDlg, SearchUpdateHdl)
 {
-    // if the search view is hidden, hide the folder view and display search one
-    if (!mpCurView->isNonRootRegionVisible() && !mpSearchView->IsVisible())
-    {
-        mpSearchView->Clear();
-        mpSearchView->Show();
-        mpCurView->Hide();
-    }
-
     OUString aKeyword = mpSearchEdit->GetText();
 
     if (!aKeyword.isEmpty())
     {
-        if (mpCurView->isNonRootRegionVisible())
+        mpSearchView->Clear();
+
+        // if the search view is hidden, hide the folder view and display search one
+        if (!mpSearchView->IsVisible())
         {
-            mpCurView->filterItems(ViewFilter_Keyword(aKeyword));
+            mpSearchView->Show();
+            mpCurView->Hide();
         }
-        else
+
+        bool bDisplayFolder = !mpCurView->isNonRootRegionVisible();
+
+        std::vector<TemplateItemProperties> aItems =
+                maView->getFilteredItems(SearchView_Keyword(aKeyword));
+
+        for (size_t i = 0; i < aItems.size(); ++i)
         {
-            mpSearchView->Clear();
+            TemplateItemProperties *pItem = &aItems[i];
 
-            std::vector<TemplateItemProperties> aItems =
-                    maView->getFilteredItems(SearchView_Keyword(aKeyword));
+            OUString aFolderName;
 
-            size_t nCounter = 0;
-            for (size_t i = 0; i < aItems.size(); ++i)
-            {
-                TemplateItemProperties *pItem = &aItems[i];
+            if (bDisplayFolder)
+                aFolderName = maView->getRegionName(pItem->nRegionId);
 
-                mpSearchView->AppendItem(++nCounter,pItem->nRegionId,
-                                         pItem->nId-1,
-                                         pItem->aName,
-                                         maView->GetItemText(pItem->nRegionId+1),
-                                         pItem->aPath,
-                                         pItem->aThumbnail);
-            }
-
-            mpSearchView->Invalidate();
+            mpSearchView->AppendItem(pItem->nId,maView->getRegionId(pItem->nRegionId),
+                                     pItem->nDocId,
+                                     pItem->aName,
+                                     aFolderName,
+                                     pItem->aPath,
+                                     pItem->aThumbnail);
         }
+
+        mpSearchView->Invalidate();
     }
     else
     {
-        if (mpCurView->isNonRootRegionVisible())
-        {
-            mpCurView->filterItems(ViewFilter_Application(FILTER_APP_NONE));
-        }
-        else
-        {
-            mpSearchView->Hide();
-            mpCurView->Show();
-        }
+        mpSearchView->Hide();
+        mpCurView->Show();
     }
 
     return 0;
@@ -905,7 +896,7 @@
 
                 OUString aPath = aPathObj.GetMainURL( INetURLObject::NO_DECODE );
 
-                if (!maView->exportTo(pItem->mnIdx+1,pItem->mnRegionId+1,aPath))
+                if (!maView->exportTo(pItem->mnDocId,pItem->mnRegionId+1,aPath))
                 {
                     if (aTemplateList.isEmpty())
                         aTemplateList = pItem->maTitle;
@@ -1044,37 +1035,24 @@
 
     if (mpSearchView->IsVisible())
     {
+        std::set<const ThumbnailViewItem*,selection_cmp_fn> aSelTemplates = maSelTemplates; //Avoids invalid iterators
+
         std::set<const ThumbnailViewItem*,selection_cmp_fn>::const_iterator pIter;
-        for (pIter = maSelTemplates.begin(); pIter != maSelTemplates.end();)
+        for (pIter = aSelTemplates.begin(); pIter != aSelTemplates.end(); ++pIter)
         {
             const TemplateSearchViewItem *pItem =
                     static_cast<const TemplateSearchViewItem*>(*pIter);
 
-            sal_uInt16 nItemId = pItem->mnIdx + 1;
-            sal_uInt16 nItemRegionId = pItem->mnRegionId + 1;
-
-            if (maView->removeTemplate(nItemId,nItemRegionId))
-                maSelTemplates.erase(pIter++);
-            else
+            if (!maView->removeTemplate(pItem->mnAssocId,pItem->mnRegionId))
             {
                 if (aTemplateList.isEmpty())
                     aTemplateList = pItem->maTitle;
                 else
                     aTemplateList = aTemplateList + "\n" + pItem->maTitle;
-
-                ++pIter;
             }
+            else
+                mpSearchView->RemoveItem(pItem->mnId);
         }
-
-        // Update search results
-        if (maSelTemplates.empty())
-        {
-            mpTemplateBar->Show(false);
-            mpViewBar->Show();
-            mpActionBar->Show();
-        }
-
-        SearchUpdateHdl(mpSearchEdit);
     }
     else
     {
diff --git a/sfx2/source/inc/templatesearchview.hxx b/sfx2/source/inc/templatesearchview.hxx
index de5514d..b9ca781 100644
--- a/sfx2/source/inc/templatesearchview.hxx
+++ b/sfx2/source/inc/templatesearchview.hxx
@@ -20,7 +20,7 @@
 
     virtual ~TemplateSearchView();
 
-    void AppendItem(sal_uInt16 nItemId, sal_uInt16 nRegionId, sal_uInt16 nIdx,
+    void AppendItem(sal_uInt16 nAssocItemId, sal_uInt16 nRegionId, sal_uInt16 nIdx,
                     const OUString &rTitle, const OUString &rSubtitle,
                     const OUString &rPath, const BitmapEx &rImage );
 };
diff --git a/sfx2/source/inc/templatesearchviewitem.hxx b/sfx2/source/inc/templatesearchviewitem.hxx
index 27e393d..9d26ac7 100644
--- a/sfx2/source/inc/templatesearchviewitem.hxx
+++ b/sfx2/source/inc/templatesearchviewitem.hxx
@@ -21,8 +21,7 @@
     virtual ~TemplateSearchViewItem ()
     {}
 
-    sal_uInt16 mnIdx;       // Template associated Index
-    sal_uInt16 mnRegionId;  // Template associated Region id
+    sal_uInt16 mnAssocId;    //Associated item id to the TemplateViews
 };
 
 #endif // __SFX2_TEMPLATESEARCHVIEWITEM_HXX__

-- 
To view, visit https://gerrit.libreoffice.org/3240
To unsubscribe, visit https://gerrit.libreoffice.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4a594e3c35d4c68da51421c92247b6687d163fe5
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: libreoffice-4-0
Gerrit-Owner: Rafael Dominguez <venccsralph at gmail.com>



More information about the LibreOffice mailing list