[PATCH] Delete the correct template from the selected search results...
Rafael Dominguez (via Code Review)
gerrit at gerrit.libreoffice.org
Tue Mar 26 22:35:26 PDT 2013
Hi,
I have submitted a patch for review:
https://gerrit.libreoffice.org/3077
To pull it, you can do:
git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/77/3077/1
Delete the correct template from the selected search results.
Change-Id: I2fe82b20e9b4a78abbbb3e8e587a5720054f845d
---
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 da51114..17eb140 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 dd99ceb..c6dd5b5 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 1cea676d..cd4b999 100644
--- a/sfx2/source/doc/templatedlg.cxx
+++ b/sfx2/source/doc/templatedlg.cxx
@@ -653,56 +653,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;
@@ -909,7 +900,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;
@@ -1053,37 +1044,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/3077
To unsubscribe, visit https://gerrit.libreoffice.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I2fe82b20e9b4a78abbbb3e8e587a5720054f845d
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: master
Gerrit-Owner: Rafael Dominguez <venccsralph at gmail.com>
More information about the LibreOffice
mailing list