diff options
author | Rafael Dominguez <venccsralph@gmail.com> | 2013-03-26 19:00:11 -0430 |
---|---|---|
committer | Bosdonnat Cedric <cedric.bosdonnat@free.fr> | 2013-03-27 14:57:26 +0000 |
commit | 036c783b4c755c3054ab89a16853a145a13cbcfe (patch) | |
tree | 3a230650598b8f7bd8e382a389744db2106812fb | |
parent | 4653d73c577d5bf197e7e6c01876f85cf728e279 (diff) |
Separate template region ids from thumbnail ids.
- Update all actions to use the new system.
Change-Id: I22da25a4bbba4604f5df42f440e6532076d39457
Reviewed-on: https://gerrit.libreoffice.org/3075
Reviewed-by: Bosdonnat Cedric <cedric.bosdonnat@free.fr>
Tested-by: Bosdonnat Cedric <cedric.bosdonnat@free.fr>
-rw-r--r-- | sfx2/inc/sfx2/templatecontaineritem.hxx | 1 | ||||
-rw-r--r-- | sfx2/inc/sfx2/templatelocalview.hxx | 2 | ||||
-rw-r--r-- | sfx2/inc/sfx2/thumbnailview.hxx | 2 | ||||
-rw-r--r-- | sfx2/source/control/templateabstractview.cxx | 2 | ||||
-rw-r--r-- | sfx2/source/control/templatelocalview.cxx | 111 | ||||
-rw-r--r-- | sfx2/source/control/thumbnailview.cxx | 5 | ||||
-rw-r--r-- | sfx2/source/doc/templatedlg.cxx | 22 |
7 files changed, 90 insertions, 55 deletions
diff --git a/sfx2/inc/sfx2/templatecontaineritem.hxx b/sfx2/inc/sfx2/templatecontaineritem.hxx index 476860433c47..527571c80cac 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 7ea226c92867..da511145d6b6 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 8d7f46ad326f..467ac743f547 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 baa72ee64ff1..eb725ba4c1fb 100644 --- a/sfx2/source/control/templateabstractview.cxx +++ b/sfx2/source/control/templateabstractview.cxx @@ -375,7 +375,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 8c41502d31a8..9ab4ad687ee1 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) @@ -666,7 +695,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 d7521b0638bd..605ee50a084b 100644 --- a/sfx2/source/control/thumbnailview.cxx +++ b/sfx2/source/control/thumbnailview.cxx @@ -896,6 +896,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 4250fe1fd0db..c537321b3aed 100644 --- a/sfx2/source/doc/templatedlg.cxx +++ b/sfx2/source/doc/templatedlg.cxx @@ -925,7 +925,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) @@ -1087,10 +1087,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 { @@ -1159,11 +1161,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; @@ -1174,12 +1176,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() ); @@ -1371,7 +1367,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; |