/src/libreoffice/svx/source/dialog/ThemeDialog.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | */ |
9 | | |
10 | | #include <svx/dialog/ThemeDialog.hxx> |
11 | | #include <docmodel/theme/ColorSet.hxx> |
12 | | #include <docmodel/theme/Theme.hxx> |
13 | | #include <svx/ColorSets.hxx> |
14 | | #include <vcl/svapp.hxx> |
15 | | #include <vcl/vclenum.hxx> |
16 | | #include <vcl/weld/Builder.hxx> |
17 | | #include <vcl/weld/Dialog.hxx> |
18 | | #include <comphelper/lok.hxx> |
19 | | #include <vcl/virdev.hxx> |
20 | | |
21 | | namespace svx |
22 | | { |
23 | | ThemeDialog::ThemeDialog(weld::Window* pParent, model::Theme* pTheme) |
24 | 0 | : GenericDialogController(pParent, u"svx/ui/themedialog.ui"_ustr, u"ThemeDialog"_ustr) |
25 | 0 | , ThemeColorsPaneBase(m_xBuilder->weld_icon_view(u"iconview_theme_colors"_ustr)) |
26 | 0 | , mpTheme(pTheme) |
27 | 0 | , mxAdd(m_xBuilder->weld_button(u"button_add"_ustr)) |
28 | 0 | { |
29 | 0 | mxAdd->connect_clicked(LINK(this, ThemeDialog, ButtonClicked)); |
30 | |
|
31 | 0 | initColorSets(pTheme); |
32 | 0 | } |
33 | | |
34 | | ThemeDialog::~ThemeDialog() |
35 | 0 | { |
36 | 0 | if (mxSubDialog) |
37 | 0 | mxSubDialog->response(RET_CANCEL); |
38 | 0 | } |
39 | | |
40 | | void ThemeDialog::onColorSetActivated() |
41 | 0 | { |
42 | 0 | if (!comphelper::LibreOfficeKit::isActive()) |
43 | 0 | m_xDialog->response(RET_OK); |
44 | 0 | } |
45 | | |
46 | | void ThemeDialog::runThemeColorEditDialog() |
47 | 0 | { |
48 | 0 | if (mxSubDialog) |
49 | 0 | return; |
50 | | |
51 | 0 | mxSubDialog = std::make_shared<svx::ThemeColorEditDialog>(getDialog(), *mpCurrentColorSet); |
52 | |
|
53 | 0 | weld::DialogController::runAsync(mxSubDialog, [this](sal_uInt32 nResult) { |
54 | 0 | if (nResult != RET_OK) |
55 | 0 | { |
56 | 0 | mxAdd->set_sensitive(true); |
57 | 0 | mxSubDialog = nullptr; |
58 | 0 | return; |
59 | 0 | } |
60 | 0 | auto aColorSet = mxSubDialog->getColorSet(); |
61 | 0 | if (!aColorSet.getName().isEmpty()) |
62 | 0 | { |
63 | 0 | ColorSets::get().insert(aColorSet); |
64 | 0 | initColorSets(mpTheme); |
65 | |
|
66 | 0 | mxIconViewThemeColors->select(maColorSets.size() - 1); |
67 | 0 | mpCurrentColorSet |
68 | 0 | = std::make_shared<model::ColorSet>(maColorSets[maColorSets.size() - 1]); |
69 | 0 | } |
70 | 0 | mxAdd->set_sensitive(true); |
71 | 0 | mxSubDialog = nullptr; |
72 | 0 | }); |
73 | 0 | } |
74 | | |
75 | | IMPL_LINK(ThemeDialog, ButtonClicked, weld::Button&, rButton, void) |
76 | 0 | { |
77 | 0 | mxAdd->set_sensitive(false); |
78 | 0 | if (mpCurrentColorSet && mxAdd.get() == &rButton) |
79 | 0 | { |
80 | 0 | runThemeColorEditDialog(); |
81 | 0 | } |
82 | 0 | } |
83 | | |
84 | | } // end svx namespace |
85 | | |
86 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |