LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / sfx2 / source / dialog / styledlg.cxx
blob2614083f8f75a3678cd0251535fca708debf994d
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/whiter.hxx>
21 #include <svl/style.hxx>
23 #include <sfx2/styledlg.hxx>
24 #include <sfx2/sfxresid.hxx>
25 #include <sfx2/strings.hrc>
27 #include "mgetempl.hxx"
29 /* [Description]
31 Constructor: Add Manage TabPage, set ExampleSet from style.
33 SfxStyleDialogController::SfxStyleDialogController
35 weld::Window* pParent, // Parent
36 const OUString& rUIXMLDescription, const OString& rID,
37 SfxStyleSheetBase& rStyle // stylesheet to be processed
39 : SfxTabDialogController(pParent, rUIXMLDescription, rID, &rStyle.GetItemSet(), true)
40 , m_rStyle(rStyle)
42 // without ParentSupport suppress the standardButton
43 if (!rStyle.HasParentSupport())
44 RemoveStandardButton();
46 AddTabPage("organizer", SfxManageStyleSheetPage::Create, nullptr);
48 // With new template always set the management page as the current page
49 if (rStyle.GetName().isEmpty())
50 SetCurPageId("organizer");
51 else
53 OUString sTxt = m_xDialog->get_title() + ": " + rStyle.GetName();
54 m_xDialog->set_title(sTxt);
56 m_xExampleSet.reset(&m_rStyle.GetItemSet()); // in SfxTabDialog::Ctor() already created, reset will delete it
58 GetCancelButton().connect_clicked(LINK(this, SfxStyleDialogController, CancelHdl));
61 /* [Description]
63 Destructor: set ExampleSet to NULL, so that SfxTabDialog does not delete
64 the Set from Style.
66 SfxStyleDialogController::~SfxStyleDialogController()
68 m_xExampleSet.release();
71 /* [Description]
73 Override so that always RET_OK is returned.
75 short SfxStyleDialogController::Ok()
77 SfxTabDialogController::Ok();
78 return RET_OK;
81 /* [Description]
83 If the dialogue was canceled, then all selected attributes must be reset
84 again.
86 IMPL_LINK_NOARG(SfxStyleDialogController, CancelHdl, weld::Button&, void)
88 SfxTabPage* pPage = GetTabPage("organizer");
90 const SfxItemSet* pInSet = GetInputSetImpl();
91 SfxWhichIter aIter(*pInSet);
92 sal_uInt16 nWhich = aIter.FirstWhich();
94 while (nWhich)
96 SfxItemState eState = pInSet->GetItemState(nWhich, false);
98 if (SfxItemState::DEFAULT == eState)
99 m_xExampleSet->ClearItem(nWhich);
100 else
101 m_xExampleSet->Put(pInSet->Get(nWhich));
102 nWhich = aIter.NextWhich();
105 if (pPage)
106 pPage->Reset(GetInputSetImpl());
108 m_xDialog->response(RET_CANCEL);
111 OUString SfxStyleDialogController::GenerateUnusedName(SfxStyleSheetBasePool &rPool, SfxStyleFamily eFam)
113 OUString aNo(SfxResId(STR_NONAME));
114 sal_uInt16 i = 1;
115 OUString aNoName = aNo + OUString::number(i);
116 while (rPool.Find(aNoName, eFam))
118 ++i;
119 aNoName = aNo + OUString::number(i);
121 return aNoName;
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */