/src/libreoffice/sfx2/source/dialog/newstyle.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 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #include <svl/style.hxx> |
21 | | |
22 | | #include <sfx2/newstyle.hxx> |
23 | | #include <sfx2/strings.hrc> |
24 | | #include <sfx2/sfxresid.hxx> |
25 | | #include <vcl/svapp.hxx> |
26 | | #include <vcl/vclenum.hxx> |
27 | | #include <vcl/weld/Builder.hxx> |
28 | | #include <vcl/weld/Dialog.hxx> |
29 | | #include <vcl/weld/MessageDialog.hxx> |
30 | | #include <vcl/weld/weld.hxx> |
31 | | |
32 | | // Private methods ------------------------------------------------------ |
33 | | |
34 | | IMPL_LINK_NOARG(SfxNewStyleDlg, OKClickHdl, weld::Button&, void) |
35 | 0 | { |
36 | 0 | const OUString aName(m_xColBox->get_active_text()); |
37 | 0 | SfxStyleSheetBase* pStyle = m_rPool.Find(aName, m_eSearchFamily); |
38 | 0 | if ( pStyle ) |
39 | 0 | { |
40 | 0 | if ( !pStyle->IsUserDefined() ) |
41 | 0 | { |
42 | 0 | std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(), |
43 | 0 | VclMessageType::Info, VclButtonsType::Ok, |
44 | 0 | SfxResId(STR_POOL_STYLE_NAME))); |
45 | 0 | xBox->run(); |
46 | 0 | return; |
47 | 0 | } |
48 | | |
49 | 0 | if (RET_YES == m_xQueryOverwriteBox->run()) |
50 | 0 | m_xDialog->response(RET_OK); |
51 | 0 | } |
52 | 0 | else |
53 | 0 | m_xDialog->response(RET_OK); |
54 | 0 | } |
55 | | |
56 | | IMPL_LINK_NOARG(SfxNewStyleDlg, OKHdl, const weld::TreeIter&, bool) |
57 | 0 | { |
58 | 0 | OKClickHdl(*m_xOKBtn); |
59 | 0 | return true; |
60 | 0 | } |
61 | | |
62 | | IMPL_LINK(SfxNewStyleDlg, ModifyHdl, weld::ComboBox&, rBox, void) |
63 | 0 | { |
64 | 0 | m_xOKBtn->set_sensitive(!rBox.get_active_text().replaceAll(" ", "").isEmpty()); |
65 | 0 | } |
66 | | |
67 | | SfxNewStyleDlg::SfxNewStyleDlg(weld::Widget* pParent, SfxStyleSheetBasePool& rInPool, SfxStyleFamily eFam) |
68 | 0 | : GenericDialogController(pParent, u"sfx/ui/newstyle.ui"_ustr, u"CreateStyleDialog"_ustr) |
69 | 0 | , m_rPool(rInPool) |
70 | 0 | , m_eSearchFamily(eFam) |
71 | 0 | , m_xColBox(m_xBuilder->weld_entry_tree_view(u"stylegrid"_ustr, u"stylename"_ustr, u"styles"_ustr)) |
72 | 0 | , m_xOKBtn(m_xBuilder->weld_button(u"ok"_ustr)) |
73 | 0 | , m_xQueryOverwriteBox(Application::CreateMessageDialog(m_xDialog.get(), VclMessageType::Question, VclButtonsType::YesNo, |
74 | 0 | SfxResId(STR_QUERY_OVERWRITE))) |
75 | 0 | { |
76 | 0 | m_xColBox->set_entry_width_chars(20); |
77 | 0 | m_xColBox->set_height_request_by_rows(8); |
78 | |
|
79 | 0 | m_xOKBtn->connect_clicked(LINK(this, SfxNewStyleDlg, OKClickHdl)); |
80 | 0 | m_xColBox->connect_changed(LINK(this, SfxNewStyleDlg, ModifyHdl)); |
81 | 0 | m_xColBox->connect_item_activated(LINK(this, SfxNewStyleDlg, OKHdl)); |
82 | |
|
83 | 0 | auto xIter = m_rPool.CreateIterator(eFam, SfxStyleSearchBits::UserDefined); |
84 | 0 | SfxStyleSheetBase *pStyle = xIter->First(); |
85 | 0 | while (pStyle) |
86 | 0 | { |
87 | 0 | m_xColBox->append_text(pStyle->GetName()); |
88 | 0 | pStyle = xIter->Next(); |
89 | 0 | } |
90 | 0 | } |
91 | | |
92 | | SfxNewStyleDlg::~SfxNewStyleDlg() |
93 | 0 | { |
94 | 0 | } |
95 | | |
96 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |