LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / sfx2 / source / sidebar / UnoDecks.cxx
blobcbd9d1c214e775f262855928a59c0e414b372594
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 */
11 #include <sal/config.h>
13 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
14 #include <sidebar/UnoDecks.hxx>
15 #include <sidebar/UnoDeck.hxx>
17 #include <sfx2/sidebar/ResourceManager.hxx>
18 #include <sfx2/sidebar/SidebarController.hxx>
20 #include <vcl/svapp.hxx>
22 #include <algorithm>
24 using namespace css;
25 using namespace ::sfx2::sidebar;
27 SfxUnoDecks::SfxUnoDecks(const uno::Reference<frame::XFrame>& rFrame):
28 xFrame(rFrame)
32 SidebarController* SfxUnoDecks::getSidebarController()
34 return SidebarController::GetSidebarControllerForFrame(xFrame);
37 // XNameAccess
39 uno::Any SAL_CALL SfxUnoDecks::getByName( const OUString& aName )
41 SolarMutexGuard aGuard;
43 if (!hasByName(aName))
44 throw container::NoSuchElementException();
46 uno::Reference<ui::XDeck> xDeck = new SfxUnoDeck(xFrame, aName);
47 return uno::Any(xDeck);
51 uno::Sequence< OUString > SAL_CALL SfxUnoDecks::getElementNames()
53 SolarMutexGuard aGuard;
55 SidebarController* pSidebarController = getSidebarController();
57 ResourceManager::DeckContextDescriptorContainer aDecks;
58 css::uno::Sequence< OUString > deckList(aDecks.size());
60 if (pSidebarController)
62 pSidebarController->GetResourceManager()->GetMatchingDecks (
63 aDecks,
64 pSidebarController->GetCurrentContext(),
65 pSidebarController->IsDocumentReadOnly(),
66 xFrame->getController());
68 deckList.realloc(aDecks.size());
69 std::transform(aDecks.begin(), aDecks.end(), deckList.getArray(),
70 [](const auto& rDeck) { return rDeck.msId; });
73 return deckList;
77 sal_Bool SAL_CALL SfxUnoDecks::hasByName( const OUString& aName )
79 SolarMutexGuard aGuard;
81 SidebarController* pSidebarController = getSidebarController();
83 bool bFound = false;
85 if (pSidebarController)
87 ResourceManager::DeckContextDescriptorContainer aDecks;
89 pSidebarController->GetResourceManager()->GetMatchingDecks (
90 aDecks,
91 pSidebarController->GetCurrentContext(),
92 pSidebarController->IsDocumentReadOnly(),
93 xFrame->getController());
95 bFound = std::any_of(aDecks.begin(), aDecks.end(),
96 [&aName](const ResourceManager::DeckContextDescriptor& rDeck) { return rDeck.msId == aName; });
99 return bFound;
103 // XIndexAccess
105 sal_Int32 SAL_CALL SfxUnoDecks::getCount()
107 SolarMutexGuard aGuard;
109 uno::Sequence< OUString > decks = getElementNames();
110 return decks.getLength();
113 uno::Any SAL_CALL SfxUnoDecks::getByIndex( sal_Int32 Index )
115 SolarMutexGuard aGuard;
116 uno::Any aRet;
118 uno::Sequence< OUString > decks = getElementNames();
120 if (Index > decks.getLength()-1 || Index < 0)
121 throw lang::IndexOutOfBoundsException();
123 uno::Reference<ui::XDeck> xDeck = new SfxUnoDeck(xFrame, decks[Index]);
124 aRet <<= xDeck;
125 return aRet;
129 // XElementAccess
130 uno::Type SAL_CALL SfxUnoDecks::getElementType()
132 SolarMutexGuard aGuard;
134 return uno::Type();
137 sal_Bool SAL_CALL SfxUnoDecks::hasElements()
139 SolarMutexGuard aGuard;
141 uno::Sequence< OUString > decks = getElementNames();
142 return decks.hasElements();
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */