From 6ca3a21ba96f93b9ed729202ef5d4170daddd6f7 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Mon, 5 Mar 2018 13:57:56 +0000 Subject: weld SfxSaveAsTemplateDialog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ia663102a2d871fdca093c0d33e5af5a79deebeb5 Reviewed-on: https://gerrit.libreoffice.org/50775 Tested-by: Jenkins Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- sfx2/inc/saveastemplatedlg.hxx | 59 +++++++++++++++++++++ sfx2/source/doc/objserv.cxx | 7 ++- sfx2/source/doc/saveastemplatedlg.cxx | 99 +++++++++++++++-------------------- sfx2/uiconfig/ui/saveastemplatedlg.ui | 61 +++++++++++++++------ 4 files changed, 149 insertions(+), 77 deletions(-) create mode 100644 sfx2/inc/saveastemplatedlg.hxx (limited to 'sfx2') 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 +#include +#include + +// class SfxSaveAsTemplateDialog ------------------------------------------------------------------- +class SfxSaveAsTemplateDialog +{ +private: + std::unique_ptr m_xBuilder; + std::unique_ptr m_xDialog; + std::unique_ptr m_xLBCategory; + std::unique_ptr m_xCBXDefault; + std::unique_ptr m_xTemplateNameEdit; + std::unique_ptr m_xOKButton; + + OUString msSelectedCategory; + OUString msTemplateName; + sal_uInt16 mnRegionPos; + + std::vector msCategories; + + SfxDocumentTemplates maDocTemplates; + + css::uno::Reference 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& 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& 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 #include -#include +#include #include #include #include @@ -795,9 +795,8 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq) case SID_DOCTEMPLATE: { // save as document templates - ScopedVclPtrInstance 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 - #include #include #include @@ -28,57 +26,42 @@ #include +#include + 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 &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 &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 xQueryDlg(Application::CreateMessageDialog(GetFrameWeld(), VclMessageType::Question, VclButtonsType::YesNo, - OUString())); + std::unique_ptr 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 xBox(Application::CreateMessageDialog(GetFrameWeld(), VclMessageType::Warning, VclButtonsType::Ok, - sText.replaceFirst("$1", msTemplateName))); + std::unique_ptr 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 aFolderNames) +void SfxSaveAsTemplateDialog::SetCategoryLBEntries(const std::vector& 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 @@ - + - - + @@ -19,6 +18,8 @@ 6 Save As Template True + 0 + 0 normal @@ -87,22 +88,25 @@ True False 6 + True + True 12 12 True False + True vertical 6 True False - 0 Template _Name True name_entry + 0 @@ -135,16 +139,17 @@ True False + True + True vertical 6 True False - 0 Template _Category True - categorylb:border + 0 @@ -156,15 +161,38 @@ - - 300 - 150 + True - False - 2 - categorylist - - + True + True + True + in + + + 146 + True + True + True + True + categorylist + False + False + False + False + + + + + + + + + 0 + + + + + @@ -196,7 +224,7 @@ - False + True True 2 @@ -208,5 +236,8 @@ ok cancel + + + -- cgit