sd: keep a non-owning pointer to the OverridingShell
[LibreOffice.git] / sfx2 / source / dialog / newstyle.cxx
blob7e6b5f62749d5e53f9f1ddedd7ac31d29a52ca49
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svl/style.hxx>
22 #include <sfx2/newstyle.hxx>
23 #include <sfx2/strings.hrc>
24 #include <sfx2/sfxresid.hxx>
25 #include <vcl/svapp.hxx>
26 #include <vcl/weld.hxx>
28 // Private methods ------------------------------------------------------
30 IMPL_LINK_NOARG(SfxNewStyleDlg, OKClickHdl, weld::Button&, void)
32 const OUString aName(m_xColBox->get_active_text());
33 SfxStyleSheetBase* pStyle = m_rPool.Find(aName, m_eSearchFamily);
34 if ( pStyle )
36 if ( !pStyle->IsUserDefined() )
38 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
39 VclMessageType::Info, VclButtonsType::Ok,
40 SfxResId(STR_POOL_STYLE_NAME)));
41 xBox->run();
42 return;
45 if (RET_YES == m_xQueryOverwriteBox->run())
46 m_xDialog->response(RET_OK);
48 else
49 m_xDialog->response(RET_OK);
52 IMPL_LINK_NOARG(SfxNewStyleDlg, OKHdl, weld::TreeView&, bool)
54 OKClickHdl(*m_xOKBtn);
55 return true;
58 IMPL_LINK(SfxNewStyleDlg, ModifyHdl, weld::ComboBox&, rBox, void)
60 m_xOKBtn->set_sensitive(!rBox.get_active_text().replaceAll(" ", "").isEmpty());
63 SfxNewStyleDlg::SfxNewStyleDlg(weld::Widget* pParent, SfxStyleSheetBasePool& rInPool, SfxStyleFamily eFam)
64 : GenericDialogController(pParent, u"sfx/ui/newstyle.ui"_ustr, u"CreateStyleDialog"_ustr)
65 , m_rPool(rInPool)
66 , m_eSearchFamily(eFam)
67 , m_xColBox(m_xBuilder->weld_entry_tree_view(u"stylegrid"_ustr, u"stylename"_ustr, u"styles"_ustr))
68 , m_xOKBtn(m_xBuilder->weld_button(u"ok"_ustr))
69 , m_xQueryOverwriteBox(Application::CreateMessageDialog(m_xDialog.get(), VclMessageType::Question, VclButtonsType::YesNo,
70 SfxResId(STR_QUERY_OVERWRITE)))
72 m_xColBox->set_entry_width_chars(20);
73 m_xColBox->set_height_request_by_rows(8);
75 m_xOKBtn->connect_clicked(LINK(this, SfxNewStyleDlg, OKClickHdl));
76 m_xColBox->connect_changed(LINK(this, SfxNewStyleDlg, ModifyHdl));
77 m_xColBox->connect_row_activated(LINK(this, SfxNewStyleDlg, OKHdl));
79 auto xIter = m_rPool.CreateIterator(eFam, SfxStyleSearchBits::UserDefined);
80 SfxStyleSheetBase *pStyle = xIter->First();
81 while (pStyle)
83 m_xColBox->append_text(pStyle->GetName());
84 pStyle = xIter->Next();
88 SfxNewStyleDlg::~SfxNewStyleDlg()
92 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */