include/sfx2/saveastemplatedlg.hxx | 2 ++ sfx2/source/doc/saveastemplatedlg.cxx | 33 ++++++++++++++++++++++++++++++++- sfx2/uiconfig/ui/saveastemplatedlg.ui | 18 ++++++++++++++++-- 3 files changed, 50 insertions(+), 3 deletions(-)
New commits: commit f944195baabfda068cc37bd4e8ddf60e6cc990b7 Author: Akshay Deep <akshaydeepi...@gmail.com> Date: Sun Jun 5 07:53:03 2016 +0530 tdf#94131 Easier access to set a default template when saving a template Change-Id: I2a3732a178f47ce49c77089a6e0865b609efd499 Reviewed-on: https://gerrit.libreoffice.org/25916 Reviewed-by: Samuel Mehrbrodt <samuel.mehrbr...@cib.de> Tested-by: Samuel Mehrbrodt <samuel.mehrbr...@cib.de> diff --git a/include/sfx2/saveastemplatedlg.hxx b/include/sfx2/saveastemplatedlg.hxx index 691d4f0..bc3eade 100644 --- a/include/sfx2/saveastemplatedlg.hxx +++ b/include/sfx2/saveastemplatedlg.hxx @@ -18,6 +18,7 @@ class Edit; class ListBox; +class CheckBox; class SfxDocumentTemplates; // class SfxSaveAsTemplateDialog ------------------------------------------------------------------- @@ -27,6 +28,7 @@ class SFX2_DLLPUBLIC SfxSaveAsTemplateDialog : public ModalDialog private: VclPtr<ListBox> mpLBCategory; + VclPtr<CheckBox> mpCBXDefault; VclPtr<Edit> mpTemplateNameEdit; VclPtr<PushButton> mpOKButton; diff --git a/sfx2/source/doc/saveastemplatedlg.cxx b/sfx2/source/doc/saveastemplatedlg.cxx index 28025e1..3042b4b 100644 --- a/sfx2/source/doc/saveastemplatedlg.cxx +++ b/sfx2/source/doc/saveastemplatedlg.cxx @@ -11,13 +11,20 @@ #include <comphelper/processfactory.hxx> #include <comphelper/string.hxx> +#include <comphelper/storagehelper.hxx> #include <sfx2/sfxresid.hxx> +#include <sfx2/app.hxx> +#include <sfx2/fcontnr.hxx> +#include <sfx2/docfac.hxx> #include <sfx2/doctempl.hxx> +#include <sfx2/docfilt.hxx> #include <vcl/edit.hxx> #include <vcl/layout.hxx> #include <vcl/lstbox.hxx> +#include <sot/storage.hxx> #include <com/sun/star/frame/DocumentTemplates.hpp> +#include <com/sun/star/frame/XStorable.hpp> #include "doc.hrc" @@ -34,6 +41,7 @@ SfxSaveAsTemplateDialog::SfxSaveAsTemplateDialog( vcl::Window* pParent): mpDocTemplates(new SfxDocumentTemplates) { get(mpLBCategory, "categorylb"); + get(mpCBXDefault, "defaultcb"); get(mpTemplateNameEdit, "name_entry"); get(mpOKButton, "ok"); @@ -158,10 +166,33 @@ bool SfxSaveAsTemplateDialog::SaveTemplate() sal_uInt16 nDocId = mpDocTemplates->GetCount(mnRegionPos); OUString sURL = mpDocTemplates->GetTemplateTargetURLFromComponent(msSelectedCategory, msTemplateName); + bool bIsSaved = mpDocTemplates->InsertTemplate( mnRegionPos, nDocId, msTemplateName, sURL); - if(!mpDocTemplates->InsertTemplate( mnRegionPos, nDocId, msTemplateName, sURL)) + if (!bIsSaved) return false; + if ( !sURL.isEmpty() && mpCBXDefault->IsChecked() ) + { + OUString aServiceName; + try + { + uno::Reference< embed::XStorage > xStorage = + comphelper::OStorageHelper::GetStorageFromURL( sURL, embed::ElementModes::READ ); + + SotClipboardFormatId nFormat = SotStorage::GetFormatID( xStorage ); + + std::shared_ptr<const SfxFilter> pFilter = SfxGetpApp()->GetFilterMatcher().GetFilter4ClipBoardId( nFormat ); + + if ( pFilter ) + aServiceName = pFilter->GetServiceName(); + } + catch( uno::Exception& ) + {} + + if(!aServiceName.isEmpty()) + SfxObjectFactory::SetStandardTemplate(aServiceName, sURL); + } + mpDocTemplates->Update(); return true; } diff --git a/sfx2/uiconfig/ui/saveastemplatedlg.ui b/sfx2/uiconfig/ui/saveastemplatedlg.ui index da673a3..d8ff31c 100644 --- a/sfx2/uiconfig/ui/saveastemplatedlg.ui +++ b/sfx2/uiconfig/ui/saveastemplatedlg.ui @@ -113,9 +113,9 @@ </child> <child> <object class="GtkEntry" id="name_entry"> + <property name="width_request">300</property> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="width_request">300</property> </object> <packing> <property name="expand">False</property> @@ -153,8 +153,8 @@ </child> <child> <object class="GtkTreeView" id="categorylb:border"> - <property name="height_request">150</property> <property name="width_request">300</property> + <property name="height_request">150</property> <property name="visible">True</property> <property name="can_focus">False</property> <property name="border_width">2</property> @@ -175,6 +175,20 @@ <property name="top_attach">1</property> </packing> </child> + <child> + <object class="GtkCheckButton" id="defaultcb"> + <property name="label" translatable="yes">Set as Default Template</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="xalign">0</property> + <property name="draw_indicator">True</property> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">2</property> + </packing> + </child> </object> <packing> <property name="expand">False</property> _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits