[Libreoffice-commits] .: Branch 'feature/template-dialog' - 4 commits - sfx2/inc sfx2/source
Rafael Dominguez
rdominguez at kemper.freedesktop.org
Thu Jul 5 20:09:33 PDT 2012
sfx2/inc/sfx2/templatefolderview.hxx | 2
sfx2/source/control/templatefolderview.cxx | 124 ++++++++++++++++++-----------
sfx2/source/doc/templatedlg.cxx | 15 +++
3 files changed, 94 insertions(+), 47 deletions(-)
New commits:
commit fa99c1ea4f6d450cc12998d4513ed8cf77bafcc9
Author: Rafael Dominguez <venccsralph at gmail.com>
Date: Thu Jul 5 22:39:50 2012 -0430
Update thumnails for all template operations.
Change-Id: I7370e2ec459f64366277217b30875172104a72f6
diff --git a/sfx2/source/control/templatefolderview.cxx b/sfx2/source/control/templatefolderview.cxx
index ef58cfe..c66148d 100644
--- a/sfx2/source/control/templatefolderview.cxx
+++ b/sfx2/source/control/templatefolderview.cxx
@@ -297,41 +297,30 @@ void TemplateFolderView::Populate ()
sal_uInt16 nEntries = mpDocTemplates->GetCount(i);
- if (nEntries)
+ for (sal_uInt16 j = 0; j < nEntries; ++j)
{
- /// Preview first 2 thumbnails for folder
- pItem->maPreview1 = lcl_fetchThumbnail(mpDocTemplates->GetPath(i,0),
- THUMBNAIL_MAX_WIDTH*0.75,
- THUMBNAIL_MAX_HEIGHT*0.75);
+ rtl::OUString aName = mpDocTemplates->GetName(i,j);
+ rtl::OUString aURL = mpDocTemplates->GetPath(i,j);
+ rtl::OUString aType = SvFileInformationManager::GetDescription(INetURLObject(aURL));
- if ( nEntries > 2 )
- pItem->maPreview2 = lcl_fetchThumbnail(mpDocTemplates->GetPath(i,1),
- THUMBNAIL_MAX_WIDTH*0.75,
- THUMBNAIL_MAX_HEIGHT*0.75);
-
- for (sal_uInt16 j = 0; j < nEntries; ++j)
+ if ((sal_uInt32)aName.getLength() > mpItemAttrs->nMaxTextLenght)
{
- rtl::OUString aName = mpDocTemplates->GetName(i,j);
- rtl::OUString aURL = mpDocTemplates->GetPath(i,j);
- rtl::OUString aType = SvFileInformationManager::GetDescription(INetURLObject(aURL));
-
- if ((sal_uInt32)aName.getLength() > mpItemAttrs->nMaxTextLenght)
- {
- aName = aName.copy(0,mpItemAttrs->nMaxTextLenght-3);
- aName += "...";
- }
+ aName = aName.copy(0,mpItemAttrs->nMaxTextLenght-3);
+ aName += "...";
+ }
- TemplateViewItem *pTemplateItem = new TemplateViewItem(*mpItemView,mpItemView);
- pTemplateItem->mnId = j+1;
- pTemplateItem->maText = aName;
- pTemplateItem->setPath(aURL);
- pTemplateItem->setFileType(aType);
- pTemplateItem->maPreview1 = lcl_fetchThumbnail(aURL,THUMBNAIL_MAX_WIDTH,THUMBNAIL_MAX_HEIGHT);
+ TemplateViewItem *pTemplateItem = new TemplateViewItem(*mpItemView,mpItemView);
+ pTemplateItem->mnId = j+1;
+ pTemplateItem->maText = aName;
+ pTemplateItem->setPath(aURL);
+ pTemplateItem->setFileType(aType);
+ pTemplateItem->maPreview1 = lcl_fetchThumbnail(aURL,THUMBNAIL_MAX_WIDTH,THUMBNAIL_MAX_HEIGHT);
- pItem->maTemplates.push_back(pTemplateItem);
- }
+ pItem->maTemplates.push_back(pTemplateItem);
}
+ lcl_updateThumbnails(pItem);
+
mItemList.push_back(pItem);
}
@@ -486,10 +475,15 @@ bool TemplateFolderView::removeTemplate (const sal_uInt16 nItemId)
pItem->maTemplates.erase(pIter);
mpItemView->RemoveItem(nItemId);
+
break;
}
}
+ lcl_updateThumbnails(pItem);
+
+ CalculateItemPositions();
+
break;
}
}
@@ -609,6 +603,10 @@ void TemplateFolderView::copyFrom (TemplateFolderViewItem *pItem, const rtl::OUS
pTemplate->setFileType(SvFileInformationManager::GetDescription(INetURLObject(rPath)));
pItem->maTemplates.push_back(pTemplate);
+
+ lcl_updateThumbnails(pItem);
+
+ CalculateItemPositions();
}
}
@@ -699,7 +697,7 @@ void lcl_updateThumbnails (TemplateFolderViewItem *pItem)
}
else
{
- pItem->maPreview1 = lcl_ScaleImg(pItem->maTemplates[i]->maPreview1,
+ pItem->maPreview2 = lcl_ScaleImg(pItem->maTemplates[i]->maPreview1,
THUMBNAIL_MAX_WIDTH*0.75,
THUMBNAIL_MAX_HEIGHT*0.75);
}
commit 23c3e635a2c048692deb327bbc21866d19f1806e
Author: Rafael Dominguez <venccsralph at gmail.com>
Date: Thu Jul 5 21:11:25 2012 -0430
Update folder thumbnails after moving or copying templates.
Change-Id: I25596759c78a8898b5059db9c39b752f80075a2b
diff --git a/sfx2/source/control/templatefolderview.cxx b/sfx2/source/control/templatefolderview.cxx
index 89479cd..ef58cfe 100644
--- a/sfx2/source/control/templatefolderview.cxx
+++ b/sfx2/source/control/templatefolderview.cxx
@@ -36,6 +36,8 @@
#define INIT_VIEW_COLS 3
#define INIT_VIEW_LINES 1
+void lcl_updateThumbnails (TemplateFolderViewItem *pItem);
+
BitmapEx lcl_ScaleImg (const BitmapEx &rImg, long width, long height)
{
BitmapEx aImg = rImg;
@@ -576,6 +578,11 @@ bool TemplateFolderView::moveTemplates(std::set<const ThumbnailViewItem *> &rIte
if (refresh)
{
+ lcl_updateThumbnails(pSrc);
+ lcl_updateThumbnails(pTarget);
+
+ CalculateItemPositions();
+
Invalidate();
mpItemView->Invalidate();
}
@@ -679,4 +686,24 @@ IMPL_LINK_NOARG(TemplateFolderView, OverlayCloseHdl)
return 0;
}
+void lcl_updateThumbnails (TemplateFolderViewItem *pItem)
+{
+ // Update folder thumbnails
+ for (size_t i = 0, n = pItem->maTemplates.size(); i < 2 && i < n; ++i)
+ {
+ if (i == 0)
+ {
+ pItem->maPreview1 = lcl_ScaleImg(pItem->maTemplates[i]->maPreview1,
+ THUMBNAIL_MAX_WIDTH*0.75,
+ THUMBNAIL_MAX_HEIGHT*0.75);
+ }
+ else
+ {
+ pItem->maPreview1 = lcl_ScaleImg(pItem->maTemplates[i]->maPreview1,
+ THUMBNAIL_MAX_WIDTH*0.75,
+ THUMBNAIL_MAX_HEIGHT*0.75);
+ }
+ }
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 6e21f93b752167b27e78055cffcdfd9898152a8a
Author: Rafael Dominguez <venccsralph at gmail.com>
Date: Thu Jul 5 20:47:11 2012 -0430
Try to copy templates if moving them fails.
Change-Id: I2e7e559ca84ad6155ac73aa324ed3c7f0eda0e4b
diff --git a/sfx2/inc/sfx2/templatefolderview.hxx b/sfx2/inc/sfx2/templatefolderview.hxx
index dac804b..df9860f 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 43f8720..89479cd 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 819c3ab..77f9032 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))
{
}
}
commit 25e1e3cbf6f49d893ba67d2def850167d54b3f58
Author: Rafael Dominguez <venccsralph at gmail.com>
Date: Thu Jul 5 20:23:44 2012 -0430
Fix WaE.
Change-Id: If7df918d272fcfede7d9b36619937b06a28d485a
diff --git a/sfx2/source/control/templatefolderview.cxx b/sfx2/source/control/templatefolderview.cxx
index 022fb47..43f8720 100644
--- a/sfx2/source/control/templatefolderview.cxx
+++ b/sfx2/source/control/templatefolderview.cxx
@@ -282,7 +282,7 @@ void TemplateFolderView::Populate ()
{
rtl::OUString aRegionName(mpDocTemplates->GetFullRegionName(i));
- if (aRegionName.getLength() > mpItemAttrs->nMaxTextLenght)
+ if ((sal_uInt32)aRegionName.getLength() > mpItemAttrs->nMaxTextLenght)
{
aRegionName = aRegionName.copy(0,mpItemAttrs->nMaxTextLenght-3);
aRegionName += "...";
@@ -313,7 +313,7 @@ void TemplateFolderView::Populate ()
rtl::OUString aURL = mpDocTemplates->GetPath(i,j);
rtl::OUString aType = SvFileInformationManager::GetDescription(INetURLObject(aURL));
- if (aName.getLength() > mpItemAttrs->nMaxTextLenght)
+ if ((sal_uInt32)aName.getLength() > mpItemAttrs->nMaxTextLenght)
{
aName = aName.copy(0,mpItemAttrs->nMaxTextLenght-3);
aName += "...";
@@ -438,7 +438,7 @@ sal_uInt16 TemplateFolderView::createRegion(const rtl::OUString &rName)
rtl::OUString aRegionName = rName;
- if (aRegionName.getLength() > (sal_Int32)mpItemAttrs->nMaxTextLenght)
+ if ((sal_uInt32)aRegionName.getLength() > mpItemAttrs->nMaxTextLenght)
{
aRegionName = aRegionName.copy(0,mpItemAttrs->nMaxTextLenght-3);
aRegionName += "...";
More information about the Libreoffice-commits
mailing list