summaryrefslogtreecommitdiff
path: root/sfx2/source/control
diff options
context:
space:
mode:
authorAkshay Deep <akshaydeepiitr@gmail.com>2016-05-01 13:05:00 +0530
committerSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>2016-05-20 13:54:17 +0000
commitca040d16d06fead95ad7ed8d10f5995fbade1219 (patch)
tree23ab08bcb53eebc9a2757e5bcffbca8c9c3f38c6 /sfx2/source/control
parent365c4d8c60e89fd57a91f51ca51a8796fe91edd7 (diff)
New Template Manager
1. Save Mode removed from Template Manager 2. Context Menu for TemplateViewItems (Handled from LocalView for Local Repos) 3. 'showAllTemplates()' replacing 'showRootRegion()' 4. Filter Combobox for templates (Remembers filters also) 5. Search Filter (Synchronized with Filter ComboBoxes) 6. Removed Tabs from Template Manager 7. Removed Buttons from TemplateAbstractView 8. Unused GtkToolButtons removed 9. PushButtons in UI 10. Modal dialog for Import and Move (Works from "All Categories" now too) 11. ContextMenu for TemplateSearchView 12. Delete Categories(Folder) in Settings Menu 13. Save As Template Dialog Change-Id: I88f6568c35271c17dbd7e6877d50119a8cfe4d60 Reviewed-on: https://gerrit.libreoffice.org/24545 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Diffstat (limited to 'sfx2/source/control')
-rw-r--r--sfx2/source/control/templateabstractview.cxx135
-rw-r--r--sfx2/source/control/templatedefaultview.cxx14
-rw-r--r--sfx2/source/control/templatelocalview.cxx387
-rw-r--r--sfx2/source/control/templateremoteview.cxx15
-rw-r--r--sfx2/source/control/templatesearchview.cxx91
5 files changed, 291 insertions, 351 deletions
diff --git a/sfx2/source/control/templateabstractview.cxx b/sfx2/source/control/templateabstractview.cxx
index b202fb614299..ff39a2562ebf 100644
--- a/sfx2/source/control/templateabstractview.cxx
+++ b/sfx2/source/control/templateabstractview.cxx
@@ -10,9 +10,9 @@
#include <sfx2/templateabstractview.hxx>
#include <comphelper/processfactory.hxx>
-#include <sfx2/sfxresid.hxx>
#include <sfx2/templatecontaineritem.hxx>
#include <sfx2/templateviewitem.hxx>
+#include <sfx2/sfxresid.hxx>
#include <tools/urlobj.hxx>
#include <unotools/ucbstreamhelper.hxx>
#include <vcl/pngread.hxx>
@@ -71,80 +71,27 @@ bool ViewFilter_Application::operator () (const ThumbnailViewItem *pItem)
if (pTempItem)
return isValid(pTempItem->getPath());
- TemplateContainerItem *pContainerItem = const_cast<TemplateContainerItem*>(dynamic_cast<const TemplateContainerItem*>(pItem));
- if (pContainerItem)
- {
- std::vector<TemplateItemProperties> &rTemplates = pContainerItem->maTemplates;
-
- size_t nVisCount = 0;
-
- // Clear thumbnails
- pContainerItem->maPreview1.Clear();
- pContainerItem->maPreview2.Clear();
- pContainerItem->maPreview3.Clear();
- pContainerItem->maPreview4.Clear();
-
- for (size_t i = 0, n = rTemplates.size(); i < n && pContainerItem->HasMissingPreview(); ++i)
- {
- if (isValid(rTemplates[i].aPath))
- {
- ++nVisCount;
- if ( pContainerItem->maPreview1.IsEmpty( ) )
- {
- pContainerItem->maPreview1 = TemplateAbstractView::scaleImg(rTemplates[i].aThumbnail,
- TEMPLATE_THUMBNAIL_MAX_WIDTH*0.75,
- TEMPLATE_THUMBNAIL_MAX_HEIGHT*0.75);
- }
- else if ( pContainerItem->maPreview2.IsEmpty() )
- {
- pContainerItem->maPreview2 = TemplateAbstractView::scaleImg(rTemplates[i].aThumbnail,
- TEMPLATE_THUMBNAIL_MAX_WIDTH*0.75,
- TEMPLATE_THUMBNAIL_MAX_HEIGHT*0.75);
- }
- else if ( pContainerItem->maPreview3.IsEmpty() )
- {
- pContainerItem->maPreview3 = TemplateAbstractView::scaleImg(rTemplates[i].aThumbnail,
- TEMPLATE_THUMBNAIL_MAX_WIDTH*0.75,
- TEMPLATE_THUMBNAIL_MAX_HEIGHT*0.75);
- }
- else if ( pContainerItem->maPreview4.IsEmpty() )
- {
- pContainerItem->maPreview4 = TemplateAbstractView::scaleImg(rTemplates[i].aThumbnail,
- TEMPLATE_THUMBNAIL_MAX_WIDTH*0.75,
- TEMPLATE_THUMBNAIL_MAX_HEIGHT*0.75);
- }
- }
- }
- }
return true;
}
TemplateAbstractView::TemplateAbstractView (vcl::Window *pParent, WinBits nWinStyle, bool bDisableTransientChildren)
: ThumbnailView(pParent,nWinStyle,bDisableTransientChildren),
mnCurRegionId(0),
+ maSelectedItem(nullptr),
mnThumbnailWidth(TEMPLATE_THUMBNAIL_MAX_WIDTH),
mnThumbnailHeight(TEMPLATE_THUMBNAIL_MAX_HEIGHT),
- maAllButton(VclPtr<PushButton>::Create(this, SfxResId(BTN_ALL_TEMPLATES))),
- maFTName(VclPtr<FixedText>::Create(this, SfxResId(FT_NAME)))
+ maPosition(0,0)
{
- maAllButton->Hide();
- maAllButton->SetStyle(maAllButton->GetStyle() | WB_FLATBUTTON);
- maAllButton->SetClickHdl(LINK(this,TemplateAbstractView,ShowRootRegionHdl));
- maFTName->Hide();
}
TemplateAbstractView::TemplateAbstractView(vcl::Window *pParent)
: ThumbnailView(pParent),
mnCurRegionId(0),
+ maSelectedItem(nullptr),
mnThumbnailWidth(TEMPLATE_THUMBNAIL_MAX_WIDTH),
mnThumbnailHeight(TEMPLATE_THUMBNAIL_MAX_HEIGHT),
- maAllButton(VclPtr<PushButton>::Create(this, SfxResId(BTN_ALL_TEMPLATES))),
- maFTName(VclPtr<FixedText>::Create(this, SfxResId(FT_NAME)))
+ maPosition(0,0)
{
- maAllButton->Hide();
- maAllButton->SetStyle(maAllButton->GetStyle() | WB_FLATBUTTON);
- maAllButton->SetClickHdl(LINK(this,TemplateAbstractView,ShowRootRegionHdl));
- maFTName->Hide();
}
TemplateAbstractView::~TemplateAbstractView()
@@ -154,8 +101,6 @@ TemplateAbstractView::~TemplateAbstractView()
void TemplateAbstractView::dispose()
{
- maAllButton.disposeAndClear();
- maFTName.disposeAndClear();
ThumbnailView::dispose();
}
@@ -187,7 +132,6 @@ void TemplateAbstractView::insertItems(const std::vector<TemplateItemProperties>
std::vector<ThumbnailViewItem*> aItems(rTemplates.size());
for (size_t i = 0, n = rTemplates.size(); i < n; ++i )
{
- //TODO: CHECK IF THE ITEM IS A FOLDER OR NOT
const TemplateItemProperties *pCur = &rTemplates[i];
TemplateViewItem *pChild = new TemplateViewItem(*this, pCur->nId);
@@ -215,16 +159,58 @@ void TemplateAbstractView::updateThumbnailDimensions(long itemMaxSize)
mnThumbnailHeight = itemMaxSize;
}
+
+void TemplateAbstractView::MouseButtonDown( const MouseEvent& rMEvt )
+{
+ if (rMEvt.IsRight())
+ {
+ size_t nPos = ImplGetItem(rMEvt.GetPosPixel());
+ Point aPosition (rMEvt.GetPosPixel());
+ maPosition = aPosition;
+ ThumbnailViewItem* pItem = ImplGetItem(nPos);
+ const TemplateViewItem *pViewItem = dynamic_cast<const TemplateViewItem*>(pItem);
+
+ if(pViewItem)
+ {
+ maSelectedItem = dynamic_cast<TemplateViewItem*>(pItem);
+ maRightClickHdl.Call(pItem);
+ }
+ }
+
+ ThumbnailView::MouseButtonDown(rMEvt);
+}
+
+
void TemplateAbstractView::setOpenRegionHdl(const Link<void*,void> &rLink)
{
maOpenRegionHdl = rLink;
}
+void TemplateAbstractView::setRightClickHdl(const Link<ThumbnailViewItem*,void> &rLink)
+{
+ maRightClickHdl = rLink;
+}
+
void TemplateAbstractView::setOpenTemplateHdl(const Link<ThumbnailViewItem*,void> &rLink)
{
maOpenTemplateHdl = rLink;
}
+void TemplateAbstractView::setEditTemplateHdl(const Link<ThumbnailViewItem*,void> &rLink)
+{
+ maEditTemplateHdl = rLink;
+}
+
+void TemplateAbstractView::setDeleteTemplateHdl(const Link<ThumbnailViewItem*,void> &rLink)
+{
+ maDeleteTemplateHdl = rLink;
+}
+
+void TemplateAbstractView::setDefaultTemplateHdl(const Link<ThumbnailViewItem*,void> &rLink)
+{
+ maDefaultTemplateHdl = rLink;
+}
+
BitmapEx TemplateAbstractView::scaleImg (const BitmapEx &rImg, long width, long height)
{
BitmapEx aImg = rImg;
@@ -271,11 +257,6 @@ BitmapEx TemplateAbstractView::fetchThumbnail (const OUString &msURL, long width
return TemplateAbstractView::scaleImg(ThumbnailView::readThumbnail(msURL), width, height);
}
-IMPL_LINK_NOARG_TYPED(TemplateAbstractView, ShowRootRegionHdl, Button*, void)
-{
- showRootRegion();
-}
-
void TemplateAbstractView::OnItemDblClicked (ThumbnailViewItem *pItem)
{
//Check if the item is a TemplateContainerItem (Folder) or a TemplateViewItem (File)
@@ -284,10 +265,8 @@ void TemplateAbstractView::OnItemDblClicked (ThumbnailViewItem *pItem)
if ( pContainerItem )
{
// Fill templates
-
mnCurRegionId = pContainerItem->mnRegionId+1;
maCurRegionName = pContainerItem->maTitle;
- maFTName->SetText(maCurRegionName);
showRegion(pItem);
}
else
@@ -296,24 +275,4 @@ void TemplateAbstractView::OnItemDblClicked (ThumbnailViewItem *pItem)
}
}
-void TemplateAbstractView::Paint(vcl::RenderContext& rRenderContext, const Rectangle& rRect)
-{
- ThumbnailView::Paint(rRenderContext, rRect);
-
- Rectangle aRect(rRect.TopLeft(),
- Point(rRect.BottomRight().X(),
- mnHeaderHeight));
-
- drawinglayer::primitive2d::Primitive2DContainer aSeq(1);
- aSeq[0] = drawinglayer::primitive2d::Primitive2DReference(
- new PolyPolygonColorPrimitive2D(B2DPolyPolygon(::tools::Polygon(aRect).getB2DPolygon()),
- maFillColor.getBColor()));
-
- const drawinglayer::geometry::ViewInformation2D aNewViewInfos;
- std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor(
- drawinglayer::processor2d::createBaseProcessor2DFromOutputDevice(rRenderContext, aNewViewInfos));
-
- pProcessor->process(aSeq);
-}
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/source/control/templatedefaultview.cxx b/sfx2/source/control/templatedefaultview.cxx
index aad2187e7401..63c2e7148166 100644
--- a/sfx2/source/control/templatedefaultview.cxx
+++ b/sfx2/source/control/templatedefaultview.cxx
@@ -19,7 +19,7 @@ VCL_BUILDER_FACTORY(TemplateDefaultView)
TemplateDefaultView::TemplateDefaultView( Window* pParent)
: TemplateLocalView(pParent)
, mnTextHeight(30)
- , mnItemPadding(5)
+ , mnItemPadding(5)//TODO:: Change padding to 10. It looks really crowded and occupied.
{
Rectangle aScreen = Application::GetScreenPosSizePixel(Application::GetDisplayBuiltInScreen());
mnItemMaxSize = std::min(aScreen.GetWidth(),aScreen.GetHeight()) > 800 ? 256 : 192;
@@ -32,18 +32,6 @@ TemplateDefaultView::TemplateDefaultView( Window* pParent)
maHighlightColor = Color(officecfg::Office::Common::Help::StartCenter::StartCenterThumbnailsHighlightColor::get());
maHighlightTextColor = Color(officecfg::Office::Common::Help::StartCenter::StartCenterThumbnailsHighlightTextColor::get());
mfHighlightTransparence = 0.25;
-
-
- maAllButton->SetControlForeground(maTextColor);
- maFTName->SetControlForeground(maTextColor);
-
- // TODO - convert the TemplateAbstractView to .ui (instead of fixed layout
- // of the button and the fixed text), and do the following:
- // const float fMultiplier = 1.4;
- // vcl::Font aFont(maAllButton->GetSettings().GetStyleSettings().GetPushButtonFont());
- // aFont.SetSize(Size(0, aFont.GetSize().Height() * fMultiplier));
- // maAllButton->SetControlFont(aFont);
- // maFTName->SetControlFont(aFont);
}
void TemplateDefaultView::reload()
diff --git a/sfx2/source/control/templatelocalview.cxx b/sfx2/source/control/templatelocalview.cxx
index 5481475403d6..7e84c5e26366 100644
--- a/sfx2/source/control/templatelocalview.cxx
+++ b/sfx2/source/control/templatelocalview.cxx
@@ -10,7 +10,10 @@
#include <sfx2/templatelocalview.hxx>
#include <comphelper/processfactory.hxx>
+#include <comphelper/string.hxx>
#include <sfx2/doctempl.hxx>
+#include <sfx2/inputdlg.hxx>
+#include <sfx2/sfxresid.hxx>
#include <sfx2/templatecontaineritem.hxx>
#include <sfx2/templateviewitem.hxx>
#include <svl/inettype.hxx>
@@ -27,11 +30,17 @@
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
+#include "../doc/doc.hrc"
+
+#define MNI_OPEN 1
+#define MNI_EDIT 2
+#define MNI_DEFAULT_TEMPLATE 3
+#define MNI_DELETE 4
+#define MNI_RENAME 5
+
using namespace ::com::sun::star;
using namespace ::com::sun::star::frame;
-static void lcl_updateThumbnails (TemplateContainerItem *pItem);
-
TemplateLocalView::TemplateLocalView ( vcl::Window* pParent)
: TemplateAbstractView(pParent),
mpDocTemplates(new SfxDocumentTemplates)
@@ -52,6 +61,8 @@ void TemplateLocalView::dispose()
maRegions.clear();
+ maAllTemplates.clear();
+
delete mpDocTemplates;
TemplateAbstractView::dispose();
}
@@ -63,6 +74,8 @@ void TemplateLocalView::Populate ()
maRegions.clear();
+ maAllTemplates.clear();
+
sal_uInt16 nCount = mpDocTemplates->GetRegionCount();
for (sal_uInt16 i = 0; i < nCount; ++i)
{
@@ -91,10 +104,9 @@ void TemplateLocalView::Populate ()
getThumbnailHeight());
pItem->maTemplates.push_back(aProperties);
+ maAllTemplates.push_back(aProperties);
}
- lcl_updateThumbnails(pItem);
-
maRegions.push_back(pItem);
}
}
@@ -120,44 +132,25 @@ void TemplateLocalView::reload ()
}
}
else
- showRootRegion();
+ showAllTemplates();
+
+ //No items should be selected by default
+ deselectItems();
}
-void TemplateLocalView::showRootRegion()
+void TemplateLocalView::showAllTemplates()
{
- mnHeaderHeight = 0;
mnCurRegionId = 0;
maCurRegionName.clear();
- // Clone root region items so they don't get invalidated when we open another region
- std::vector<ThumbnailViewItem*> items(maRegions.size());
- for (int i = 0, n = maRegions.size(); i < n; ++i)
- {
- TemplateContainerItem *pCur = maRegions[i];
- TemplateContainerItem *pItem = new TemplateContainerItem(*this, pCur->mnId);
- pItem->mnRegionId = pCur->mnRegionId;
- pItem->maTitle = pCur->maTitle;
- pItem->maTemplates = pCur->maTemplates;
-
- items[i] = pItem;
- }
-
- maAllButton->Show(false);
- maFTName->Show(false);
-
- updateItems(items);
-
+ insertItems(maAllTemplates);
maOpenRegionHdl.Call(nullptr);
}
void TemplateLocalView::showRegion(ThumbnailViewItem *pItem)
{
- mnHeaderHeight = maAllButton->GetSizePixel().getHeight() + maAllButton->GetPosPixel().Y() * 2;
-
mnCurRegionId = static_cast<TemplateContainerItem*>(pItem)->mnRegionId+1;
maCurRegionName = pItem->maTitle;
- maAllButton->Show();
- maFTName->Show();
insertItems(reinterpret_cast<TemplateContainerItem*>(pItem)->maTemplates);
@@ -170,13 +163,81 @@ void TemplateLocalView::showRegion(const OUString &rName)
{
if (pRegion->maTitle == rName)
{
- maFTName->SetText(rName);
showRegion(pRegion);
break;
}
}
}
+ThumbnailViewItem* TemplateLocalView::getRegion(OUString rName)
+{
+ for (TemplateContainerItem* pRegion : maRegions)
+ if (pRegion->maTitle == rName)
+ return pRegion;
+
+ return nullptr;
+}
+
+void TemplateLocalView::createContextMenu()
+{
+ std::unique_ptr<PopupMenu> pItemMenu(new PopupMenu);
+ pItemMenu->InsertItem(MNI_OPEN,SfxResId(STR_OPEN).toString());
+ pItemMenu->InsertItem(MNI_EDIT,SfxResId(STR_EDIT_TEMPLATE).toString());
+ pItemMenu->InsertItem(MNI_DEFAULT_TEMPLATE,SfxResId(STR_DEFAULT_TEMPLATE).toString());
+ pItemMenu->InsertSeparator();
+ pItemMenu->InsertItem(MNI_DELETE,SfxResId(STR_DELETE).toString());
+ pItemMenu->InsertItem(MNI_RENAME,SfxResId(STR_RENAME).toString());
+ pItemMenu->InsertSeparator();
+ deselectItems();
+ maSelectedItem->setSelection(true);
+ pItemMenu->SetSelectHdl(LINK(this, TemplateLocalView, ContextMenuSelectHdl));
+ pItemMenu->Execute(this, Rectangle(maPosition,Size(1,1)), PopupMenuFlags::ExecuteDown);
+ Invalidate();
+}
+
+IMPL_LINK_TYPED(TemplateLocalView, ContextMenuSelectHdl, Menu*, pMenu, bool)
+{
+ sal_uInt16 nMenuId = pMenu->GetCurItemId();
+
+ switch(nMenuId)
+ {
+ case MNI_OPEN:
+ maOpenTemplateHdl.Call(maSelectedItem);
+ break;
+ case MNI_EDIT:
+ maEditTemplateHdl.Call(maSelectedItem);
+ break;
+ case MNI_DELETE:
+ maDeleteTemplateHdl.Call(maSelectedItem);
+ break;
+ case MNI_RENAME:
+ {
+ ScopedVclPtrInstance< InputDialog > m_pTitleEditDlg( SfxResId(STR_RENAME_TEMPLATE).toString(), this);
+ OUString sOldTitle = maSelectedItem->getHelpText();
+ m_pTitleEditDlg->SetEntryText( sOldTitle );
+ m_pTitleEditDlg->HideHelpBtn();
+
+ if(!m_pTitleEditDlg->Execute())
+ break;
+ OUString sNewTitle = comphelper::string::strip( m_pTitleEditDlg->GetEntryText(), ' ');
+
+ if ( !sNewTitle.isEmpty() && sNewTitle != sOldTitle )
+ {
+ maSelectedItem->setTitle(sNewTitle);
+ maSelectedItem->setEditTitle(true);
+ }
+ }
+ break;
+ case MNI_DEFAULT_TEMPLATE:
+ maDefaultTemplateHdl.Call(maSelectedItem);
+ break;
+ default:
+ break;
+ }
+
+ return false;
+}
+
sal_uInt16 TemplateLocalView::getCurRegionItemId() const
{
for (TemplateContainerItem* pRegion : maRegions)
@@ -195,6 +256,17 @@ sal_uInt16 TemplateLocalView::getRegionId(size_t pos) const
return maRegions[pos]->mnId;
}
+sal_uInt16 TemplateLocalView::getRegionId(OUString sRegion) const
+{
+ for (TemplateContainerItem* pRegion : maRegions)
+ {
+ if (pRegion->maTitle == sRegion)
+ return pRegion->mnId;
+ }
+
+ return 0;
+}
+
OUString TemplateLocalView::getRegionName(const sal_uInt16 nRegionId) const
{
return mpDocTemplates->GetRegionName(nRegionId);
@@ -279,16 +351,6 @@ sal_uInt16 TemplateLocalView::createRegion(const OUString &rName)
return pItem->mnId;
}
-bool TemplateLocalView::isNestedRegionAllowed() const
-{
- return !mnCurRegionId;
-}
-
-bool TemplateLocalView::isImportAllowed() const
-{
- return mnCurRegionId;
-}
-
bool TemplateLocalView::removeRegion(const sal_uInt16 nItemId)
{
sal_uInt16 nRegionId = USHRT_MAX;
@@ -364,10 +426,7 @@ bool TemplateLocalView::removeTemplate (const sal_uInt16 nItemId, const sal_uInt
}
}
- lcl_updateThumbnails(pItem);
-
CalculateItemPositions();
-
break;
}
}
@@ -446,9 +505,6 @@ bool TemplateLocalView::moveTemplate (const ThumbnailViewItem *pItem, const sal_
}
}
- lcl_updateThumbnails(pSrc);
- lcl_updateThumbnails(pTarget);
-
CalculateItemPositions();
Invalidate();
@@ -461,12 +517,8 @@ bool TemplateLocalView::moveTemplate (const ThumbnailViewItem *pItem, const sal_
bool TemplateLocalView::moveTemplates(const std::set<const ThumbnailViewItem*, selection_cmp_fn> &rItems,
const sal_uInt16 nTargetItem)
{
- assert(mnCurRegionId); // Only allowed in non root regions
-
bool ret = true;
- sal_uInt16 nSrcRegionId = mnCurRegionId-1;
-
TemplateContainerItem *pTarget = nullptr;
TemplateContainerItem *pSrc = nullptr;
@@ -474,11 +526,9 @@ bool TemplateLocalView::moveTemplates(const std::set<const ThumbnailViewItem*, s
{
if (pRegion->mnId == nTargetItem)
pTarget = static_cast<TemplateContainerItem*>(pRegion);
- else if (pRegion->mnRegionId == nSrcRegionId)
- pSrc = static_cast<TemplateContainerItem*>(pRegion);
}
- if (pTarget && pSrc)
+ if (pTarget)
{
bool refresh = false;
@@ -490,59 +540,69 @@ bool TemplateLocalView::moveTemplates(const std::set<const ThumbnailViewItem*, s
for ( aSelIter = rItems.begin(); aSelIter != rItems.end(); ++aSelIter, ++nTargetIdx )
{
const TemplateViewItem *pViewItem = static_cast<const TemplateViewItem*>(*aSelIter);
+ sal_uInt16 nSrcRegionId = pViewItem->mnRegionId;
- bool bCopy = !mpDocTemplates->Move(nTargetRegion,nTargetIdx,nSrcRegionId,pViewItem->mnDocId);
+ for (TemplateContainerItem* pRegion : maRegions)
+ {
+ if (pRegion->mnRegionId == nSrcRegionId)
+ pSrc = static_cast<TemplateContainerItem*>(pRegion);
+ }
- if (bCopy)
+ if(pSrc)
{
- if (!mpDocTemplates->Copy(nTargetRegion,nTargetIdx,nSrcRegionId,pViewItem->mnDocId))
+ bool bCopy = !mpDocTemplates->Move(nTargetRegion,nTargetIdx,nSrcRegionId,pViewItem->mnDocId);
+
+ if (bCopy)
{
- ret = false;
- continue;
+ if (!mpDocTemplates->Copy(nTargetRegion,nTargetIdx,nSrcRegionId,pViewItem->mnDocId))
+ {
+ ret = false;
+ continue;
+ }
}
- }
-
- // move template to destination
- TemplateItemProperties aTemplateItem;
- aTemplateItem.nId = nTargetIdx + 1;
- aTemplateItem.nDocId = nTargetIdx;
- aTemplateItem.nRegionId = nTargetRegion;
- aTemplateItem.aName = pViewItem->maTitle;
- aTemplateItem.aPath = mpDocTemplates->GetPath(nTargetRegion,nTargetIdx);
- aTemplateItem.aThumbnail = pViewItem->maPreview1;
+ // move template to destination
- pTarget->maTemplates.push_back(aTemplateItem);
+ TemplateItemProperties aTemplateItem;
+ aTemplateItem.nId = nTargetIdx + 1;
+ aTemplateItem.nDocId = nTargetIdx;
+ aTemplateItem.nRegionId = nTargetRegion;
+ aTemplateItem.aName = pViewItem->maTitle;
+ aTemplateItem.aPath = mpDocTemplates->GetPath(nTargetRegion,nTargetIdx);
+ aTemplateItem.aThumbnail = pViewItem->maPreview1;
- if (!bCopy)
- {
- // remove template from region cached data
+ pTarget->maTemplates.push_back(aTemplateItem);
- std::vector<TemplateItemProperties>::iterator pPropIter;
- for (pPropIter = pSrc->maTemplates.begin(); pPropIter != pSrc->maTemplates.end();)
+ if (!bCopy)
{
- if (pPropIter->nDocId == pViewItem->mnDocId)
+ // remove template from region cached data
+
+ std::vector<TemplateItemProperties>::iterator pPropIter;
+ for (pPropIter = pSrc->maTemplates.begin(); pPropIter != pSrc->maTemplates.end();)
{
- pPropIter = pSrc->maTemplates.erase(pPropIter);
- aItemIds.push_back(pViewItem->mnId);
+ if (pPropIter->nDocId == pViewItem->mnDocId)
+ {
+ pPropIter = pSrc->maTemplates.erase(pPropIter);
+ aItemIds.push_back(pViewItem->mnId);
+ }
+ else
+ {
+ // Keep region document id synchronized with SfxDocumentTemplates
+ if (pPropIter->nDocId > pViewItem->mnDocId)
+ --pPropIter->nDocId;
+
+ ++pPropIter;
+ }
}
- else
- {
- // Keep region document id synchronized with SfxDocumentTemplates
- if (pPropIter->nDocId > pViewItem->mnDocId)
- --pPropIter->nDocId;
- ++pPropIter;
+ // Keep view document id synchronized with SfxDocumentTemplates
+ std::vector<ThumbnailViewItem*>::iterator pItemIter = mItemList.begin();
+ for (; pItemIter != mItemList.end(); ++pItemIter)
+ {
+ if (static_cast<TemplateViewItem*>(*pItemIter)->mnDocId > pViewItem->mnDocId)
+ --static_cast<TemplateViewItem*>(*pItemIter)->mnDocId;
}
}
-
- // Keep view document id synchronized with SfxDocumentTemplates
- std::vector<ThumbnailViewItem*>::iterator pItemIter = mItemList.begin();
- for (; pItemIter != mItemList.end(); ++pItemIter)
- {
- if (static_cast<TemplateViewItem*>(*pItemIter)->mnDocId > pViewItem->mnDocId)
- --static_cast<TemplateViewItem*>(*pItemIter)->mnDocId;
- }
}
refresh = true;
@@ -554,9 +614,6 @@ bool TemplateLocalView::moveTemplates(const std::set<const ThumbnailViewItem*, s
if (refresh)
{
- lcl_updateThumbnails(pSrc);
- lcl_updateThumbnails(pTarget);
-
CalculateItemPositions();
Invalidate();
}
@@ -604,8 +661,6 @@ bool TemplateLocalView::copyFrom(const sal_uInt16 nRegionItemId, const BitmapEx
pItem->maTemplates.push_back(aTemplate);
- lcl_updateThumbnails(pItem);
-
return true;
}
@@ -680,8 +735,6 @@ bool TemplateLocalView::copyFrom (TemplateContainerItem *pItem, const OUString &
pItem->maTemplates.push_back(aTemplate);
- lcl_updateThumbnails(pItem);
-
CalculateItemPositions();
return true;
@@ -715,107 +768,6 @@ bool TemplateLocalView::exportTo(const sal_uInt16 nItemId, const sal_uInt16 nReg
return false;
}
-bool TemplateLocalView::saveTemplateAs (sal_uInt16 nItemId,
- css::uno::Reference<css::frame::XModel> &rModel,
- const OUString &rName)
-{
-
- for (TemplateContainerItem* pRegion : maRegions)
- {
- if (pRegion->mnId == nItemId)
- {
- uno::Reference< frame::XStorable > xStorable(rModel, uno::UNO_QUERY_THROW );
-
- uno::Reference< frame::XDocumentTemplates > xTemplates(
- frame::DocumentTemplates::create(comphelper::getProcessComponentContext()) );
-
- if (!xTemplates->storeTemplate(mpDocTemplates->GetRegionName(pRegion->mnRegionId),rName, xStorable ))
- return false;
-
- sal_uInt16 nDocId = pRegion->maTemplates.size();
-
- OUString aURL = mpDocTemplates->GetTemplateTargetURLFromComponent(mpDocTemplates->GetRegionName(pRegion->mnRegionId),rName);
-
- if(!mpDocTemplates->InsertTemplate(pRegion->mnRegionId,nDocId,rName,aURL))
- return false;
-
-
- TemplateItemProperties aTemplate;
- aTemplate.aIsFolder = false;
- aTemplate.nId = getNextItemId();
- aTemplate.nDocId = nDocId;
- aTemplate.nRegionId = pRegion->mnRegionId;
- aTemplate.aName = rName;
- aTemplate.aThumbnail = TemplateAbstractView::fetchThumbnail(aURL,
- TEMPLATE_THUMBNAIL_MAX_WIDTH,
- TEMPLATE_THUMBNAIL_MAX_HEIGHT);
- aTemplate.aPath = aURL;
-
- pRegion->maTemplates.push_back(aTemplate);
-
- insertItem(aTemplate);
-
- return true;
- }
- }
-
- return false;
-}
-
-bool TemplateLocalView::saveTemplateAs(TemplateContainerItem *pDstItem,
- css::uno::Reference<css::frame::XModel> &rModel,
- const OUString &rName)
-{
- uno::Reference< frame::XStorable > xStorable(rModel, uno::UNO_QUERY_THROW );
-
- uno::Reference< frame::XDocumentTemplates > xTemplates(
- frame::DocumentTemplates::create(comphelper::getProcessComponentContext()) );
-
- if (!xTemplates->storeTemplate(mpDocTemplates->GetRegionName(pDstItem->mnRegionId),rName, xStorable ))
- return false;
-
- sal_uInt16 nDocId = pDstItem->maTemplates.size();
- OUString aURL = mpDocTemplates->GetTemplateTargetURLFromComponent(mpDocTemplates->GetRegionName(pDstItem->mnRegionId),rName);
-
- if(!mpDocTemplates->InsertTemplate(pDstItem->mnRegionId,nDocId,rName,aURL))
- return false;
-
- TemplateItemProperties aTemplate;
- aTemplate.aIsFolder = false;
- aTemplate.nId = pDstItem->maTemplates.empty() ? 1 : pDstItem->maTemplates.back().nId+1;
- aTemplate.nDocId = nDocId;
- aTemplate.nRegionId = pDstItem->mnRegionId;
- aTemplate.aName = rName;
- aTemplate.aThumbnail = TemplateAbstractView::fetchThumbnail(aURL,
- TEMPLATE_THUMBNAIL_MAX_WIDTH,
- TEMPLATE_THUMBNAIL_MAX_HEIGHT);
- aTemplate.aPath = aURL;
-
- pDstItem->maTemplates.push_back(aTemplate);
-
- return true;
-}
-
-bool TemplateLocalView::isTemplateNameUnique(const sal_uInt16 nRegionItemId, const OUString &rName) const
-{
- for (const TemplateContainerItem* pRegItem : maRegions)
- {
- if (pRegItem->mnId == nRegionItemId)
- {
- std::vector<TemplateItemProperties>::const_iterator aIter;
- for (aIter = pRegItem->maTemplates.begin(); aIter != pRegItem->maTemplates.end(); ++aIter)
- {
- if (aIter->aName == rName)
- return false;
- }
-
- break;
- }
- }
-
- return true;
-}
-
bool TemplateLocalView::renameItem(ThumbnailViewItem* pItem, const OUString& sNewTitle)
{
sal_uInt16 nRegionId = 0;
@@ -834,41 +786,4 @@ bool TemplateLocalView::renameItem(ThumbnailViewItem* pItem, const OUString& sNe
return mpDocTemplates->SetName( sNewTitle, nRegionId, nDocId );
}
-static void lcl_updateThumbnails (TemplateContainerItem *pItem)
-{
- pItem->maPreview1.Clear();
- pItem->maPreview2.Clear();
- pItem->maPreview3.Clear();
- pItem->maPreview4.Clear();
-
- // Update folder thumbnails
- for (size_t i = 0, n = pItem->maTemplates.size(); i < n && pItem->HasMissingPreview(); ++i)
- {
- if ( pItem->maPreview1.IsEmpty( ) )
- {
- pItem->maPreview1 = TemplateAbstractView::scaleImg(pItem->maTemplates[i].aThumbnail,
- TEMPLATE_THUMBNAIL_MAX_WIDTH*0.75,
- TEMPLATE_THUMBNAIL_MAX_HEIGHT*0.75);
- }
- else if ( pItem->maPreview2.IsEmpty() )
- {
- pItem->maPreview2 = TemplateAbstractView::scaleImg(pItem->maTemplates[i].aThumbnail,
- TEMPLATE_THUMBNAIL_MAX_WIDTH*0.75,
- TEMPLATE_THUMBNAIL_MAX_HEIGHT*0.75);
- }
- else if ( pItem->maPreview3.IsEmpty() )
- {
- pItem->maPreview3 = TemplateAbstractView::scaleImg(pItem->maTemplates[i].aThumbnail,
- TEMPLATE_THUMBNAIL_MAX_WIDTH*0.75,
- TEMPLATE_THUMBNAIL_MAX_HEIGHT*0.75);
- }
- else if ( pItem->maPreview4.IsEmpty() )
- {
- pItem->maPreview4 = TemplateAbstractView::scaleImg(pItem->maTemplates[i].aThumbnail,
- TEMPLATE_THUMBNAIL_MAX_WIDTH*0.75,
- TEMPLATE_THUMBNAIL_MAX_HEIGHT*0.75);
- }
- }
-}
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/source/control/templateremoteview.cxx b/sfx2/source/control/templateremoteview.cxx
index 07aaef278cae..1e9409a7f37d 100644
--- a/sfx2/source/control/templateremoteview.cxx
+++ b/sfx2/source/control/templateremoteview.cxx
@@ -60,12 +60,12 @@ VCL_BUILDER_DECL_FACTORY(TemplateRemoteView)
rRet = VclPtr<TemplateRemoteView>::Create(pParent, WB_VSCROLL, false);
}
-void TemplateRemoteView::showRootRegion()
+void TemplateRemoteView::showRegion(ThumbnailViewItem * /*pItem*/)
{
//TODO:
}
-void TemplateRemoteView::showRegion(ThumbnailViewItem * /*pItem*/)
+void TemplateRemoteView::showAllTemplates()
{
//TODO:
}
@@ -83,7 +83,6 @@ bool TemplateRemoteView::loadRepository (TemplateRepository* pItem)
mnCurRegionId = pItem->mnId;
maCurRegionName = pItem->maTitle;
- maFTName->SetText(maCurRegionName);
OUString aURL = pItem->getURL();
@@ -172,14 +171,4 @@ sal_uInt16 TemplateRemoteView::createRegion(const OUString &/*rName*/)
return 0;
}
-bool TemplateRemoteView::isNestedRegionAllowed() const
-{
- return true;
-}
-
-bool TemplateRemoteView::isImportAllowed() const
-{
- return true;
-}
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/source/control/templatesearchview.cxx b/sfx2/source/control/templatesearchview.cxx
index fa6a00997660..15e0857bad10 100644
--- a/sfx2/source/control/templatesearchview.cxx
+++ b/sfx2/source/control/templatesearchview.cxx
@@ -9,21 +9,110 @@
#include "templatesearchview.hxx"
#include "templatesearchviewitem.hxx"
+#include <sfx2/sfxresid.hxx>
+
+#include "../doc/doc.hrc"
#include <vcl/builderfactory.hxx>
+#define MNI_OPEN 1
+#define MNI_EDIT 2
+#define MNI_DEFAULT_TEMPLATE 3
+#define MNI_DELETE 4
+
TemplateSearchView::TemplateSearchView (vcl::Window *pParent, WinBits nWinStyle)
- : ThumbnailView(pParent,nWinStyle)
+ : ThumbnailView(pParent,nWinStyle),
+ maSelectedItem(nullptr),
+ maPosition(0,0)
{
}
VCL_BUILDER_FACTORY(TemplateSearchView)
+void TemplateSearchView::MouseButtonDown( const MouseEvent& rMEvt )
+{
+ if (rMEvt.IsRight())
+ {
+ size_t nPos = ImplGetItem(rMEvt.GetPosPixel());
+ Point aPosition (rMEvt.GetPosPixel());
+ maPosition = aPosition;
+ ThumbnailViewItem* pItem = ImplGetItem(nPos);
+ const TemplateViewItem *pViewItem = dynamic_cast<const TemplateViewItem*>(pItem);
+
+ if(pViewItem)
+ {
+ maSelectedItem = dynamic_cast<TemplateViewItem*>(pItem);
+ maRightClickHdl.Call(pItem);
+ }
+ }
+
+ ThumbnailView::MouseButtonDown(rMEvt);
+}
+
+void TemplateSearchView::createContextMenu()
+{
+ std::unique_ptr<PopupMenu> pItemMenu(new PopupMenu);
+ pItemMenu->InsertItem(MNI_OPEN,SfxResId(STR_OPEN).toString());
+ pItemMenu->InsertItem(MNI_EDIT,SfxResId(STR_EDIT_TEMPLATE).toString());
+ pItemMenu->InsertItem(MNI_DEFAULT_TEMPLATE,SfxResId(STR_DEFAULT_TEMPLATE).toString());
+ pItemMenu->InsertSeparator();
+ pItemMenu->InsertItem(MNI_DELETE,SfxResId(STR_DELETE).toString());
+ maSelectedItem->setSelection(true);
+ pItemMenu->SetSelectHdl(LINK(this, TemplateSearchView, ContextMenuSelectHdl));
+ pItemMenu->Execute(this, Rectangle(maPosition,Size(1,1)), PopupMenuFlags::ExecuteDown);
+ Invalidate();
+}
+
+IMPL_LINK_TYPED(TemplateSearchView, ContextMenuSelectHdl, Menu*, pMenu, bool)
+{
+ sal_uInt16 nMenuId = pMenu->GetCurItemId();
+
+ switch(nMenuId)
+ {
+ case MNI_OPEN:
+ maOpenTemplateHdl.Call(maSelectedItem);
+ break;
+ case MNI_EDIT:
+ maEditTemplateHdl.Call(maSelectedItem);
+ break;
+ case MNI_DELETE:
+ maDeleteTemplateHdl.Call(maSelectedItem);
+ break;
+ case MNI_DEFAULT_TEMPLATE:
+ maDefaultTemplateHdl.Call(maSelectedItem);
+ break;
+ default:
+ break;
+ }
+
+ return false;
+}
+
+void TemplateSearchView::setRightClickHdl(const Link<ThumbnailViewItem*,void> &rLink)
+{
+ maRightClickHdl = rLink;
+}
+
void TemplateSearchView::setOpenTemplateHdl(const Link<ThumbnailViewItem*, void> &rLink)
{
maOpenTemplateHdl = rLink;
}
+void TemplateSearchView::setEditTemplateHdl(const Link<ThumbnailViewItem*,void> &rLink)
+{
+ maEditTemplateHdl = rLink;
+}
+
+void TemplateSearchView::setDeleteTemplateHdl(const Link<ThumbnailViewItem*,void> &rLink)
+{
+ maDeleteTemplateHdl = rLink;
+}
+
+void TemplateSearchView::setDefaultTemplateHdl(const Link<ThumbnailViewItem*,void> &rLink)
+{
+ maDefaultTemplateHdl = rLink;
+}
+
void TemplateSearchView::OnItemDblClicked (ThumbnailViewItem *pItem)
{
maOpenTemplateHdl.Call(pItem);