[Libreoffice-commits] .: Branch 'feature/template-dialog' - sfx2/inc sfx2/source
Rafael Dominguez
rdominguez at kemper.freedesktop.org
Sun Jul 1 11:44:55 PDT 2012
sfx2/inc/sfx2/templatefolderview.hxx | 6 ++
sfx2/source/control/templatefolderview.cxx | 87 +++++++++++++++++++++++++++++
sfx2/source/doc/templatedlg.cxx | 3 +
3 files changed, 96 insertions(+)
New commits:
commit c296909f4707e08903736b30e66debddbde26f34
Author: Rafael Dominguez <venccsralph at gmail.com>
Date: Sun Jul 1 14:12:16 2012 -0430
Implement moving templates between folders.
Change-Id: I33763aad192eb667f4865a02a3f2d91b5d3b9e8f
diff --git a/sfx2/inc/sfx2/templatefolderview.hxx b/sfx2/inc/sfx2/templatefolderview.hxx
index 9b23005..2f604d9 100644
--- a/sfx2/inc/sfx2/templatefolderview.hxx
+++ b/sfx2/inc/sfx2/templatefolderview.hxx
@@ -10,6 +10,8 @@
#ifndef TEMPLATEFOLDERVIEW_HXX
#define TEMPLATEFOLDERVIEW_HXX
+#include <set>
+
#include <sfx2/thumbnailview.hxx>
class SfxDocumentTemplates;
@@ -36,6 +38,8 @@ public:
// Fill view with template folders thumbnails
void Populate ();
+ std::vector<rtl::OUString> getFolderNames ();
+
// Check if the overlay is visible or not.
bool isOverlayVisible () const;
@@ -52,6 +56,8 @@ public:
bool removeTemplate (const sal_uInt16 nItemId);
+ bool moveTemplates (std::set<const ThumbnailViewItem*> &rItems, const sal_uInt16 nTargetItem);
+
void copyFrom (TemplateFolderViewItem *pItem, const rtl::OUString &rPath);
private:
diff --git a/sfx2/source/control/templatefolderview.cxx b/sfx2/source/control/templatefolderview.cxx
index 15ac471..e2fc4ba 100644
--- a/sfx2/source/control/templatefolderview.cxx
+++ b/sfx2/source/control/templatefolderview.cxx
@@ -334,6 +334,17 @@ void TemplateFolderView::Populate ()
Invalidate();
}
+std::vector<rtl::OUString> TemplateFolderView::getFolderNames()
+{
+ size_t n = mItemList.size();
+ std::vector<rtl::OUString> ret(n);
+
+ for (size_t i = 0; i < n; ++i)
+ ret[i] = mItemList[i]->maText;
+
+ return ret;
+}
+
bool TemplateFolderView::isOverlayVisible () const
{
return mpItemView->IsVisible();
@@ -423,6 +434,82 @@ bool TemplateFolderView::removeTemplate (const sal_uInt16 nItemId)
return true;
}
+bool TemplateFolderView::moveTemplates(std::set<const ThumbnailViewItem *> &rItems, const sal_uInt16 nTargetItem)
+{
+ bool ret = true;
+ bool refresh = false;
+
+ sal_uInt16 nSrcRegionId = mpItemView->getRegionId();
+ sal_uInt16 nSrcRegionItemId = nSrcRegionId + 1;
+
+ 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 == nSrcRegionItemId)
+ pSrc = static_cast<TemplateFolderViewItem*>(mItemList[i]);
+ }
+
+ if (pTarget && pSrc)
+ {
+ std::set<const ThumbnailViewItem*>::iterator aSelIter;
+ for ( aSelIter = rItems.begin(); aSelIter != rItems.end(); ++aSelIter )
+ {
+ sal_uInt16 nTargetRegion = pTarget->mnId-1;
+ sal_uInt16 nTargetIdx = pTarget->maTemplates.back()->mnId; // Last Assigned in filesystem is mnId-1
+
+ if (!mpDocTemplates->Move(nTargetRegion,nTargetIdx,mpItemView->getRegionId(),(*aSelIter)->mnId-1))
+ {
+ ret = false;
+ continue;
+ }
+
+ // move template to destination
+ const TemplateViewItem *pViewItem = static_cast<const TemplateViewItem*>(*aSelIter);
+
+ TemplateViewItem *pTemplateItem = new TemplateViewItem(*mpItemView,mpItemView);
+ pTemplateItem->mnId = nTargetIdx + 1;
+ pTemplateItem->maText = pViewItem->maText;
+ pTemplateItem->setPath(pViewItem->getPath());
+ pTemplateItem->setFileType(pViewItem->getFileType());
+ pTemplateItem->maPreview1 = pViewItem->maPreview1;
+
+ 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 ((*pIter)->mnId == pViewItem->mnId)
+ {
+ delete *pIter;
+
+ pSrc->maTemplates.erase(pIter);
+
+ mpItemView->RemoveItem(pViewItem->mnId);
+ break;
+ }
+ }
+
+ refresh = true;
+ }
+ }
+ else
+ ret = false;
+
+ if (refresh)
+ {
+ Invalidate();
+ mpItemView->Invalidate();
+ }
+
+ return ret;
+}
+
void TemplateFolderView::copyFrom (TemplateFolderViewItem *pItem, const rtl::OUString &rPath)
{
sal_uInt16 nId = 0;
diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx
index 4494065..12ddd1c 100644
--- a/sfx2/source/doc/templatedlg.cxx
+++ b/sfx2/source/doc/templatedlg.cxx
@@ -465,6 +465,9 @@ IMPL_LINK(SfxTemplateManagerDlg, MoveMenuSelectHdl, Menu*, pMenu)
}
else
{
+ if (!maView->moveTemplates(maSelTemplates,maView->GetItemId(nMenuId-MNI_MOVE_FOLDER_BASE)))
+ {
+ }
}
return 0;
More information about the Libreoffice-commits
mailing list