[Libreoffice-commits] core.git: Branch 'libreoffice-4-0' - 3 commits - sfx2/inc sfx2/source
Rafael Dominguez
venccsralph at gmail.com
Mon Apr 8 00:37:36 PDT 2013
sfx2/inc/sfx2/templatecontaineritem.hxx | 1
sfx2/inc/sfx2/templatelocalview.hxx | 4
sfx2/inc/sfx2/thumbnailview.hxx | 2
sfx2/source/control/templateabstractview.cxx | 2
sfx2/source/control/templatelocalview.cxx | 133 ++++++++++++++++++---------
sfx2/source/control/templatesearchview.cxx | 7 -
sfx2/source/control/thumbnailview.cxx | 5 +
sfx2/source/doc/templatedlg.cxx | 127 +++++++++----------------
sfx2/source/inc/templatesearchview.hxx | 2
sfx2/source/inc/templatesearchviewitem.hxx | 3
10 files changed, 154 insertions(+), 132 deletions(-)
New commits:
commit 2f489b5f33f746f15258780d284c05a9aefc006e
Author: Rafael Dominguez <venccsralph at gmail.com>
Date: Tue Mar 26 23:07:57 2013 -0430
Delete the correct template from the selected search results.
Change-Id: I4a594e3c35d4c68da51421c92247b6687d163fe5
Reviewed-on: https://gerrit.libreoffice.org/3240
Reviewed-by: Miklos Vajna <vmiklos at suse.cz>
Tested-by: Miklos Vajna <vmiklos at suse.cz>
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 @@ public:
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 @@ sal_uInt16 TemplateLocalView::getRegionId(size_t pos) const
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 @@ TemplateLocalView::getFilteredItems(const boost::function<bool (const TemplateIt
{
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 @@ TemplateLocalView::getFilteredItems(const boost::function<bool (const TemplateIt
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 @@ TemplateSearchView::~TemplateSearchView ()
{
}
-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(SfxTemplateManagerDlg, OpenTemplateHdl, ThumbnailViewItem*, pItem)
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];
-
- mpSearchView->AppendItem(++nCounter,pItem->nRegionId,
- pItem->nId-1,
- pItem->aName,
- maView->GetItemText(pItem->nRegionId+1),
- pItem->aPath,
- pItem->aThumbnail);
- }
+ if (bDisplayFolder)
+ aFolderName = maView->getRegionName(pItem->nRegionId);
- 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 @@ void SfxTemplateManagerDlg::OnTemplateExport()
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 @@ void SfxTemplateManagerDlg::OnTemplateDelete ()
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 @@ public:
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 @@ struct TemplateSearchViewItem : public TemplateViewItem
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__
commit 951f7341f8449a79dc9e0f3bae5e4d650ecb3314
Author: Rafael Dominguez <venccsralph at gmail.com>
Date: Tue Mar 26 20:44:44 2013 -0430
Fix deleting templates through Template Manager.
Change-Id: I79c16eb264d957b510a8bf8ee2009e1f55190a0b
Reviewed-on: https://gerrit.libreoffice.org/3239
Reviewed-by: Miklos Vajna <vmiklos at suse.cz>
Tested-by: Miklos Vajna <vmiklos at suse.cz>
diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx
index 6951df3..75449d0 100644
--- a/sfx2/source/doc/templatedlg.cxx
+++ b/sfx2/source/doc/templatedlg.cxx
@@ -1079,30 +1079,19 @@ void SfxTemplateManagerDlg::OnTemplateDelete ()
else
{
sal_uInt16 nRegionItemId = maView->getCurRegionItemId();
+ std::set<const ThumbnailViewItem*,selection_cmp_fn> aSelTemplates = maSelTemplates; //Avoid 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)
{
- if (maView->removeTemplate((*pIter)->mnId,nRegionItemId))
- maSelTemplates.erase(pIter++);
- else
+ if (!maView->removeTemplate((*pIter)->mnId,nRegionItemId))
{
if (aTemplateList.isEmpty())
aTemplateList = (*pIter)->maTitle;
else
aTemplateList = aTemplateList + "\n" + (*pIter)->maTitle;
-
- ++pIter;
}
}
-
- if (maSelTemplates.empty())
- {
- mpTemplateBar->SetItemDown(TBI_TEMPLATE_DELETE,false);
- mpTemplateBar->Show(false);
- mpViewBar->Show();
- mpActionBar->Show();
- }
}
if (!aTemplateList.isEmpty())
commit 2231019888a670198e481b9f5771c356e4a73ffe
Author: Rafael Dominguez <venccsralph at gmail.com>
Date: Tue Mar 26 19:00:11 2013 -0430
Separate template region ids from thumbnail ids.
- Update all actions to use the new system.
Change-Id: I8aa09a3317eff4cb083c8fc151ea2f93a5a971fe
Reviewed-on: https://gerrit.libreoffice.org/3238
Reviewed-by: Miklos Vajna <vmiklos at suse.cz>
Tested-by: Miklos Vajna <vmiklos at suse.cz>
diff --git a/sfx2/inc/sfx2/templatecontaineritem.hxx b/sfx2/inc/sfx2/templatecontaineritem.hxx
index 4768604..527571c 100644
--- a/sfx2/inc/sfx2/templatecontaineritem.hxx
+++ b/sfx2/inc/sfx2/templatecontaineritem.hxx
@@ -17,6 +17,7 @@ class TemplateContainerItem : public ThumbnailViewItem
{
public:
+ sal_uInt16 mnRegionId;
BitmapEx maPreview2;
BitmapEx maPreview3;
BitmapEx maPreview4;
diff --git a/sfx2/inc/sfx2/templatelocalview.hxx b/sfx2/inc/sfx2/templatelocalview.hxx
index 68b7dc7..6d6beb1 100644
--- a/sfx2/inc/sfx2/templatelocalview.hxx
+++ b/sfx2/inc/sfx2/templatelocalview.hxx
@@ -42,6 +42,8 @@ public:
virtual void showRegion (ThumbnailViewItem *pItem);
+ sal_uInt16 getCurRegionItemId () const;
+
sal_uInt16 getRegionId (size_t pos) const;
std::vector<OUString> getFolderNames ();
diff --git a/sfx2/inc/sfx2/thumbnailview.hxx b/sfx2/inc/sfx2/thumbnailview.hxx
index 5a56645..2310060 100644
--- a/sfx2/inc/sfx2/thumbnailview.hxx
+++ b/sfx2/inc/sfx2/thumbnailview.hxx
@@ -192,6 +192,8 @@ public:
sal_uInt16 GetItemId( const Point& rPos ) const;
+ sal_uInt16 getNextItemId () const;
+
long GetItemWidth() const { return mnItemWidth; }
long GetItemHeight() const { return mnItemHeight; }
diff --git a/sfx2/source/control/templateabstractview.cxx b/sfx2/source/control/templateabstractview.cxx
index 8af4bcc..49aea81 100644
--- a/sfx2/source/control/templateabstractview.cxx
+++ b/sfx2/source/control/templateabstractview.cxx
@@ -382,7 +382,7 @@ void TemplateAbstractView::OnItemDblClicked (ThumbnailViewItem *pItem)
{
// Fill templates
- mnCurRegionId = pContainerItem->mnId-1;
+ mnCurRegionId = pContainerItem->mnRegionId+1;
maCurRegionName = pContainerItem->maTitle;
maFTName.SetText(maCurRegionName);
showRegion(pItem);
diff --git a/sfx2/source/control/templatelocalview.cxx b/sfx2/source/control/templatelocalview.cxx
index 429b4dc..d435f3d 100644
--- a/sfx2/source/control/templatelocalview.cxx
+++ b/sfx2/source/control/templatelocalview.cxx
@@ -61,6 +61,7 @@ void TemplateLocalView::Populate ()
TemplateContainerItem* pItem = new TemplateContainerItem( *this );
pItem->mnId = i+1;
+ pItem->mnRegionId = i;
pItem->maTitle = aRegionName;
pItem->setSelectClickHdl(LINK(this,ThumbnailView,OnItemSelected));
@@ -100,11 +101,11 @@ void TemplateLocalView::reload ()
// Check if we are currently browsing a region or root folder
if (mnCurRegionId)
{
- sal_uInt16 nItemId = mnCurRegionId + 1;
+ sal_uInt16 nRegionId = mnCurRegionId - 1; //Is offset by 1
for (size_t i = 0; i < maRegions.size(); ++i)
{
- if (maRegions[i]->mnId == nItemId)
+ if (maRegions[i]->mnRegionId == nRegionId)
{
showRegion(maRegions[i]);
break;
@@ -128,6 +129,7 @@ void TemplateLocalView::showRootRegion()
TemplateContainerItem *pCur = maRegions[i];
TemplateContainerItem *pItem = new TemplateContainerItem(*this);
pItem->mnId = pCur->mnId;
+ pItem->mnRegionId = pCur->mnRegionId;
pItem->maTitle = pCur->maTitle;
pItem->maTemplates = pCur->maTemplates;
pItem->setSelectClickHdl(LINK(this,ThumbnailView,OnItemSelected));
@@ -147,7 +149,7 @@ void TemplateLocalView::showRegion(ThumbnailViewItem *pItem)
{
mnHeaderHeight = maAllButton.GetSizePixel().getHeight() + maAllButton.GetPosPixel().Y() * 2;
- mnCurRegionId = pItem->mnId-1;
+ mnCurRegionId = static_cast<TemplateContainerItem*>(pItem)->mnRegionId+1;
maCurRegionName = pItem->maTitle;
maAllButton.Show(true);
maFTName.Show(true);
@@ -157,6 +159,17 @@ void TemplateLocalView::showRegion(ThumbnailViewItem *pItem)
maOpenRegionHdl.Call(NULL);
}
+sal_uInt16 TemplateLocalView::getCurRegionItemId() const
+{
+ for (size_t i = 0; i < maRegions.size(); ++i)
+ {
+ if (maRegions[i]->mnRegionId == mnCurRegionId-1)
+ return maRegions[i]->mnId;
+ }
+
+ return 0;
+}
+
sal_uInt16 TemplateLocalView::getRegionId(size_t pos) const
{
assert(pos < maRegions.size());
@@ -197,6 +210,7 @@ TemplateLocalView::getFilteredItems(const boost::function<bool (const TemplateIt
sal_uInt16 TemplateLocalView::createRegion(const OUString &rName)
{
sal_uInt16 nRegionId = mpDocTemplates->GetRegionCount(); // Next regionId
+ sal_uInt16 nItemId = getNextItemId();
if (!mpDocTemplates->InsertDir(rName,nRegionId))
return false;
@@ -205,14 +219,16 @@ sal_uInt16 TemplateLocalView::createRegion(const OUString &rName)
// Insert to the region cache list and to the thumbnail item list
TemplateContainerItem* pItem = new TemplateContainerItem( *this );
- pItem->mnId = nRegionId+1;
+ pItem->mnId = nItemId;
+ pItem->mnRegionId = nRegionId;
pItem->maTitle = aRegionName;
pItem->setSelectClickHdl(LINK(this,ThumbnailView,OnItemSelected));
maRegions.push_back(pItem);
pItem = new TemplateContainerItem(*this);
- pItem->mnId = nRegionId + 1;
+ pItem->mnId = nItemId;
+ pItem->mnRegionId = nRegionId;
pItem->maTitle = aRegionName;
pItem->setSelectClickHdl(LINK(this,ThumbnailView,OnItemSelected));
@@ -226,32 +242,50 @@ sal_uInt16 TemplateLocalView::createRegion(const OUString &rName)
bool TemplateLocalView::removeRegion(const sal_uInt16 nItemId)
{
- sal_uInt16 nRegionId = nItemId - 1;
-
- if (!mpDocTemplates->Delete(nRegionId,USHRT_MAX))
- return false;
-
- RemoveItem(nItemId);
+ sal_uInt16 nRegionId = USHRT_MAX;
// Remove from the region cache list
- std::vector<TemplateContainerItem*>::iterator it;
- for ( it = maRegions.begin(); it != maRegions.end(); ++it )
+ std::vector<TemplateContainerItem*>::iterator pRegionIt;
+ for ( pRegionIt = maRegions.begin(); pRegionIt != maRegions.end();)
{
- if ( (*it)->mnId == nItemId )
+ if ( (*pRegionIt)->mnId == nItemId )
{
- delete *it;
- maRegions.erase(it);
- break;
+ if (!mpDocTemplates->Delete((*pRegionIt)->mnRegionId,USHRT_MAX))
+ return false;
+
+ nRegionId = (*pRegionIt)->mnRegionId;
+
+ delete *pRegionIt;
+ pRegionIt = maRegions.erase(pRegionIt);
+ }
+ else
+ {
+ // Syncronize regions cache ids with SfxDocumentTemplates
+ if (nRegionId != USHRT_MAX && (*pRegionIt)->mnRegionId > nRegionId)
+ --(*pRegionIt)->mnRegionId;
+
+ ++pRegionIt;
}
}
+ if (nRegionId == USHRT_MAX)
+ return false;
+
+ // Syncronize view regions ids with SfxDocumentTemplates
+ std::vector<ThumbnailViewItem*>::iterator pViewIt = mItemList.begin();
+ for ( pViewIt = mItemList.begin(); pViewIt != mItemList.end(); ++pViewIt)
+ {
+ if (static_cast<TemplateContainerItem*>(*pViewIt)->mnRegionId > nRegionId)
+ --static_cast<TemplateContainerItem*>(*pViewIt)->mnRegionId;
+ }
+
+ RemoveItem(nItemId);
+
return true;
}
bool TemplateLocalView::removeTemplate (const sal_uInt16 nItemId, const sal_uInt16 nSrcItemId)
{
- sal_uInt16 nRegionId = nSrcItemId - 1;
-
for (size_t i = 0, n = maRegions.size(); i < n; ++i)
{
if (maRegions[i]->mnId == nSrcItemId)
@@ -262,7 +296,7 @@ bool TemplateLocalView::removeTemplate (const sal_uInt16 nItemId, const sal_uInt
{
if (pIter->nId == nItemId)
{
- if (!mpDocTemplates->Delete(nRegionId,pIter->nDocId))
+ if (!mpDocTemplates->Delete(pItem->mnRegionId,pIter->nDocId))
return false;
pIter = pItem->maTemplates.erase(pIter);
@@ -304,8 +338,8 @@ bool TemplateLocalView::moveTemplate (const ThumbnailViewItem *pItem, const sal_
if (pTarget && pSrc)
{
- sal_uInt16 nSrcRegionId = nSrcItem-1;
- sal_uInt16 nTargetRegion = pTarget->mnId-1;
+ sal_uInt16 nSrcRegionId = pSrc->mnRegionId;
+ sal_uInt16 nTargetRegion = pTarget->mnRegionId;
sal_uInt16 nTargetIdx = mpDocTemplates->GetCount(nTargetRegion); // Next Idx
const TemplateViewItem *pViewItem = static_cast<const TemplateViewItem*>(pItem);
@@ -374,11 +408,12 @@ bool TemplateLocalView::moveTemplate (const ThumbnailViewItem *pItem, const sal_
bool TemplateLocalView::moveTemplates(const std::set<const ThumbnailViewItem*, selection_cmp_fn> &rItems,
const sal_uInt16 nTargetItem)
{
+ assert(mnCurRegionId); // Only allowed in non root regions
+
bool ret = true;
bool refresh = false;
- sal_uInt16 nSrcRegionId = mnCurRegionId;
- sal_uInt16 nSrcRegionItemId = nSrcRegionId + 1;
+ sal_uInt16 nSrcRegionId = mnCurRegionId-1;
TemplateContainerItem *pTarget = NULL;
TemplateContainerItem *pSrc = NULL;
@@ -387,13 +422,13 @@ bool TemplateLocalView::moveTemplates(const std::set<const ThumbnailViewItem*, s
{
if (maRegions[i]->mnId == nTargetItem)
pTarget = static_cast<TemplateContainerItem*>(maRegions[i]);
- else if (maRegions[i]->mnId == nSrcRegionItemId)
+ else if (maRegions[i]->mnRegionId == nSrcRegionId)
pSrc = static_cast<TemplateContainerItem*>(maRegions[i]);
}
if (pTarget && pSrc)
{
- sal_uInt16 nTargetRegion = pTarget->mnId-1;
+ sal_uInt16 nTargetRegion = pTarget->mnRegionId;
sal_uInt16 nTargetIdx = mpDocTemplates->GetCount(nTargetRegion); // Next Idx
std::vector<sal_uInt16> aItemIds; // List of moved items ids (also prevents the invalidation of rItems iterators when we remove them as we go)
@@ -481,8 +516,6 @@ bool TemplateLocalView::moveTemplates(const std::set<const ThumbnailViewItem*, s
bool TemplateLocalView::copyFrom(const sal_uInt16 nRegionItemId, const BitmapEx &rThumbnail,
const OUString &rPath)
{
- sal_uInt16 nRegionId = nRegionItemId - 1;
-
for (size_t i = 0, n = maRegions.size(); i < n; ++i)
{
if (maRegions[i]->mnId == nRegionItemId)
@@ -500,6 +533,7 @@ bool TemplateLocalView::copyFrom(const sal_uInt16 nRegionItemId, const BitmapEx
}
String aPath(rPath);
+ sal_uInt16 nRegionId = maRegions[i]->mnRegionId;
if (mpDocTemplates->CopyFrom(nRegionId,nDocId,aPath))
{
@@ -530,9 +564,9 @@ bool TemplateLocalView::copyFrom(const sal_uInt16 nRegionItemId, const BitmapEx
bool TemplateLocalView::copyFrom (TemplateContainerItem *pItem, const OUString &rPath)
{
- sal_uInt16 nId = 0;
+ sal_uInt16 nId = 1;
sal_uInt16 nDocId = 0;
- sal_uInt16 nRegionId = pItem->mnId - 1;
+ sal_uInt16 nRegionId = pItem->mnRegionId;
String aPath(rPath);
if (!pItem->maTemplates.empty())
@@ -544,6 +578,7 @@ bool TemplateLocalView::copyFrom (TemplateContainerItem *pItem, const OUString &
if (mpDocTemplates->CopyFrom(nRegionId,nDocId,aPath))
{
TemplateItemProperties aTemplate;
+ aTemplate.aIsFolder = false;
aTemplate.nId = nId;
aTemplate.nDocId = nDocId;
aTemplate.nRegionId = nRegionId;
@@ -567,21 +602,18 @@ bool TemplateLocalView::copyFrom (TemplateContainerItem *pItem, const OUString &
bool TemplateLocalView::exportTo(const sal_uInt16 nItemId, const sal_uInt16 nRegionItemId, const OUString &rName)
{
- sal_uInt16 nRegionId = nRegionItemId - 1;
-
for (size_t i = 0, n = maRegions.size(); i < n; ++i)
{
if (maRegions[i]->mnId == nRegionItemId)
{
- TemplateContainerItem *pRegItem =
- static_cast<TemplateContainerItem*>(maRegions[i]);
+ TemplateContainerItem *pRegItem = maRegions[i];
std::vector<TemplateItemProperties>::iterator aIter;
for (aIter = pRegItem->maTemplates.begin(); aIter != pRegItem->maTemplates.end(); ++aIter)
{
if (aIter->nId == nItemId)
{
- if (!mpDocTemplates->CopyTo(nRegionId,aIter->nDocId,rName))
+ if (!mpDocTemplates->CopyTo(pRegItem->mnRegionId,aIter->nDocId,rName))
return false;
return true;
@@ -622,9 +654,7 @@ bool TemplateLocalView::saveTemplateAs(const TemplateContainerItem *pDstItem,
uno::Reference< frame::XDocumentTemplates > xTemplates(
frame::DocumentTemplates::create(comphelper::getProcessComponentContext()) );
- sal_uInt16 nRegionId = pDstItem->mnId-1;
-
- if (!xTemplates->storeTemplate(mpDocTemplates->GetRegionName(nRegionId),rName, xStorable ))
+ if (!xTemplates->storeTemplate(mpDocTemplates->GetRegionName(pDstItem->mnRegionId),rName, xStorable ))
return false;
return true;
@@ -636,8 +666,7 @@ bool TemplateLocalView::isTemplateNameUnique(const sal_uInt16 nRegionItemId, con
{
if (maRegions[i]->mnId == nRegionItemId)
{
- TemplateContainerItem *pRegItem =
- static_cast<TemplateContainerItem*>(maRegions[i]);
+ TemplateContainerItem *pRegItem = maRegions[i];
std::vector<TemplateItemProperties>::iterator aIter;
for (aIter = pRegItem->maTemplates.begin(); aIter != pRegItem->maTemplates.end(); ++aIter)
@@ -667,7 +696,7 @@ bool TemplateLocalView::renameItem(ThumbnailViewItem* pItem, rtl::OUString sNewT
}
else if ( pContainerItem )
{
- nRegionId = pContainerItem->mnId - 1;
+ nRegionId = pContainerItem->mnRegionId;
}
return mpDocTemplates->SetName( sNewTitle, nRegionId, nDocId );
}
diff --git a/sfx2/source/control/thumbnailview.cxx b/sfx2/source/control/thumbnailview.cxx
index 8b2840d..6c64662 100644
--- a/sfx2/source/control/thumbnailview.cxx
+++ b/sfx2/source/control/thumbnailview.cxx
@@ -899,6 +899,11 @@ sal_uInt16 ThumbnailView::GetItemId( const Point& rPos ) const
return 0;
}
+sal_uInt16 ThumbnailView::getNextItemId() const
+{
+ return mItemList.empty() ? 1 : mItemList.back()->mnId + 1;
+}
+
void ThumbnailView::setItemMaxTextLength(sal_uInt32 nLength)
{
mpItemAttrs->nMaxTextLenght = nLength;
diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx
index f993ecf..6951df3 100644
--- a/sfx2/source/doc/templatedlg.cxx
+++ b/sfx2/source/doc/templatedlg.cxx
@@ -921,7 +921,7 @@ void SfxTemplateManagerDlg::OnTemplateExport()
// export templates from the current view
sal_uInt16 i = 1;
- sal_uInt16 nRegionItemId = maView->getCurRegionId() + 1;
+ sal_uInt16 nRegionItemId = maView->getCurRegionItemId();
std::set<const ThumbnailViewItem*,selection_cmp_fn>::const_iterator pIter = maSelTemplates.begin();
for (pIter = maSelTemplates.begin(); pIter != maSelTemplates.end(); ++pIter, ++i)
@@ -1078,10 +1078,12 @@ void SfxTemplateManagerDlg::OnTemplateDelete ()
}
else
{
+ sal_uInt16 nRegionItemId = maView->getCurRegionItemId();
+
std::set<const ThumbnailViewItem*,selection_cmp_fn>::const_iterator pIter;
for (pIter = maSelTemplates.begin(); pIter != maSelTemplates.end();)
{
- if (maView->removeTemplate((*pIter)->mnId,maView->getCurRegionId()+1))
+ if (maView->removeTemplate((*pIter)->mnId,nRegionItemId))
maSelTemplates.erase(pIter++);
else
{
@@ -1136,11 +1138,11 @@ void SfxTemplateManagerDlg::OnFolderDelete()
OUString aFolderList;
std::set<const ThumbnailViewItem*,selection_cmp_fn>::const_iterator pIter;
- for (pIter = maSelFolders.begin(); pIter != maSelFolders.end();)
+ std::set<const ThumbnailViewItem*,selection_cmp_fn> aSelFolders = maSelFolders; //Copy to avoid invalidating an iterator
+
+ for (pIter = aSelFolders.begin(); pIter != aSelFolders.end(); ++pIter)
{
- if (maView->removeRegion((*pIter)->mnId))
- maSelFolders.erase(pIter++);
- else
+ if (!maView->removeRegion((*pIter)->mnId))
{
if (aFolderList.isEmpty())
aFolderList = (*pIter)->maTitle;
@@ -1151,12 +1153,6 @@ void SfxTemplateManagerDlg::OnFolderDelete()
}
}
- if (maSelFolders.empty())
- {
- mpViewBar->HideItem(TBI_TEMPLATE_IMPORT);
- mpViewBar->HideItem(TBI_TEMPLATE_FOLDER_DEL);
- }
-
if (!aFolderList.isEmpty())
{
OUString aMsg( SfxResId(STR_MSG_ERROR_DELETE_FOLDER).toString() );
@@ -1348,7 +1344,7 @@ void SfxTemplateManagerDlg::localMoveTo(sal_uInt16 nMenuId)
OUString aTemplateList;
std::set<const ThumbnailViewItem*,selection_cmp_fn>::const_iterator pIter;
- for (pIter = maSelFolders.begin(); pIter != maSelFolders.end(); ++pIter)
+ for (pIter = maSelTemplates.begin(); pIter != maSelTemplates.end(); ++pIter)
{
if (aTemplateList.isEmpty())
aTemplateList = (*pIter)->maTitle;
More information about the Libreoffice-commits
mailing list