26#include <sfx2/strings.hrc>
27#include <bitmaps.hlst>
30#include <com/sun/star/util/thePathSettings.hpp>
33#include <../doc/doctemplateslocal.hxx>
39 bool bRet = rExt ==
u"ott" || rExt ==
u"stw" || rExt ==
u"oth" || rExt ==
u"dot" || rExt ==
u"dotx" || rExt ==
u"otm"
40 || rExt ==
u"ots" || rExt ==
u"stc" || rExt ==
u"xlt" || rExt ==
u"xltm" || rExt ==
u"xltx"
41 || rExt ==
u"otp" || rExt ==
u"sti" || rExt ==
u"pot" || rExt ==
u"potm" || rExt ==
u"potx"
42 || rExt ==
u"otg" || rExt ==
u"std";
46 bRet = rExt ==
u"ott" || rExt ==
u"stw" || rExt ==
u"oth" || rExt ==
u"dot" || rExt ==
u"dotx" || rExt ==
u"otm";
50 bRet = rExt ==
u"ots" || rExt ==
u"stc" || rExt ==
u"xlt" || rExt ==
u"xltm" || rExt ==
u"xltx";
54 bRet = rExt ==
u"otp" || rExt ==
u"sti" || rExt ==
u"pot" || rExt ==
u"potm" || rExt ==
u"potx";
58 bRet = rExt ==
u"otg" || rExt ==
u"std";
86 std::unique_ptr<weld::Menu> xMenu)
89 , maSelectedItem(nullptr)
112 pItem->mnRegionId =
i;
113 pItem->maTitle = aRegionName;
117 for (sal_uInt16 j = 0; j < nEntries; ++j)
155 if (pRegion->mnRegionId == nRegionId)
190 if (pRegion->maTitle == rName)
191 return pRegion.get();
198 if (rIdent ==
u"open")
200 else if (rIdent ==
u"edit")
202 else if (rIdent ==
u"rename")
212 OUString sTooltip(
SfxResId(STR_TOOLTIP_ERROR_RENAME_TEMPLATE));
215 if (sNewTitle.isEmpty() || sNewTitle == sOldTitle)
217 for (
const auto& rItem : aCurRegionItems)
219 if (rItem.
aName == sNewTitle)
221 aTitleEditDlg.SetTooltip(sTooltip.replaceFirst(
"$1", sNewTitle));
227 if (!aTitleEditDlg.
run())
231 if ( !sNewTitle.isEmpty() && sNewTitle != sOldTitle )
236 else if (rIdent ==
u"delete")
239 SfxResId(STR_QMSG_SEL_TEMPLATE_DELETE)));
240 if (xQueryDlg->run() !=
RET_YES)
246 else if (rIdent ==
u"default")
261 if (pRegion->maTitle == sRegion)
262 return pRegion->mnId;
277 if (pRegion->mnId == nItemId)
278 return pRegion->maTitle;
287 std::vector<OUString> ret(
n);
289 for (
size_t i = 0;
i <
n; ++
i)
295std::vector<TemplateItemProperties>
298 std::vector<TemplateItemProperties> aItems;
306 if (rFunc(rItemProps))
307 aItems.push_back(rItemProps);
312 for (
auto const & pFolderItem :
maRegions)
316 if (rFunc(rItemProps))
317 aItems.push_back(rItemProps);
328 sal_uInt16 nItemId =
maRegions.size() + 1;
335 pItem->mnRegionId = nRegionId;
336 pItem->maTitle = rName;
350 return mpDocTemplates->SetName( rNewTitle, nRegionId, USHRT_MAX );
357 sal_uInt16 nRegionId = USHRT_MAX;
362 if ( (*pRegionIt)->mnId == nItemId )
367 nRegionId = (*pRegionIt)->mnRegionId;
374 if (nRegionId != USHRT_MAX && (*pRegionIt)->mnRegionId > nRegionId)
375 --(*pRegionIt)->mnRegionId;
381 if (nRegionId == USHRT_MAX)
387 if (region->mnRegionId > nRegionId)
388 --region->mnRegionId;
398 if (pRegion->mnId == nSrcItemId)
418 pIter->nDocId = pIter->nDocId - 1;
430 const sal_uInt16 nTargetItem)
437 if (pRegion->mnId == nTargetItem)
438 pTarget = pRegion.get();
444 bool refresh =
false;
446 sal_uInt16 nTargetRegion = pTarget->
mnRegionId;
450 std::set<const ThumbnailViewItem*,selection_cmp_fn>::const_iterator aSelIter;
451 for ( aSelIter = rItems.begin(); aSelIter != rItems.end(); ++aSelIter, ++nTargetIdx )
454 sal_uInt16 nSrcRegionId = pViewItem->
mnRegionId;
458 if (pRegion->mnRegionId == nSrcRegionId)
459 pSrc = pRegion.get();
468 OUString sQuery =
SfxResId(STR_MSG_QUERY_COPY).replaceFirst(
"$1", pViewItem->
maTitle).replaceFirst(
"$2",
471 if (xQueryDlg->run() !=
RET_YES)
473 OUString sMsg(
SfxResId(STR_MSG_ERROR_LOCAL_MOVE));
476 VclMessageType::Warning, VclButtonsType::Ok, sMsg.replaceFirst(
"$2",pViewItem->
maTitle)));
491 aTemplateItem.
nId = nTargetIdx + 1;
492 aTemplateItem.
nDocId = nTargetIdx;
505 std::vector<TemplateItemProperties>::iterator pPropIter;
508 if (pPropIter->nDocId == pViewItem->
mnDocId)
516 if (pPropIter->nDocId > pViewItem->
mnDocId)
527 if (pTemplateViewItem->mnDocId > pViewItem->
mnDocId)
550 sal_uInt16 nDocId = 0;
552 OUString aPath(rPath);
564 aTemplate.
nDocId = nDocId;
566 aTemplate.
aName = aPath;
570 aTemplate.
aPath = rPath;
587 if (pRegItem->mnId == nRegionItemId)
589 for (
auto const& elem : pRegItem->maTemplates)
591 if (elem.nId == nItemId)
593 return mpDocTemplates->CopyTo(pRegItem->mnRegionId,elem.nDocId,rName);
606 sal_uInt16 nRegionId = 0;
607 sal_uInt16 nDocId = USHRT_MAX;
616 bool bRes =
mpDocTemplates->SetName( sNewTitle, nRegionId, nDocId );
621 if (pRegion->mnId == nRegionId + 1 )
623 for(
auto & aTemplate : pRegion->maTemplates)
625 if(aTemplate.nId == nDocId + 1)
627 aTemplate.aName = sNewTitle;
634 OUString sRegionName;
637 if (aTemplate.nRegionId == nRegionId && aTemplate.nDocId == nDocId)
639 aTemplate.aName = sNewTitle;
640 sRegionName = aTemplate.aRegionName;
645 OUString sHelpText =
SfxResId(STR_TEMPLATE_TOOLTIP);
646 sHelpText = (sHelpText.replaceFirst(
"$1", sNewTitle)).replaceFirst(
"$2", sRegionName);
655 std::vector<std::unique_ptr<ThumbnailViewItem>> aItems(rTemplates.size());
656 for (
size_t i = 0,
n = rTemplates.size();
i <
n; ++
i )
660 std::unique_ptr<TemplateViewItem> pChild;
666 pChild->mnDocId = pCur->
nDocId;
668 pChild->maTitle = pCur->
aName;
669 pChild->setPath(pCur->
aPath);
671 if(!bShowCategoryInTooltip)
672 pChild->setHelpText(pCur->
aName);
675 OUString sHelpText =
SfxResId(STR_TEMPLATE_TOOLTIP);
676 sHelpText = (sHelpText.replaceFirst(
"$1", pCur->
aName)).replaceFirst(
"$2", pCur->
aRegionName);
677 pChild->setHelpText(sHelpText);
683 pChild->showDefaultIcon(
true);
691 aItems[
i] = std::move(pChild);
705 if (rCEvt.
GetCommand() != CommandEventId::ContextMenu)
706 return CustomWidgetController::Command(rCEvt);
732 if (pItem->isSelected())
753 if (!pItem->isSelected())
755 pItem->setSelection(
true);
767 SfxResId(STR_QMSG_SEL_TEMPLATE_DELETE)));
768 if (xQueryDlg->run() !=
RET_YES)
776 if (pItem->isSelected())
835 if (aSize.
Width() == 0)
842 double nRatio = std::min(
double(width)/
double(aSize.
Width()),
double(height)/
double(aSize.
Height()));
844 aImg.
Scale(nRatio, nRatio);
856 return SfxObjectFactory::GetStandardTemplate(rName).match(rPath); });
861 for (
const std::unique_ptr<ThumbnailViewItem>& pItem :
mItemList)
864 if (pViewItem && pViewItem->
getPath().match(rPath))
880 aImg =
BitmapEx(SFX_THUMBNAIL_TEXT);
882 aImg =
BitmapEx(SFX_THUMBNAIL_SHEET);
884 aImg =
BitmapEx(SFX_THUMBNAIL_PRESENTATION);
886 aImg =
BitmapEx(SFX_THUMBNAIL_DRAWING);
906 uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
907 css::uno::Reference< css::util::XPathSettings > xPathSettings = css::util::thePathSettings::get(xContext);
908 uno::Sequence<OUString> aInternalTemplateDirs;
909 uno::Any aAny = xPathSettings->getPropertyValue(
"Template_internal");
910 aAny >>= aInternalTemplateDirs;
912 for (OUString& rInternalTemplateDir : asNonConstRange(aInternalTemplateDirs))
916 if(::utl::UCBContentHelper::IsSubPath(rInternalTemplateDir, rPath))
924 bool isBuiltInCategory =
false;
926 isBuiltInCategory = std::find(aGroupNames.begin(), aGroupNames.end(),
927 rRegionName) != aGroupNames.end();
928 if(isBuiltInCategory)
933 if(rItem->maTitle == rRegionName)
935 for(
const auto& rTemplateItem : rItem->maTemplates)
geometry::RealPoint2D maPosition
PropertiesInfo aProperties
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
bool Scale(const Size &rNewSize, BmpScaleFlag nScaleFlag=BmpScaleFlag::Default)
const Size & GetSizePixel() const
CommandEventId GetCommand() const
const Point & GetMousePosPixel() const
bool IsMouseEvent() const
static std::vector< OUString > GetBuiltInGroupNames()
OUString getExtension(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true, DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
const vcl::KeyCode & GetKeyCode() const
void makeAbsoluteURL(OUString &rURL)
void makeRelocatableURL(OUString &rURL)
constexpr tools::Long Height() const
void setWidth(tools::Long nWidth)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
css::uno::Sequence< OUString > GetAllServiceNames()
std::vector< TemplateItemProperties > maTemplates
bool exportTo(const sal_uInt16 nItemId, const sal_uInt16 nRegionItemId, std::u16string_view rName)
tools::Long mnThumbnailWidth
TemplateLocalView(std::unique_ptr< weld::ScrolledWindow > xWindow, std::unique_ptr< weld::Menu > xMenu)
std::vector< TemplateItemProperties > maAllTemplates
void RemoveDefaultTemplateIcon(std::u16string_view rPath)
TemplateContainerItem * getRegion(std::u16string_view sStr)
bool IsBuiltInRegion(const OUString &rRegionName)
static BitmapEx getDefaultThumbnail(std::u16string_view rPath)
static bool IsInternalTemplate(const OUString &rPath)
Link< ThumbnailViewItem *, void > maEditTemplateHdl
void ContextMenuSelectHdl(std::u16string_view rIdent)
void setMoveTemplateHdl(const Link< void *, void > &rLink)
OUString getRegionName(const sal_uInt16 nRegionId) const
void setCreateContextMenuHdl(const Link< ThumbnailViewItem *, void > &rLink)
Link< ThumbnailViewItem *, void > maDefaultTemplateHdl
bool removeTemplate(const sal_uInt16 nItemId, const sal_uInt16 nSrcItemId)
sal_uInt16 getRegionId(size_t pos) const
virtual void OnItemDblClicked(ThumbnailViewItem *pItem) override
void moveTemplates(const std::set< const ThumbnailViewItem *, selection_cmp_fn > &rItems, const sal_uInt16 nTargetItem)
OUString getRegionItemName(const sal_uInt16 nItemId) const
sal_uInt16 createRegion(const OUString &rName)
static BitmapEx fetchThumbnail(const OUString &msURL, tools::Long width, tools::Long height)
virtual bool Command(const CommandEvent &rPos) override
void setEditTemplateHdl(const Link< ThumbnailViewItem *, void > &rLink)
Link< ThumbnailViewItem *, void > maCreateContextMenuHdl
void showRegion(TemplateContainerItem const *pItem)
std::vector< OUString > getFolderNames()
Link< void *, void > maOpenRegionHdl
Link< void *, void > maExportTemplateHdl
virtual bool renameItem(ThumbnailViewItem *pItem, const OUString &sNewTitle) override
void setDeleteTemplateHdl(const Link< void *, void > &rLink)
void setExportTemplateHdl(const Link< void *, void > &rLink)
virtual ~TemplateLocalView() override
void updateThumbnailDimensions(tools::Long itemMaxSize)
Link< void *, void > maDeleteTemplateHdl
virtual bool KeyInput(const KeyEvent &rKEvt) override
void setDefaultTemplateHdl(const Link< ThumbnailViewItem *, void > &rLink)
std::unique_ptr< SfxDocumentTemplates > mpDocTemplates
std::vector< TemplateItemProperties > getFilteredItems(const std::function< bool(const TemplateItemProperties &) > &rFunc) const
bool copyFrom(TemplateContainerItem *pItem, const OUString &rPath)
tools::Long mnThumbnailHeight
void insertItems(const std::vector< TemplateItemProperties > &rTemplates, bool isRegionSelected=true, bool bShowCategoryInTooltip=false)
Link< ThumbnailViewItem *, void > maOpenTemplateHdl
bool removeRegion(const sal_uInt16 nItemId)
std::vector< std::unique_ptr< TemplateContainerItem > > maRegions
TemplateViewItem * maSelectedItem
void setOpenTemplateHdl(const Link< ThumbnailViewItem *, void > &rLink)
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
Link< void *, void > maMoveTemplateHdl
void setOpenRegionHdl(const Link< void *, void > &rLink)
static bool IsDefaultTemplate(const OUString &rPath)
virtual void showAllTemplates()
bool renameRegion(std::u16string_view rTitle, const OUString &rNewTitle)
static BitmapEx scaleImg(const BitmapEx &rImg, tools::Long width, tools::Long height)
const OUString & getPath() const
void showDefaultIcon(bool bVal)
OUString const & getTitle() const
void setHelpText(const OUString &sText)
Text to be used for the tooltip.
void setSelection(bool state)
void setTitle(const OUString &rTitle)
Class to display thumbnails with their names below their respective icons.
void updateItems(std::vector< std::unique_ptr< ThumbnailViewItem > > items)
void CalculateItemPositions(bool bScrollBarUsed=false)
void deselectItems()
deselect all current selected items.
Link< const ThumbnailViewItem *, void > maItemStateHdl
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
size_t ImplGetItem(const Point &rPoint) const
virtual bool KeyInput(const KeyEvent &rKEvt) override
void RemoveItem(sal_uInt16 nItemId)
static BitmapEx readThumbnail(const OUString &msURL)
std::vector< std::unique_ptr< ThumbnailViewItem > > mItemList
ThumbnailValueItemList mFilteredItemList
Cache to store the filtered items.
static bool isFilteredExtension(FILTER_APPLICATION filter, std::u16string_view rExt)
bool isValid(std::u16string_view rPath) const
bool operator()(const ThumbnailViewItem *pItem)
Sequence< OUString > aServiceNames
const sal_uInt16 aItemIds[]
constexpr sal_uInt16 KEY_MOD1
constexpr sal_uInt16 KEY_A
constexpr sal_uInt16 KEY_DELETE
OString strip(const OString &rIn, char c)
OUString SfxResId(TranslateId aId)
sal_uInt16 nId
Index for ThumbnailView.
sal_uInt16 nDocId
Index based on SfxTemplateDocument.
#define TEMPLATE_THUMBNAIL_MAX_HEIGHT
#define TEMPLATE_THUMBNAIL_MAX_WIDTH
::std::vector< ThumbnailViewItem * > ThumbnailValueItemList