diff options
author | Rafael Dominguez <venccsralph@gmail.com> | 2012-07-28 17:43:45 -0430 |
---|---|---|
committer | Rafael Dominguez <venccsralph@gmail.com> | 2012-07-29 21:29:25 -0430 |
commit | 4b0999916a17327337129dea7695648be1478529 (patch) | |
tree | 85ecc7c3553c5cef8907d282aa28404679cbe83e /sfx2 | |
parent | 7cc0477506ffa023b6e360863e43c8afc90b8712 (diff) |
Implement moveTemplate function for a single template.
- Copy or move a template from a source region to a target region.
Change-Id: I6dc2eedd0b8fdb310d67c63c6c315bf51d03e881
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/inc/sfx2/templatefolderview.hxx | 3 | ||||
-rw-r--r-- | sfx2/source/control/templatefolderview.cxx | 86 |
2 files changed, 89 insertions, 0 deletions
diff --git a/sfx2/inc/sfx2/templatefolderview.hxx b/sfx2/inc/sfx2/templatefolderview.hxx index 5274dd6b7fe8..e11d524e8615 100644 --- a/sfx2/inc/sfx2/templatefolderview.hxx +++ b/sfx2/inc/sfx2/templatefolderview.hxx @@ -55,6 +55,9 @@ public: bool removeTemplate (const sal_uInt16 nItemId); + bool moveTemplate (const ThumbnailViewItem* pItem, const sal_uInt16 nSrcItem, + const sal_uInt16 nTargetItem, bool bCopy); + bool moveTemplates (std::set<const ThumbnailViewItem*> &rItems, const sal_uInt16 nTargetItem, bool bCopy); void copyFrom (TemplateFolderViewItem *pItem, const rtl::OUString &rPath); diff --git a/sfx2/source/control/templatefolderview.cxx b/sfx2/source/control/templatefolderview.cxx index 59ef94bcfe69..117899f39824 100644 --- a/sfx2/source/control/templatefolderview.cxx +++ b/sfx2/source/control/templatefolderview.cxx @@ -496,6 +496,92 @@ bool TemplateFolderView::removeTemplate (const sal_uInt16 nItemId) return true; } +bool TemplateFolderView::moveTemplate (const ThumbnailViewItem *pItem, const sal_uInt16 nSrcItem, + const sal_uInt16 nTargetItem, bool bCopy) +{ + bool bRet = true; + bool bRefresh = false; + + TemplateFolderViewItem *pTarget = NULL; + TemplateFolderViewItem *pSrc = NULL; + + for (size_t i = 0, n = mItemList.size(); i < n; ++i) + { + if (mItemList[i]->mnId == nTargetItem) + pTarget = static_cast<TemplateFolderViewItem*>(mItemList[i]); + else if (mItemList[i]->mnId == nSrcItem) + pSrc = static_cast<TemplateFolderViewItem*>(mItemList[i]); + } + + if (pTarget && pSrc) + { + sal_uInt16 nSrcRegionId = nSrcItem-1; + sal_uInt16 nTargetRegion = pTarget->mnId-1; + sal_uInt16 nTargetIdx = mpDocTemplates->GetCount(nTargetRegion); // Next Idx + + const TemplateViewItem *pViewItem = static_cast<const TemplateViewItem*>(pItem); + + bool bOK; + + if (bCopy) + bOK = mpDocTemplates->Copy(nTargetRegion,nTargetIdx,nSrcRegionId,pViewItem->mnId-1); + else + bOK = mpDocTemplates->Move(nTargetRegion,nTargetIdx,nSrcRegionId,pViewItem->mnId-1); + + if (!bOK) + return false; + + // move template to destination + + TemplateItemProperties aTemplateItem; + aTemplateItem.nId = nTargetIdx + 1; + aTemplateItem.nRegionId = nTargetRegion; + aTemplateItem.aName = pViewItem->maTitle; + aTemplateItem.aPath = pViewItem->getPath(); + aTemplateItem.aType = pViewItem->getFileType(); + aTemplateItem.aThumbnail = pViewItem->maPreview1; + + pTarget->maTemplates.push_back(aTemplateItem); + + if (!bCopy) + { + // remove template from overlay and from cached data + + std::vector<TemplateItemProperties>::iterator aIter; + for (aIter = pSrc->maTemplates.begin(); aIter != pSrc->maTemplates.end(); ++aIter) + { + if (aIter->nId == pViewItem->mnId) + { + pSrc->maTemplates.erase(aIter); + + mpItemView->RemoveItem(pViewItem->mnId); + break; + } + } + } + + bRefresh = true; + } + else + bRet = false; + + if (bRefresh) + { + lcl_updateThumbnails(pSrc); + lcl_updateThumbnails(pTarget); + + CalculateItemPositions(); + + if (IsReallyVisible() && IsUpdateMode()) + { + Invalidate(); + mpItemView->Invalidate(); + } + } + + return bRet; +} + bool TemplateFolderView::moveTemplates(std::set<const ThumbnailViewItem *> &rItems, const sal_uInt16 nTargetItem, bool bCopy) { |