39#include <com/sun/star/beans/NamedValue.hpp>
40#include <com/sun/star/beans/PropertyValue.hpp>
41#include <com/sun/star/document/MacroExecMode.hpp>
42#include <com/sun/star/document/UpdateDocMode.hpp>
43#include <com/sun/star/embed/XStorage.hpp>
44#include <com/sun/star/embed/ElementModes.hpp>
45#include <com/sun/star/frame/Desktop.hpp>
46#include <com/sun/star/frame/XStorable.hpp>
47#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
48#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
49#include <com/sun/star/ui/dialogs/XFolderPicker2.hpp>
50#include <com/sun/star/task/InteractionHandler.hpp>
53#include <sfx2/strings.hrc>
54#include <bitmaps.hlst>
71#define MNI_ALL_APPLICATIONS 0
92class SearchView_Keyword
97 : maKeyword(rKeyword.toAsciiLowerCase()), meApp(
App)
105 OUString aExt = aUrl.getExtension();
109 bRet = aExt ==
"ott" || aExt ==
"stw" || aExt ==
"oth" || aExt ==
"dot" || aExt ==
"dotx";
113 bRet = aExt ==
"ots" || aExt ==
"stc" || aExt ==
"xlt" || aExt ==
"xltm" || aExt ==
"xltx";
117 bRet = aExt ==
"otp" || aExt ==
"sti" || aExt ==
"pot" || aExt ==
"potm" || aExt ==
"potx";
121 bRet = aExt ==
"otg" || aExt ==
"std";
124 return bRet && MatchSubstring(rItem.
aName);
127 bool MatchSubstring( OUString
const & sItemName )
129 if(maKeyword.isEmpty())
131 return sItemName.toAsciiLowerCase().indexOf(maKeyword) >= 0;
155 : GenericDialogController(pParent,
"sfx/ui/templatedlg.ui",
"TemplateDialog")
158 , m_aUpdateDataTimer(
"SfxTemplateManagerDlg UpdateDataTimer" )
159 , mxSearchFilter(m_xBuilder->weld_entry(
"search_filter"))
160 , mxCBApp(m_xBuilder->weld_combo_box(
"filter_application"))
161 , mxCBFolder(m_xBuilder->weld_combo_box(
"filter_folder"))
162 , mxOKButton(m_xBuilder->weld_button(
"ok"))
163 , mxCBXHideDlg(m_xBuilder->weld_check_button(
"hidedialogcb"))
164 , mxActionBar(m_xBuilder->weld_menu_button(
"action_menu"))
166 m_xBuilder->weld_menu(
"contextmenu"),
167 m_xBuilder->weld_tree_view(
"tree_list")))
168 , mxLocalViewWeld(new
weld::CustomWeld(*m_xBuilder,
"template_view", *mxLocalView))
169 , mxListViewButton(m_xBuilder->weld_toggle_button(
"list_view_btn"))
170 , mxThumbnailViewButton(m_xBuilder->weld_toggle_button(
"thumbnail_view_btn"))
271 if (mxSearchFilter !=
nullptr && !mxSearchFilter->get_text().isEmpty())
274 sal_uInt16 nKeyCode = aKeyCode.
GetCode();
278 mxSearchFilter->set_text(
"");
279 SearchUpdateHdl(*mxSearchFilter);
321 const sal_Int16 nCurAppId =
mxCBApp->get_active();
337 std::vector<OUString> aFolderNames =
mxLocalView->getFolderNames();
339 for (
size_t i = 0,
n = aFolderNames.size();
i <
n; ++
i)
391 OUString aLastFolder;
393 sal_Int16 nViewMode = -1;
395 if ( aViewSettings.
Exists() )
428 if (aLastFolder.isEmpty())
440 bool bIsBuiltInRegion =
mxLocalView->IsBuiltInRegion(aLastFolder);
460 OUString aLastFolder;
466 Sequence< NamedValue > aSettings
481 SelectRegionHdl(*mxCBFolder);
487 const OUString sSelectedRegion = mxCBFolder->get_active_text();
489 if(mxCBFolder->get_active() == 0)
496 bool bIsBuiltInRegion = mxLocalView->IsBuiltInRegion(sSelectedRegion);
508 OnTemplateState(pItem);
528 DefaultTemplateMenuSelectHdl(rIdent);
532 ExtensionsActionHdl();
538 OUString aFactoryURL;
552 if(!sPrevDefault.isEmpty())
554 mxLocalView->RemoveDefaultTemplateIcon(sPrevDefault);
583 if (!sCategory.isEmpty())
585 nItemId = mxLocalView->createRegion(sCategory);
587 mxCBFolder->append_text(sCategory);
591 nItemId = mxLocalView->getRegionId(sCategory);
595 localMoveTo(nItemId);
598 mxLocalView->reload();
627 OUString aMsg(
SfxResId(STR_CREATE_ERROR) );
629 VclMessageType::Warning, VclButtonsType::Ok,
630 aMsg.replaceFirst(
"$1", sCategory)));
641 const auto sCategory =
mxCBFolder->get_active_text();
651 "AdditionsTag", OUString(
"Templates")) };
657 maSelTemplates.clear();
658 mxOKButton->set_sensitive(
false);
665 bool bIsDefault =
false;
666 bool bIsInternal =
false;
667 std::vector<const TemplateViewItem*> aSelTemplates;
668 for(
const auto& aSelTmpl : maSelTemplates)
671 aSelTemplates.push_back(aItem);
674 for(
const auto& aSelTmpl : aSelTemplates)
676 if(aSelTmpl->IsDefaultTemplate())
689 bool bIsSingleSel = maSelTemplates.size() == 1;
690 OUString aDefaultImg;
693 aDefaultImg = BMP_ACTION_DEFAULT_WRITER;
695 aDefaultImg = BMP_ACTION_DEFAULT_CALC;
697 aDefaultImg = BMP_ACTION_DEFAULT_IMPRESS;
699 aDefaultImg = BMP_ACTION_DEFAULT_DRAW;
700 mxLocalView->createContextMenu(bIsDefault, bIsInternal, bIsSingleSel, aDefaultImg);
705 uno::Sequence< PropertyValue > aArgs{
709 comphelper::makePropertyValue(
"InteractionHandler", task::InteractionHandler::createWithParent( ::comphelper::getProcessComponentContext(),
nullptr )),
717 mxDesktop->loadComponentFromURL(pTemplateItem->
getPath(),
"_default", 0, aArgs );
719 catch(
const uno::Exception& )
728 uno::Sequence< PropertyValue > aArgs{
734 uno::Reference< XStorable > xStorable;
739 xStorable.set( mxDesktop->loadComponentFromURL(pViewItem->
getPath(),
"_default", 0, aArgs ),
742 catch(
const uno::Exception& )
751 std::set<const ThumbnailViewItem*,selection_cmp_fn> aSelTemplates = maSelTemplates;
752 OUString aDeletedTemplate;
754 for (
auto const& pItem : aSelTemplates)
757 sal_uInt16 nRegionItemId = mxLocalView->getRegionId(pViewItem->
mnRegionId);
759 if (!mxLocalView->removeTemplate(pViewItem->
mnDocId + 1, nRegionItemId))
761 aDeletedTemplate += pItem->
maTitle+
"\n";
765 if (!aDeletedTemplate.isEmpty())
767 OUString aMsg(
SfxResId(STR_MSG_ERROR_DELETE_TEMPLATE) );
769 VclMessageType::Warning, VclButtonsType::Ok,
770 aMsg.replaceFirst(
"$1",aDeletedTemplate)));
778 OUString aServiceName;
785 if(!sPrevDefault.isEmpty())
787 mxLocalView->RemoveDefaultTemplateIcon(sPrevDefault);
807 m_aUpdateDataTimer.Start();
817 if (m_aUpdateDataTimer.IsActive())
819 m_aUpdateDataTimer.Stop();
820 m_aUpdateDataTimer.Invoke();
832 bMakeSelItemVisible =
true;
837 if(bMakeSelItemVisible && !maSelTemplates.empty())
838 mxLocalView->MakeItemVisible((*maSelTemplates.begin())->mnId);
839 bMakeSelItemVisible =
false;
845 const OUString sSelectedRegion =
mxCBFolder->get_active_text();
855 std::vector<TemplateItemProperties> aItems =
mxLocalView->getFilteredItems(aFunc);
862 mxLocalView->deselectItems();
863 maSelTemplates.clear();
915 OUString sFilterName(
SfxResId( STR_TEMPLATE_FILTER ) );
920 sFilterExt +=
"*.ott;*.stw;*.oth;*.dotx;*.dot";
924 if ( !sFilterExt.isEmpty() )
927 sFilterExt +=
"*.ots;*.stc;*.xltx;*.xlt";
932 if ( !sFilterExt.isEmpty() )
935 sFilterExt +=
"*.otp;*.sti;*.pot;*.potx";
940 if ( !sFilterExt.isEmpty() )
943 sFilterExt +=
"*.otg;*.std";
946 if ( !sFilterExt.isEmpty() )
949 sFilterExt +=
"*.vor";
951 sFilterName +=
" (" + sFilterExt +
")";
953 aFileDlg.
AddFilter( sFilterName, sFilterExt );
963 if (!aFiles.hasElements())
971 OUString aTemplateList;
973 for (
const auto& rFile : aFiles)
977 if (aTemplateList.isEmpty())
978 aTemplateList = rFile;
980 aTemplateList +=
"\n" + rFile;
984 if (!aTemplateList.isEmpty())
986 OUString aMsg(
SfxResId(STR_MSG_ERROR_IMPORT));
987 aMsg = aMsg.replaceFirst(
"$1",pContItem->
maTitle);
989 VclMessageType::Warning, VclButtonsType::Ok,
990 aMsg.replaceFirst(
"$2",aTemplateList)));
1000 xFolderPicker->setDisplayDirectory(
SvtPathOptions().GetWorkPath());
1002 sal_Int16 nResult = xFolderPicker->execute();
1005 if( nResult != ExecutableDialogResults::OK )
1008 OUString aTemplateList;
1016 for (
auto const& selTemplate : aSelTemplates)
1033 if (aTemplateList.isEmpty())
1034 aTemplateList = pItem->
maTitle;
1036 aTemplateList +=
"\n" + pItem->
maTitle;
1042 if (!aTemplateList.isEmpty())
1044 OUString aText(
SfxResId(STR_MSG_ERROR_EXPORT) );
1046 VclMessageType::Warning, VclButtonsType::Ok,
1047 aText.replaceFirst(
"$1",aTemplateList)));
1052 OUString sText(
SfxResId(STR_MSG_EXPORT_SUCCESS) );
1054 VclMessageType::Info, VclButtonsType::Ok,
1055 sText.replaceFirst(
"$1", OUString::number(
nCount))));
1064 OpenTemplateHdl(pItem);
1071 int ret = dlg.
run();
1082 OUString aMsg(
SfxResId(STR_CREATE_ERROR) );
1084 VclMessageType::Warning, VclButtonsType::Ok,
1085 aMsg.replaceFirst(
"$1",
aName)));
1092 OUString sCategory =
mxCBFolder->get_active_text();
1096 int ret = dlg.
run();
1115 OUString aMsg(
SfxResId(STR_CREATE_ERROR) );
1117 VclMessageType::Warning, VclButtonsType::Ok,
1118 aMsg.replaceFirst(
"$1",
aName)));
1125 const auto sCategory =
mxCBFolder->get_active_text();
1127 VclMessageType::Question, VclButtonsType::YesNo,
1128 SfxResId(STR_QMSG_SEL_FOLDER_DELETE).replaceFirst(
"$1",sCategory)));
1129 if (popupDlg->run() !=
RET_YES)
1132 sal_Int16 nItemId =
mxLocalView->getRegionId(sCategory);
1136 OUString sMsg(
SfxResId(STR_MSG_ERROR_DELETE_FOLDER) );
1138 VclMessageType::Warning, VclButtonsType::Ok,
1139 sMsg.replaceFirst(
"$1",sCategory)));
1218 if ( !rFileURL.isEmpty() )
1222 uno::Reference< embed::XStorage > xStorage =
1231 rName = pFilter->GetServiceName();
1235 catch( uno::Exception& )
1245 std::vector<OUString> aList;
1265 : GenericDialogController(pParent,
"sfx/ui/templatecategorydlg.ui",
"TemplatesCategoryDialog")
1266 , mbIsNewCategory(false)
1267 , mxLBCategory(m_xBuilder->weld_tree_view(
"categorylb"))
1268 , mxNewCategoryEdit(m_xBuilder->weld_entry(
"category_entry"))
1269 , mxOKButton(m_xBuilder->weld_button(
"ok"))
1286 mxLBCategory->set_sensitive(sParam.isEmpty());
1287 if(!sParam.isEmpty())
1289 msSelectedCategory = sParam;
1290 mbIsNewCategory =
true;
1291 mxOKButton->set_sensitive(
true);
1295 SelectCategoryHdl(*mxLBCategory);
1296 mbIsNewCategory =
false;
1302 if (mxLBCategory->get_selected_index() == 0)
1304 msSelectedCategory = OUString();
1305 mxOKButton->set_sensitive(
false);
1306 mxNewCategoryEdit->set_sensitive(
true);
1310 msSelectedCategory = mxLBCategory->get_selected_text();
1311 mxNewCategoryEdit->set_sensitive(
false);
1312 mxOKButton->set_sensitive(
true);
1315 mbIsNewCategory =
false;
1320 for (
size_t i = 0,
n = aFolderNames.size();
i <
n; ++
i)
1329 , maIdle(
"sfx2 SfxTemplateManagerDlg maIdle")
1341 mxCBApp->set_sensitive(
false);
1362 m_xDialog->set_centered_on_parent(
true);
1375 m_xDialog->set_centered_on_parent(
false);
1381 msTemplatePath = pViewItem->
getPath();
1389 msTemplatePath = pViewItem->
getPath();
SfxApplication * SfxGetpApp()
Reference< XExecutableDialog > m_xDialog
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
OUString getName(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true, DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
OUString getExtension(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true, DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
bool setName(std::u16string_view rTheName, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
bool Append(std::u16string_view rTheSegment, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
virtual void Start(bool bStartTimer=true) override
SfxFilterMatcher & GetFilterMatcher()
std::shared_ptr< const SfxFilter > GetFilter4ClipBoardId(SotClipboardFormatId nId, SfxFilterFlags nMust=SfxFilterFlags::IMPORT, SfxFilterFlags nDont=SFX_FILTER_NOTINSTALLED) const
static SfxModule * GetActiveModule(SfxViewFrame *pFrame=nullptr)
static void SetStandardTemplate(const OUString &rServiceName, const OUString &rTemplateName)
static OUString GetStandardTemplate(std::u16string_view rServiceName)
static OUString GetServiceNameFromFactory(const OUString &rFact)
std::unique_ptr< weld::TreeView > mxLBCategory
std::unique_ptr< weld::Entry > mxNewCategoryEdit
virtual ~SfxTemplateCategoryDialog() override
const OUString & GetSelectedCategory() const
bool IsNewCategoryCreated() const
void SetCategoryLBEntries(std::vector< OUString > names)
SfxTemplateCategoryDialog(weld::Window *pParent)
std::unique_ptr< weld::Button > mxOKButton
FILTER_APPLICATION getCurrentApplicationFilter() const
Return filter according to the currently selected application filter.
SfxTemplateManagerDlg(weld::Window *parent)
TemplateViewMode getTemplateViewMode() const
void OnTemplateImportCategory(std::u16string_view sCategory)
std::unique_ptr< weld::Entry > mxSearchFilter
TemplateViewMode mViewMode
std::unique_ptr< weld::MenuButton > mxActionBar
void getApplicationSpecificSettings()
void DefaultTemplateMenuSelectHdl(std::u16string_view rIdent)
void OnTemplateState(const ThumbnailViewItem *pItem)
void fillFolderComboBox()
virtual short run() override
static void ExtensionsActionHdl()
std::set< const ThumbnailViewItem *, selection_cmp_fn > maSelTemplates
std::unique_ptr< weld::CheckButton > mxCBXHideDlg
std::unique_ptr< weld::Toggleable > mxThumbnailViewButton
std::unique_ptr< weld::CustomWeld > mxLocalViewWeld
virtual ~SfxTemplateManagerDlg() override
void setTemplateViewMode(TemplateViewMode eViewMode)
void localMoveTo(sal_uInt16 nMenuId)
Move templates stored in the filesystem to another folder.
css::uno::Reference< css::frame::XModel > m_xModel
std::unique_ptr< weld::ComboBox > mxCBApp
std::unique_ptr< weld::Button > mxOKButton
std::unique_ptr< TemplateDlgLocalView > mxLocalView
void setDocumentModel(const css::uno::Reference< css::frame::XModel > &rModel)
std::unique_ptr< weld::Toggleable > mxListViewButton
std::unique_ptr< weld::ComboBox > mxCBFolder
virtual ~SfxTemplateSelectionDlg() override
SfxTemplateSelectionDlg(weld::Window *parent)
virtual short run() override
static SotClipboardFormatId GetFormatID(css::uno::Reference< css::embed::XStorage > const &xStorage)
bool IsModuleInstalled(EModule eModule) const
OUString GetFactoryEmptyDocumentURL(EFactory eFactory) const
OUString GetFactoryStandardTemplate(EFactory eFactory) const
css::uno::Sequence< OUString > GetAllServiceNames()
static EFactory ClassifyFactoryByModel(const css::uno::Reference< css::frame::XModel > &xModel)
static bool ClassifyFactoryByName(std::u16string_view sName, EFactory &eFactory)
css::uno::Any GetUserItem(const OUString &sName) const
void SetUserData(const css::uno::Sequence< css::beans::NamedValue > &lData)
void SetPriority(TaskPriority ePriority)
static bool IsInternalTemplate(const OUString &rPath)
bool IsDefaultTemplate() const
const OUString & getPath() const
void showDefaultIcon(bool bVal)
void SetTimeout(sal_uInt64 nTimeoutMs)
void SetInvokeHandler(const Link< Timer *, void > &rLink)
static bool isFilteredExtension(FILTER_APPLICATION filter, std::u16string_view rExt)
static css::uno::Reference< css::embed::XStorage > GetStorageFromURL(const OUString &aURL, sal_Int32 nStorageMode, const css::uno::Reference< css::uno::XComponentContext > &rxContext=css::uno::Reference< css::uno::XComponentContext >())
void AddFilter(const OUString &rFilterName, const OUString &rExtension)
css::uno::Sequence< OUString > GetSelectedFiles() const
Provides the selected files with full path information.
void SetCurrentFilter(const OUString &rFilter)
void SetContext(Context _eNewContext)
sets the context of the dialog and trigger necessary actions e.g.
sal_uInt16 GetCode() const
void set_title(const OUString &rTitle)
std::shared_ptr< weld::Dialog > m_xDialog
Sequence< OUString > aServiceNames
constexpr OUStringLiteral FILEDIALOG_FILTER_ALL
constexpr sal_uInt16 KEY_ESCAPE
#define LINK(Instance, Class, Member)
Implementation of the interface com.sun.star.rdf.XDocumentMetadataAccess.
OString strip(const OString &rIn, char c)
bool dispatchCommand(const OUString &rCommand, const uno::Reference< css::frame::XFrame > &rFrame, const css::uno::Sequence< css::beans::PropertyValue > &rArguments, const uno::Reference< css::frame::XDispatchResultListener > &rListener)
Reference< XComponentContext > getProcessComponentContext()
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
css::uno::Reference< css::deployment::XPackageRegistry > create(css::uno::Reference< css::deployment::XPackageRegistry > const &xRootRegistry, OUString const &context, OUString const &cachePath, css::uno::Reference< css::uno::XComponentContext > const &xComponentContext)
css::uno::Reference< css::ui::dialogs::XFolderPicker2 > createFolderPicker(const css::uno::Reference< css::uno::XComponentContext > &rContext, weld::Window *pPreferredParent)
OUString SfxResId(TranslateId aId)
static bool cmpSelectionItems(const ThumbnailViewItem *pItem1, const ThumbnailViewItem *pItem2)
constexpr OUStringLiteral MNI_ACTION_DELETE_FOLDER
constexpr OUStringLiteral MNI_ACTION_DEFAULT_WRITER
IMPL_LINK(SfxTemplateManagerDlg, KeyInputHdl, const KeyEvent &, rKeyEvent, bool)
constexpr OUStringLiteral MNI_ACTION_IMPORT
constexpr OUStringLiteral MNI_ACTION_DEFAULT_CALC
constexpr OUStringLiteral MNI_ACTION_DEFAULT_DRAW
constexpr OUStringLiteral MNI_ACTION_NEW_FOLDER
constexpr OUStringLiteral MNI_ACTION_RENAME_FOLDER
constexpr OUStringLiteral MNI_ACTION_DEFAULT_IMPRESS
IMPL_LINK_NOARG(SfxTemplateManagerDlg, SelectApplicationHdl, weld::ComboBox &, void)
constexpr OUStringLiteral TM_SETTING_LASTFOLDER
constexpr OUStringLiteral TM_SETTING_LASTAPPLICATION
constexpr OUStringLiteral TM_SETTING_VIEWMODE
static std::vector< OUString > lcl_getAllFactoryURLs()
constexpr OUStringLiteral TM_SETTING_MANAGER
static bool lcl_getServiceName(const OUString &rFileURL, OUString &rName)
constexpr OUStringLiteral MNI_ACTION_EXTENSIONS
#define MNI_ALL_APPLICATIONS
constexpr OUStringLiteral MNI_ACTION_DEFAULT
#define TEMPLATE_ITEM_MAX_HEIGHT_SUB
#define TEMPLATE_ITEM_PADDING
#define TEMPLATE_ITEM_MAX_HEIGHT
#define TEMPLATE_ITEM_MAX_WIDTH
#define TEMPLATE_ITEM_MAX_TEXT_LENGTH
#define TEMPLATE_ITEM_THUMBNAIL_MAX_HEIGHT
#define EDIT_UPDATEDATA_TIMEOUT