Kaydet (Commit) f944195b authored tarafından Akshay Deep's avatar Akshay Deep Kaydeden (comit) Samuel Mehrbrodt

tdf#94131 Easier access to set a default template when saving a template

Change-Id: I2a3732a178f47ce49c77089a6e0865b609efd499
Reviewed-on: https://gerrit.libreoffice.org/25916Reviewed-by: 's avatarSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Tested-by: 's avatarSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
üst 47d0e1be
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
class Edit; class Edit;
class ListBox; class ListBox;
class CheckBox;
class SfxDocumentTemplates; class SfxDocumentTemplates;
// class SfxSaveAsTemplateDialog ------------------------------------------------------------------- // class SfxSaveAsTemplateDialog -------------------------------------------------------------------
...@@ -27,6 +28,7 @@ class SFX2_DLLPUBLIC SfxSaveAsTemplateDialog : public ModalDialog ...@@ -27,6 +28,7 @@ class SFX2_DLLPUBLIC SfxSaveAsTemplateDialog : public ModalDialog
private: private:
VclPtr<ListBox> mpLBCategory; VclPtr<ListBox> mpLBCategory;
VclPtr<CheckBox> mpCBXDefault;
VclPtr<Edit> mpTemplateNameEdit; VclPtr<Edit> mpTemplateNameEdit;
VclPtr<PushButton> mpOKButton; VclPtr<PushButton> mpOKButton;
......
...@@ -11,13 +11,20 @@ ...@@ -11,13 +11,20 @@
#include <comphelper/processfactory.hxx> #include <comphelper/processfactory.hxx>
#include <comphelper/string.hxx> #include <comphelper/string.hxx>
#include <comphelper/storagehelper.hxx>
#include <sfx2/sfxresid.hxx> #include <sfx2/sfxresid.hxx>
#include <sfx2/app.hxx>
#include <sfx2/fcontnr.hxx>
#include <sfx2/docfac.hxx>
#include <sfx2/doctempl.hxx> #include <sfx2/doctempl.hxx>
#include <sfx2/docfilt.hxx>
#include <vcl/edit.hxx> #include <vcl/edit.hxx>
#include <vcl/layout.hxx> #include <vcl/layout.hxx>
#include <vcl/lstbox.hxx> #include <vcl/lstbox.hxx>
#include <sot/storage.hxx>
#include <com/sun/star/frame/DocumentTemplates.hpp> #include <com/sun/star/frame/DocumentTemplates.hpp>
#include <com/sun/star/frame/XStorable.hpp>
#include "doc.hrc" #include "doc.hrc"
...@@ -34,6 +41,7 @@ SfxSaveAsTemplateDialog::SfxSaveAsTemplateDialog( vcl::Window* pParent): ...@@ -34,6 +41,7 @@ SfxSaveAsTemplateDialog::SfxSaveAsTemplateDialog( vcl::Window* pParent):
mpDocTemplates(new SfxDocumentTemplates) mpDocTemplates(new SfxDocumentTemplates)
{ {
get(mpLBCategory, "categorylb"); get(mpLBCategory, "categorylb");
get(mpCBXDefault, "defaultcb");
get(mpTemplateNameEdit, "name_entry"); get(mpTemplateNameEdit, "name_entry");
get(mpOKButton, "ok"); get(mpOKButton, "ok");
...@@ -158,10 +166,33 @@ bool SfxSaveAsTemplateDialog::SaveTemplate() ...@@ -158,10 +166,33 @@ bool SfxSaveAsTemplateDialog::SaveTemplate()
sal_uInt16 nDocId = mpDocTemplates->GetCount(mnRegionPos); sal_uInt16 nDocId = mpDocTemplates->GetCount(mnRegionPos);
OUString sURL = mpDocTemplates->GetTemplateTargetURLFromComponent(msSelectedCategory, msTemplateName); 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; 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(); mpDocTemplates->Update();
return true; return true;
} }
......
...@@ -113,9 +113,9 @@ ...@@ -113,9 +113,9 @@
</child> </child>
<child> <child>
<object class="GtkEntry" id="name_entry"> <object class="GtkEntry" id="name_entry">
<property name="width_request">300</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="width_request">300</property>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
...@@ -153,8 +153,8 @@ ...@@ -153,8 +153,8 @@
</child> </child>
<child> <child>
<object class="GtkTreeView" id="categorylb:border"> <object class="GtkTreeView" id="categorylb:border">
<property name="height_request">150</property>
<property name="width_request">300</property> <property name="width_request">300</property>
<property name="height_request">150</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="border_width">2</property> <property name="border_width">2</property>
...@@ -175,6 +175,20 @@ ...@@ -175,6 +175,20 @@
<property name="top_attach">1</property> <property name="top_attach">1</property>
</packing> </packing>
</child> </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> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment