summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2018-03-05 13:57:56 +0000
committerCaolán McNamara <caolanm@redhat.com>2018-03-05 18:08:44 +0100
commit6ca3a21ba96f93b9ed729202ef5d4170daddd6f7 (patch)
tree997078113e3fac133aa7d3d698707842b59f29c1 /sfx2
parent5ad62544bce42396faaae2bc79c7517af6ff085b (diff)
weld SfxSaveAsTemplateDialog
Change-Id: Ia663102a2d871fdca093c0d33e5af5a79deebeb5 Reviewed-on: https://gerrit.libreoffice.org/50775 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/inc/saveastemplatedlg.hxx59
-rw-r--r--sfx2/source/doc/objserv.cxx7
-rw-r--r--sfx2/source/doc/saveastemplatedlg.cxx99
-rw-r--r--sfx2/uiconfig/ui/saveastemplatedlg.ui61
4 files changed, 149 insertions, 77 deletions
diff --git a/sfx2/inc/saveastemplatedlg.hxx b/sfx2/inc/saveastemplatedlg.hxx
new file mode 100644
index 000000000000..8e7af6d3a448
--- /dev/null
+++ b/sfx2/inc/saveastemplatedlg.hxx
@@ -0,0 +1,59 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_SFX2_INC_SAVEASTEMPLATEDLG_HXX
+#define INCLUDED_SFX2_INC_SAVEASTEMPLATEDLG_HXX
+
+#include <sal/config.h>
+#include <sfx2/doctempl.hxx>
+#include <vcl/weld.hxx>
+
+// class SfxSaveAsTemplateDialog -------------------------------------------------------------------
+class SfxSaveAsTemplateDialog
+{
+private:
+ std::unique_ptr<weld::Builder> m_xBuilder;
+ std::unique_ptr<weld::Dialog> m_xDialog;
+ std::unique_ptr<weld::TreeView> m_xLBCategory;
+ std::unique_ptr<weld::CheckButton> m_xCBXDefault;
+ std::unique_ptr<weld::Entry> m_xTemplateNameEdit;
+ std::unique_ptr<weld::Button> m_xOKButton;
+
+ OUString msSelectedCategory;
+ OUString msTemplateName;
+ sal_uInt16 mnRegionPos;
+
+ std::vector<OUString> msCategories;
+
+ SfxDocumentTemplates maDocTemplates;
+
+ css::uno::Reference<css::frame::XModel> m_xModel;
+
+public:
+ DECL_LINK(OkClickHdl, weld::Button&, void);
+ DECL_LINK(TemplateNameEditHdl, weld::Entry&, void);
+ DECL_LINK(SelectCategoryHdl, weld::TreeView&, void);
+
+ void initialize();
+ void SetCategoryLBEntries(const std::vector<OUString>& names);
+
+ /*Check whether template name is unique or not in a region*/
+ bool IsTemplateNameUnique();
+
+ bool SaveTemplate();
+
+public:
+ SfxSaveAsTemplateDialog(weld::Window* pParent,
+ const css::uno::Reference<css::frame::XModel>& rModel);
+ short run() { return m_xDialog->run(); }
+};
+
+#endif // INCLUDED_SFX2_INC_SAVEASTEMPLATEDLG_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx
index aaf71fb25586..5af4ef033706 100644
--- a/sfx2/source/doc/objserv.cxx
+++ b/sfx2/source/doc/objserv.cxx
@@ -97,7 +97,7 @@
#include <com/sun/star/document/XDocumentProperties.hpp>
#include <guisaveas.hxx>
-#include <sfx2/saveastemplatedlg.hxx>
+#include <saveastemplatedlg.hxx>
#include <memory>
#include <cppuhelper/implbase.hxx>
#include <unotools/ucbstreamhelper.hxx>
@@ -795,9 +795,8 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
case SID_DOCTEMPLATE:
{
// save as document templates
- ScopedVclPtrInstance<SfxSaveAsTemplateDialog> aDlg;
- aDlg->setDocumentModel(GetModel());
- aDlg->Execute();
+ SfxSaveAsTemplateDialog aDlg(rReq.GetFrameWeld(), GetModel());
+ aDlg.run();
break;
}
diff --git a/sfx2/source/doc/saveastemplatedlg.cxx b/sfx2/source/doc/saveastemplatedlg.cxx
index 168c39bc7e79..efdb861d86a8 100644
--- a/sfx2/source/doc/saveastemplatedlg.cxx
+++ b/sfx2/source/doc/saveastemplatedlg.cxx
@@ -7,8 +7,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
-#include <sfx2/saveastemplatedlg.hxx>
-
#include <comphelper/processfactory.hxx>
#include <comphelper/string.hxx>
#include <comphelper/storagehelper.hxx>
@@ -28,57 +26,42 @@
#include <sfx2/strings.hrc>
+#include <saveastemplatedlg.hxx>
+
using namespace ::com::sun::star;
using namespace ::com::sun::star::frame;
// Class SfxSaveAsTemplateDialog --------------------------------------------------
-SfxSaveAsTemplateDialog::SfxSaveAsTemplateDialog():
- ModalDialog(nullptr, "SaveAsTemplateDialog", "sfx/ui/saveastemplatedlg.ui"),
- msSelectedCategory(OUString()),
- msTemplateName(OUString()),
- mnRegionPos(0)
+SfxSaveAsTemplateDialog::SfxSaveAsTemplateDialog(weld::Window* pParent, const uno::Reference<frame::XModel> &rModel)
+ : m_xBuilder(Application::CreateBuilder(pParent, "sfx/ui/saveastemplatedlg.ui"))
+ , m_xDialog(m_xBuilder->weld_dialog("SaveAsTemplateDialog"))
+ , m_xLBCategory(m_xBuilder->weld_tree_view("categorylb"))
+ , m_xCBXDefault(m_xBuilder->weld_check_button("defaultcb"))
+ , m_xTemplateNameEdit(m_xBuilder->weld_entry("name_entry"))
+ , m_xOKButton(m_xBuilder->weld_button("ok"))
+ , msSelectedCategory(OUString())
+ , msTemplateName(OUString())
+ , mnRegionPos(0)
+ , m_xModel(rModel)
{
- get(mpLBCategory, "categorylb");
- get(mpCBXDefault, "defaultcb");
- get(mpTemplateNameEdit, "name_entry");
- get(mpOKButton, "ok");
-
initialize();
SetCategoryLBEntries(msCategories);
- mpTemplateNameEdit->SetModifyHdl(LINK(this, SfxSaveAsTemplateDialog, TemplateNameEditHdl));
- mpLBCategory->SetSelectHdl(LINK(this, SfxSaveAsTemplateDialog, SelectCategoryHdl));
- mpOKButton->SetClickHdl(LINK(this, SfxSaveAsTemplateDialog, OkClickHdl));
+ m_xTemplateNameEdit->connect_changed(LINK(this, SfxSaveAsTemplateDialog, TemplateNameEditHdl));
+ m_xLBCategory->connect_changed(LINK(this, SfxSaveAsTemplateDialog, SelectCategoryHdl));
+ m_xLBCategory->set_size_request(m_xLBCategory->get_approximate_char_width() * 32,
+ m_xLBCategory->get_height_rows(8));
+ m_xOKButton->connect_clicked(LINK(this, SfxSaveAsTemplateDialog, OkClickHdl));
- mpOKButton->Disable();
- mpOKButton->SetText(SfxResId(STR_SAVEDOC));
-}
-
-SfxSaveAsTemplateDialog::~SfxSaveAsTemplateDialog()
-{
- disposeOnce();
-}
-
-void SfxSaveAsTemplateDialog::dispose()
-{
- mpLBCategory.clear();
- mpTemplateNameEdit.clear();
- mpOKButton.clear();
- mpCBXDefault.clear();
-
- ModalDialog::dispose();
-}
-
-void SfxSaveAsTemplateDialog::setDocumentModel(const uno::Reference<frame::XModel> &rModel)
-{
- m_xModel = rModel;
+ m_xOKButton->set_sensitive(false);
+ m_xOKButton->set_label(SfxResId(STR_SAVEDOC));
}
-IMPL_LINK_NOARG(SfxSaveAsTemplateDialog, OkClickHdl, Button*, void)
+IMPL_LINK_NOARG(SfxSaveAsTemplateDialog, OkClickHdl, weld::Button&, void)
{
- std::unique_ptr<weld::MessageDialog> xQueryDlg(Application::CreateMessageDialog(GetFrameWeld(), VclMessageType::Question, VclButtonsType::YesNo,
- OUString()));
+ std::unique_ptr<weld::MessageDialog> xQueryDlg(Application::CreateMessageDialog(m_xDialog.get(), VclMessageType::Question,
+ VclButtonsType::YesNo, OUString()));
if(!IsTemplateNameUnique())
{
OUString sQueryMsg(SfxResId(STR_QMSG_TEMPLATE_OVERWRITE));
@@ -89,34 +72,34 @@ IMPL_LINK_NOARG(SfxSaveAsTemplateDialog, OkClickHdl, Button*, void)
return;
}
- if(SaveTemplate())
- Close();
+ if (SaveTemplate())
+ m_xDialog->response(RET_OK);
else
{
OUString sText( SfxResId(STR_ERROR_SAVEAS) );
- std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(GetFrameWeld(), VclMessageType::Warning, VclButtonsType::Ok,
- sText.replaceFirst("$1", msTemplateName)));
+ std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(), VclMessageType::Warning,
+ VclButtonsType::Ok, sText.replaceFirst("$1", msTemplateName)));
xBox->run();
}
}
-IMPL_LINK_NOARG(SfxSaveAsTemplateDialog, TemplateNameEditHdl, Edit&, void)
+IMPL_LINK_NOARG(SfxSaveAsTemplateDialog, TemplateNameEditHdl, weld::Entry&, void)
{
- msTemplateName = comphelper::string::strip(mpTemplateNameEdit->GetText(), ' ');
- SelectCategoryHdl(*mpLBCategory);
+ msTemplateName = comphelper::string::strip(m_xTemplateNameEdit->get_text(), ' ');
+ SelectCategoryHdl(*m_xLBCategory);
}
-IMPL_LINK_NOARG(SfxSaveAsTemplateDialog, SelectCategoryHdl, ListBox&, void)
+IMPL_LINK_NOARG(SfxSaveAsTemplateDialog, SelectCategoryHdl, weld::TreeView&, void)
{
- if(mpLBCategory->GetSelectedEntryPos() == 0)
+ if (m_xLBCategory->get_selected_index() == 0)
{
msSelectedCategory = OUString();
- mpOKButton->Disable();
+ m_xOKButton->set_sensitive(false);
}
else
{
- msSelectedCategory = mpLBCategory->GetSelectedEntry();
- mpOKButton->Enable(!msTemplateName.isEmpty());
+ msSelectedCategory = m_xLBCategory->get_selected();
+ m_xOKButton->set_sensitive(!msTemplateName.isEmpty());
}
}
@@ -130,14 +113,14 @@ void SfxSaveAsTemplateDialog::initialize()
}
}
-void SfxSaveAsTemplateDialog::SetCategoryLBEntries(std::vector<OUString> aFolderNames)
+void SfxSaveAsTemplateDialog::SetCategoryLBEntries(const std::vector<OUString>& rFolderNames)
{
- if (!aFolderNames.empty())
+ if (!rFolderNames.empty())
{
- for (size_t i = 0, n = aFolderNames.size(); i < n; ++i)
- mpLBCategory->InsertEntry(aFolderNames[i], i+1);
+ for (size_t i = 0, n = rFolderNames.size(); i < n; ++i)
+ m_xLBCategory->insert(rFolderNames[i], i+1);
}
- mpLBCategory->SelectEntryPos(0);
+ m_xLBCategory->select(0);
}
bool SfxSaveAsTemplateDialog::IsTemplateNameUnique()
@@ -173,7 +156,7 @@ bool SfxSaveAsTemplateDialog::SaveTemplate()
if (!bIsSaved)
return false;
- if ( !sURL.isEmpty() && mpCBXDefault->IsChecked() )
+ if (!sURL.isEmpty() && m_xCBXDefault->get_active())
{
OUString aServiceName;
try
diff --git a/sfx2/uiconfig/ui/saveastemplatedlg.ui b/sfx2/uiconfig/ui/saveastemplatedlg.ui
index 7a8606a08928..6f46ea921473 100644
--- a/sfx2/uiconfig/ui/saveastemplatedlg.ui
+++ b/sfx2/uiconfig/ui/saveastemplatedlg.ui
@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.18.3 -->
+<!-- Generated with glade 3.20.2 -->
<interface domain="sfx">
- <requires lib="gtk+" version="3.6"/>
- <requires lib="LibreOffice" version="1.0"/>
+ <requires lib="gtk+" version="3.20"/>
<object class="GtkListStore" id="categorylist">
<columns>
<!-- column-name gchararray1 -->
@@ -19,6 +18,8 @@
<property name="border_width">6</property>
<property name="title" translatable="yes" context="saveastemplatedlg|SaveAsTemplateDialog">Save As Template</property>
<property name="modal">True</property>
+ <property name="default_width">0</property>
+ <property name="default_height">0</property>
<property name="type_hint">normal</property>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox1">
@@ -87,22 +88,25 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_bottom">6</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
<property name="row_spacing">12</property>
<property name="column_spacing">12</property>
<child>
<object class="GtkBox" id="box1">
<property name="visible">True</property>
<property name="can_focus">False</property>
+ <property name="hexpand">True</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel" id="create_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="xalign">0</property>
<property name="label" translatable="yes" context="saveastemplatedlg|create_label">Template _Name</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">name_entry</property>
+ <property name="xalign">0</property>
<attributes>
<attribute name="weight" value="normal"/>
</attributes>
@@ -135,16 +139,17 @@
<object class="GtkBox" id="box2">
<property name="visible">True</property>
<property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel" id="select_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="xalign">0</property>
<property name="label" translatable="yes" context="saveastemplatedlg|select_label">Template _Category</property>
<property name="use_underline">True</property>
- <property name="mnemonic_widget">categorylb:border</property>
+ <property name="xalign">0</property>
<attributes>
<attribute name="weight" value="normal"/>
</attributes>
@@ -156,15 +161,38 @@
</packing>
</child>
<child>
- <object class="GtkTreeView" id="categorylb:border">
- <property name="width_request">300</property>
- <property name="height_request">150</property>
+ <object class="GtkScrolledWindow" id="scroll">
<property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="border_width">2</property>
- <property name="model">categorylist</property>
- <child internal-child="selection">
- <object class="GtkTreeSelection" id="treeview-selection1"/>
+ <property name="can_focus">True</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <property name="shadow_type">in</property>
+ <child>
+ <object class="GtkTreeView" id="categorylb">
+ <property name="height_request">146</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <property name="model">categorylist</property>
+ <property name="headers_visible">False</property>
+ <property name="headers_clickable">False</property>
+ <property name="enable_search">False</property>
+ <property name="show_expanders">False</property>
+ <child internal-child="selection">
+ <object class="GtkTreeSelection" id="treeview-selection1"/>
+ </child>
+ <child>
+ <object class="GtkTreeViewColumn" id="treeviewcolumn1">
+ <child>
+ <object class="GtkCellRendererText" id="cellrenderertext1"/>
+ <attributes>
+ <attribute name="text">0</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
+ </object>
</child>
</object>
<packing>
@@ -196,7 +224,7 @@
</child>
</object>
<packing>
- <property name="expand">False</property>
+ <property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
@@ -208,5 +236,8 @@
<action-widget response="-5">ok</action-widget>
<action-widget response="-6">cancel</action-widget>
</action-widgets>
+ <child>
+ <placeholder/>
+ </child>
</object>
</interface>