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 @@
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;
......
......@@ -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;
}
......
......@@ -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>
......
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