Hi, I have submitted a patch for review:
https://gerrit.libreoffice.org/3075 To pull it, you can do: git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/75/3075/1 Separate template region ids from thumbnail ids. - Update all actions to use the new system. Change-Id: I22da25a4bbba4604f5df42f440e6532076d39457 --- M sfx2/inc/sfx2/templatecontaineritem.hxx M sfx2/inc/sfx2/templatelocalview.hxx M sfx2/inc/sfx2/thumbnailview.hxx M sfx2/source/control/templateabstractview.cxx M sfx2/source/control/templatelocalview.cxx M sfx2/source/control/thumbnailview.cxx M sfx2/source/doc/templatedlg.cxx 7 files changed, 90 insertions(+), 55 deletions(-) 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 @@ { 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 7ea226c..da51114 100644 --- a/sfx2/inc/sfx2/templatelocalview.hxx +++ b/sfx2/inc/sfx2/templatelocalview.hxx @@ -42,6 +42,8 @@ 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 8d7f46a..467ac74 100644 --- a/sfx2/inc/sfx2/thumbnailview.hxx +++ b/sfx2/inc/sfx2/thumbnailview.hxx @@ -192,6 +192,8 @@ 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 baa72ee..eb725ba 100644 --- a/sfx2/source/control/templateabstractview.cxx +++ b/sfx2/source/control/templateabstractview.cxx @@ -375,7 +375,7 @@ { // 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 ddab413..dd99ceb 100644 --- a/sfx2/source/control/templatelocalview.cxx +++ b/sfx2/source/control/templatelocalview.cxx @@ -61,6 +61,7 @@ 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 @@ // 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 @@ 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 @@ { 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); @@ -155,6 +157,17 @@ insertItems(reinterpret_cast<TemplateContainerItem*>(pItem)->maTemplates); 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 @@ -197,6 +210,7 @@ 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 @@ // 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 @@ 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 @@ { 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 @@ 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::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 @@ { 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::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 @@ } String aPath(rPath); + sal_uInt16 nRegionId = maRegions[i]->mnRegionId; if (mpDocTemplates->CopyFrom(nRegionId,nDocId,aPath)) { @@ -530,9 +564,9 @@ 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 @@ 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::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 @@ 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 @@ { 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 @@ } 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 d7521b0..605ee50 100644 --- a/sfx2/source/control/thumbnailview.cxx +++ b/sfx2/source/control/thumbnailview.cxx @@ -896,6 +896,11 @@ 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 4250fe1..c537321 100644 --- a/sfx2/source/doc/templatedlg.cxx +++ b/sfx2/source/doc/templatedlg.cxx @@ -925,7 +925,7 @@ // 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 @@ } 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 @@ 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; @@ -1172,12 +1174,6 @@ ++pIter; } - } - - if (maSelFolders.empty()) - { - mpViewBar->HideItem(TBI_TEMPLATE_IMPORT); - mpViewBar->HideItem(TBI_TEMPLATE_FOLDER_DEL); } if (!aFolderList.isEmpty()) @@ -1371,7 +1367,7 @@ 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; -- To view, visit https://gerrit.libreoffice.org/3075 To unsubscribe, visit https://gerrit.libreoffice.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I22da25a4bbba4604f5df42f440e6532076d39457 Gerrit-PatchSet: 1 Gerrit-Project: core Gerrit-Branch: master Gerrit-Owner: Rafael Dominguez <venccsra...@gmail.com> _______________________________________________ LibreOffice mailing list LibreOffice@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice