diff options
author | Rafael Dominguez <venccsralph@gmail.com> | 2012-07-05 20:47:11 -0430 |
---|---|---|
committer | Rafael Dominguez <venccsralph@gmail.com> | 2012-07-05 20:47:11 -0430 |
commit | 6e21f93b752167b27e78055cffcdfd9898152a8a (patch) | |
tree | c0b5c302d2e4d2e733cd86c6bf049256dc69e168 | |
parent | 25e1e3cbf6f49d893ba67d2def850167d54b3f58 (diff) |
Try to copy templates if moving them fails.
Change-Id: I2e7e559ca84ad6155ac73aa324ed3c7f0eda0e4b
-rw-r--r-- | sfx2/inc/sfx2/templatefolderview.hxx | 2 | ||||
-rw-r--r-- | sfx2/source/control/templatefolderview.cxx | 39 | ||||
-rw-r--r-- | sfx2/source/doc/templatedlg.cxx | 15 |
3 files changed, 39 insertions, 17 deletions
diff --git a/sfx2/inc/sfx2/templatefolderview.hxx b/sfx2/inc/sfx2/templatefolderview.hxx index dac804b07e7f..df9860fad347 100644 --- a/sfx2/inc/sfx2/templatefolderview.hxx +++ b/sfx2/inc/sfx2/templatefolderview.hxx @@ -61,7 +61,7 @@ public: bool removeTemplate (const sal_uInt16 nItemId); - bool moveTemplates (std::set<const ThumbnailViewItem*> &rItems, const sal_uInt16 nTargetItem); + 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 43f8720b0387..89479cdcccda 100644 --- a/sfx2/source/control/templatefolderview.cxx +++ b/sfx2/source/control/templatefolderview.cxx @@ -495,7 +495,8 @@ bool TemplateFolderView::removeTemplate (const sal_uInt16 nItemId) return true; } -bool TemplateFolderView::moveTemplates(std::set<const ThumbnailViewItem *> &rItems, const sal_uInt16 nTargetItem) +bool TemplateFolderView::moveTemplates(std::set<const ThumbnailViewItem *> &rItems, + const sal_uInt16 nTargetItem, bool bCopy) { bool ret = true; bool refresh = false; @@ -516,15 +517,22 @@ bool TemplateFolderView::moveTemplates(std::set<const ThumbnailViewItem *> &rIte if (pTarget && pSrc) { + sal_uInt16 nTargetRegion = pTarget->mnId-1; + sal_uInt16 nTargetIdx = mpDocTemplates->GetCount(nTargetRegion); // Next Idx + std::set<const ThumbnailViewItem*>::iterator aSelIter; - for ( aSelIter = rItems.begin(); aSelIter != rItems.end(); ++aSelIter ) + for ( aSelIter = rItems.begin(); aSelIter != rItems.end(); ++aSelIter, ++nTargetIdx ) { const TemplateViewItem *pViewItem = static_cast<const TemplateViewItem*>(*aSelIter); - sal_uInt16 nTargetRegion = pTarget->mnId-1; - sal_uInt16 nTargetIdx = mpDocTemplates->GetCount(nTargetRegion); // Next Idx + bool bOK; + + if (bCopy) + bOK = mpDocTemplates->Copy(nTargetRegion,nTargetIdx,nSrcRegionId,pViewItem->mnId-1); + else + bOK = mpDocTemplates->Move(nTargetRegion,nTargetIdx,nSrcRegionId,pViewItem->mnId-1); - if (!mpDocTemplates->Move(nTargetRegion,nTargetIdx,nSrcRegionId,pViewItem->mnId-1)) + if (!bOK) { ret = false; continue; @@ -541,19 +549,22 @@ bool TemplateFolderView::moveTemplates(std::set<const ThumbnailViewItem *> &rIte pTarget->maTemplates.push_back(pTemplateItem); - // remove template for overlay and from cached data - - std::vector<TemplateViewItem*>::iterator pIter; - for (pIter = pSrc->maTemplates.begin(); pIter != pSrc->maTemplates.end(); ++pIter) + if (!bCopy) { - if ((*pIter)->mnId == pViewItem->mnId) + // remove template for overlay and from cached data + + std::vector<TemplateViewItem*>::iterator pIter; + for (pIter = pSrc->maTemplates.begin(); pIter != pSrc->maTemplates.end(); ++pIter) { - delete *pIter; + if ((*pIter)->mnId == pViewItem->mnId) + { + delete *pIter; - pSrc->maTemplates.erase(pIter); + pSrc->maTemplates.erase(pIter); - mpItemView->RemoveItem(pViewItem->mnId); - break; + mpItemView->RemoveItem(pViewItem->mnId); + break; + } } } diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx index 819c3ab4b5d1..77f903240a7b 100644 --- a/sfx2/source/doc/templatedlg.cxx +++ b/sfx2/source/doc/templatedlg.cxx @@ -500,8 +500,14 @@ IMPL_LINK(SfxTemplateManagerDlg, MoveMenuSelectHdl, Menu*, pMenu) { sal_uInt16 nNewRegionId = maView->createRegion(aName); - if (nNewRegionId && !maView->moveTemplates(maSelTemplates,nNewRegionId)) + if (nNewRegionId) { + // Move templates to desired folder if for some reason move fails + // try copying them. + if (!maView->moveTemplates(maSelTemplates,nNewRegionId,false) && + !maView->moveTemplates(maSelTemplates,nNewRegionId,true)) + { + } } } } @@ -519,7 +525,12 @@ IMPL_LINK(SfxTemplateManagerDlg, MoveMenuSelectHdl, Menu*, pMenu) } else { - if (!maView->moveTemplates(maSelTemplates,maView->GetItemId(nMenuId-MNI_MOVE_FOLDER_BASE))) + // Try to move the template, if isnt possible try to copy it. + + sal_uInt16 nItemId = maView->GetItemId(nMenuId-MNI_MOVE_FOLDER_BASE); + + if (!maView->moveTemplates(maSelTemplates,nItemId,false) && + !maView->moveTemplates(maSelTemplates,nItemId,true)) { } } |