diff options
author | Rafael Dominguez <venccsralph@gmail.com> | 2013-03-27 18:19:53 -0430 |
---|---|---|
committer | Miklos Vajna <vmiklos@suse.cz> | 2013-04-08 07:38:16 +0000 |
commit | 6bdcdb6523d17470c17b84b2da573ade6f321aad (patch) | |
tree | 31e7a529e872159b6e08c6bb76cc26ab7db91dc7 | |
parent | 73c7e4e5a0da6e4326b9dad3d48ddd0b3aa12d61 (diff) |
fdo#60581 Import templates into current directory.
Change-Id: I3dfec069c606e61fc49b44e36602804054ca1bca
Reviewed-on: https://gerrit.libreoffice.org/3248
Reviewed-by: Miklos Vajna <vmiklos@suse.cz>
Tested-by: Miklos Vajna <vmiklos@suse.cz>
-rw-r--r-- | sfx2/inc/sfx2/templateabstractview.hxx | 2 | ||||
-rw-r--r-- | sfx2/inc/sfx2/templatelocalview.hxx | 3 | ||||
-rw-r--r-- | sfx2/source/control/templateabstractview.cxx | 26 | ||||
-rw-r--r-- | sfx2/source/control/templatelocalview.cxx | 36 | ||||
-rw-r--r-- | sfx2/source/doc/templatedlg.cxx | 38 |
5 files changed, 99 insertions, 6 deletions
diff --git a/sfx2/inc/sfx2/templateabstractview.hxx b/sfx2/inc/sfx2/templateabstractview.hxx index e181a00a1da4..a60fdb3b41fe 100644 --- a/sfx2/inc/sfx2/templateabstractview.hxx +++ b/sfx2/inc/sfx2/templateabstractview.hxx @@ -82,6 +82,8 @@ public: virtual ~TemplateAbstractView (); + void insertItem (const TemplateItemProperties &rTemplate); + // Fill view with new item list void insertItems (const std::vector<TemplateItemProperties> &rTemplates); diff --git a/sfx2/inc/sfx2/templatelocalview.hxx b/sfx2/inc/sfx2/templatelocalview.hxx index 59d05887a20b..f17f0f897376 100644 --- a/sfx2/inc/sfx2/templatelocalview.hxx +++ b/sfx2/inc/sfx2/templatelocalview.hxx @@ -70,6 +70,9 @@ public: bool copyFrom (const sal_uInt16 nRegionItemId, const BitmapEx &rThumbnail, const OUString &rPath); + // Import a template to the current region + bool copyFrom (const OUString &rPath); + bool copyFrom(TemplateContainerItem *pItem, const OUString &rPath); bool exportTo (const sal_uInt16 nItemId, const sal_uInt16 nRegionItemId, const OUString &rName); diff --git a/sfx2/source/control/templateabstractview.cxx b/sfx2/source/control/templateabstractview.cxx index 49aea81143c8..8fac81efcb9e 100644 --- a/sfx2/source/control/templateabstractview.cxx +++ b/sfx2/source/control/templateabstractview.cxx @@ -143,6 +143,32 @@ TemplateAbstractView::~TemplateAbstractView () { } +void TemplateAbstractView::insertItem(const TemplateItemProperties &rTemplate) +{ + const TemplateItemProperties *pCur = &rTemplate; + + TemplateViewItem *pChild = new TemplateViewItem(*this); + pChild->mnId = pCur->nId; + pChild->mnDocId = pCur->nDocId; + pChild->mnRegionId = pCur->nRegionId; + pChild->maTitle = pCur->aName; + pChild->setPath(pCur->aPath); + pChild->maPreview1 = pCur->aThumbnail; + + if ( pCur->aThumbnail.IsEmpty() ) + { + // Use the default thumbnail if we have nothing else + pChild->maPreview1 = TemplateAbstractView::getDefaultThumbnail(pCur->aPath); + } + + pChild->setSelectClickHdl(LINK(this,ThumbnailView,OnItemSelected)); + + mItemList.push_back(pChild); + + CalculateItemPositions(); + Invalidate(); +} + void TemplateAbstractView::insertItems(const std::vector<TemplateItemProperties> &rTemplates) { std::vector<ThumbnailViewItem*> aItems(rTemplates.size()); diff --git a/sfx2/source/control/templatelocalview.cxx b/sfx2/source/control/templatelocalview.cxx index 571cbecba153..c6d32af162be 100644 --- a/sfx2/source/control/templatelocalview.cxx +++ b/sfx2/source/control/templatelocalview.cxx @@ -590,6 +590,42 @@ bool TemplateLocalView::copyFrom(const sal_uInt16 nRegionItemId, const BitmapEx return false; } +bool TemplateLocalView::copyFrom(const OUString &rPath) +{ + assert(mnCurRegionId); + + TemplateContainerItem *pRegItem = maRegions[mnCurRegionId-1]; + + sal_uInt16 nId = getNextItemId(); + sal_uInt16 nDocId = 0; + sal_uInt16 nRegionId = pRegItem->mnRegionId; + + String aPath(rPath); + + if (!pRegItem->maTemplates.empty()) + nDocId = (pRegItem->maTemplates.back()).nDocId+1; + + if (!mpDocTemplates->CopyFrom(nRegionId,nDocId,aPath)) + return false; + + TemplateItemProperties aTemplate; + aTemplate.aIsFolder = false; + aTemplate.nId = nId; + aTemplate.nDocId = nDocId; + aTemplate.nRegionId = nRegionId; + aTemplate.aName = aPath; + aTemplate.aThumbnail = TemplateAbstractView::fetchThumbnail(rPath, + TEMPLATE_THUMBNAIL_MAX_WIDTH, + TEMPLATE_THUMBNAIL_MAX_HEIGHT); + aTemplate.aPath = rPath; + + pRegItem->maTemplates.push_back(aTemplate); + + insertItem(aTemplate); + + return true; +} + bool TemplateLocalView::copyFrom (TemplateContainerItem *pItem, const OUString &rPath) { sal_uInt16 nId = 1; diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx index 7c13f95a9ac9..6ca1fb4ef43c 100644 --- a/sfx2/source/doc/templatedlg.cxx +++ b/sfx2/source/doc/templatedlg.cxx @@ -879,15 +879,41 @@ void SfxTemplateManagerDlg::OnTemplateImport () if (aFiles.hasElements()) { - std::set<const ThumbnailViewItem*,selection_cmp_fn>::const_iterator pIter; - for (pIter = maSelFolders.begin(); pIter != maSelFolders.end(); ++pIter) + if (!maSelFolders.empty()) { - OUString aTemplateList; - TemplateContainerItem *pFolder = (TemplateContainerItem*)(*pIter); + //Import to the selected regions + std::set<const ThumbnailViewItem*,selection_cmp_fn>::const_iterator pIter; + for (pIter = maSelFolders.begin(); pIter != maSelFolders.end(); ++pIter) + { + OUString aTemplateList; + TemplateContainerItem *pFolder = (TemplateContainerItem*)(*pIter); + + for (size_t i = 0, n = aFiles.getLength(); i < n; ++i) + { + if(!maView->copyFrom(pFolder,aFiles[i])) + { + if (aTemplateList.isEmpty()) + aTemplateList = aFiles[i]; + else + aTemplateList = aTemplateList + "\n" + aFiles[i]; + } + } + if (!aTemplateList.isEmpty()) + { + OUString aMsg(SfxResId(STR_MSG_ERROR_IMPORT).toString()); + aMsg = aMsg.replaceFirst("$1",pFolder->maTitle); + ErrorBox(this,WB_OK,aMsg.replaceFirst("$2",aTemplateList)); + } + } + } + else + { + //Import to current region + OUString aTemplateList; for (size_t i = 0, n = aFiles.getLength(); i < n; ++i) { - if(!maView->copyFrom(pFolder,aFiles[i])) + if(!maView->copyFrom(aFiles[i])) { if (aTemplateList.isEmpty()) aTemplateList = aFiles[i]; @@ -899,7 +925,7 @@ void SfxTemplateManagerDlg::OnTemplateImport () if (!aTemplateList.isEmpty()) { OUString aMsg(SfxResId(STR_MSG_ERROR_IMPORT).toString()); - aMsg = aMsg.replaceFirst("$1",pFolder->maTitle); + aMsg = aMsg.replaceFirst("$1",maView->getCurRegionName()); ErrorBox(this,WB_OK,aMsg.replaceFirst("$2",aTemplateList)); } } |