1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <officecfg/Office/Common.hxx>
11 #include <svx/svxdlg.hxx>
12 #include <comphelper/sequence.hxx>
13 #include <comphelper/diagnose_ex.hxx>
15 #include "tsaurls.hxx"
17 using namespace ::com::sun::star
;
19 TSAURLsDialog::TSAURLsDialog(weld::Window
* pParent
)
20 : GenericDialogController(pParent
, "cui/ui/tsaurldialog.ui", "TSAURLDialog")
21 , m_xAddBtn(m_xBuilder
->weld_button("add"))
22 , m_xDeleteBtn(m_xBuilder
->weld_button("delete"))
23 , m_xOKBtn(m_xBuilder
->weld_button("ok"))
24 , m_xURLListBox(m_xBuilder
->weld_tree_view("urls"))
25 , m_xEnterAUrl(m_xBuilder
->weld_label("enteraurl"))
27 m_xURLListBox
->set_size_request(m_xURLListBox
->get_approximate_digit_width() * 28,
28 m_xURLListBox
->get_height_rows(8));
29 m_xOKBtn
->set_sensitive(false);
31 m_xAddBtn
->connect_clicked(LINK(this, TSAURLsDialog
, AddHdl_Impl
));
32 m_xDeleteBtn
->connect_clicked(LINK(this, TSAURLsDialog
, DeleteHdl_Impl
));
33 m_xOKBtn
->connect_clicked(LINK(this, TSAURLsDialog
, OKHdl_Impl
));
34 m_xURLListBox
->connect_changed(LINK(this, TSAURLsDialog
, SelectHdl
));
38 std::optional
<css::uno::Sequence
<OUString
>> aUserSetTSAURLs(
39 officecfg::Office::Common::Security::Scripting::TSAURLs::get());
42 const css::uno::Sequence
<OUString
>& rUserSetTSAURLs
= *aUserSetTSAURLs
;
43 for (auto const& userSetTSAURL
: rUserSetTSAURLs
)
45 AddTSAURL(userSetTSAURL
);
49 catch (const uno::Exception
&)
51 TOOLS_WARN_EXCEPTION("cui.options", "TSAURLsDialog::TSAURLsDialog()");
54 if (m_xURLListBox
->get_selected_index() == -1)
56 m_xDeleteBtn
->set_sensitive(false);
60 IMPL_LINK_NOARG(TSAURLsDialog
, OKHdl_Impl
, weld::Button
&, void)
62 std::shared_ptr
<comphelper::ConfigurationChanges
> batch(
63 comphelper::ConfigurationChanges::create());
65 officecfg::Office::Common::Security::Scripting::TSAURLs::set(
66 comphelper::containerToSequence(m_aURLs
), batch
);
69 m_xDialog
->response(RET_OK
);
72 TSAURLsDialog::~TSAURLsDialog() {}
74 void TSAURLsDialog::AddTSAURL(const OUString
& rURL
)
78 m_xURLListBox
->freeze();
79 m_xURLListBox
->clear();
81 for (auto const& url
: m_aURLs
)
83 m_xURLListBox
->append_text(url
);
86 m_xURLListBox
->thaw();
89 IMPL_LINK_NOARG(TSAURLsDialog
, AddHdl_Impl
, weld::Button
&, void)
92 OUString
aDesc(m_xEnterAUrl
->get_label());
94 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
95 ScopedVclPtr
<AbstractSvxNameDialog
> pDlg(
96 pFact
->CreateSvxNameDialog(m_xDialog
.get(), aURL
, aDesc
));
98 if (pDlg
->Execute() == RET_OK
)
102 m_xOKBtn
->set_sensitive(true);
104 m_xURLListBox
->unselect_all();
105 // After operations in a ListBox we have nothing selected
106 m_xDeleteBtn
->set_sensitive(false);
109 IMPL_LINK_NOARG(TSAURLsDialog
, SelectHdl
, weld::TreeView
&, void)
111 m_xDeleteBtn
->set_sensitive(true);
114 IMPL_LINK_NOARG(TSAURLsDialog
, DeleteHdl_Impl
, weld::Button
&, void)
116 int nSel
= m_xURLListBox
->get_selected_index();
120 m_aURLs
.erase(m_xURLListBox
->get_text(nSel
));
121 m_xURLListBox
->remove(nSel
);
122 m_xURLListBox
->unselect_all();
123 // After operations in a ListBox we have nothing selected
124 m_xDeleteBtn
->set_sensitive(false);
125 m_xOKBtn
->set_sensitive(true);
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */