LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / sfx2 / source / sidebar / Sidebar.cxx
blobca48542d5403a5cf8eb784d8d60a036132133af8
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 <sfx2/sidebar/Sidebar.hxx>
21 #include <sfx2/sidebar/SidebarController.hxx>
22 #include <sfx2/sidebar/ResourceManager.hxx>
23 #include <sidebar/PanelDescriptor.hxx>
24 #include <sidebar/Tools.hxx>
25 #include <sfx2/sidebar/FocusManager.hxx>
26 #include <sfx2/childwin.hxx>
27 #include <sfx2/sfxsids.hrc>
28 #include <com/sun/star/frame/XDispatch.hpp>
30 using namespace css;
32 namespace sfx2::sidebar {
34 void Sidebar::ToggleDeck(std::u16string_view rsDeckId, SfxViewFrame* pViewFrame)
36 if (!pViewFrame)
37 return;
39 SfxChildWindow* pSidebarChildWindow = pViewFrame->GetChildWindow(SID_SIDEBAR);
40 bool bInitiallyVisible = pSidebarChildWindow && pSidebarChildWindow->IsVisible();
41 if (!bInitiallyVisible)
42 pViewFrame->ShowChildWindow(SID_SIDEBAR);
44 SidebarController* pController =
45 SidebarController::GetSidebarControllerForFrame(pViewFrame->GetFrame().GetFrameInterface());
46 if (!pController)
47 return;
49 if (bInitiallyVisible && pController->IsDeckVisible(rsDeckId))
51 // close the sidebar if it was already visible and showing this sidebar deck
52 const util::URL aURL(Tools::GetURL(".uno:Sidebar"));
53 css::uno::Reference<frame::XDispatch> xDispatch(Tools::GetDispatch(pViewFrame->GetFrame().GetFrameInterface(), aURL));
54 if (xDispatch.is())
55 xDispatch->dispatch(aURL, css::uno::Sequence<beans::PropertyValue>());
57 else
59 pController->OpenThenSwitchToDeck(rsDeckId);
60 pController->GetFocusManager().GrabFocusPanel();
64 void Sidebar::ShowPanel (
65 std::u16string_view rsPanelId,
66 const css::uno::Reference<frame::XFrame>& rxFrame, bool bFocus)
68 SidebarController* pController = SidebarController::GetSidebarControllerForFrame(rxFrame);
69 if (!pController)
70 return;
72 std::shared_ptr<PanelDescriptor> xPanelDescriptor = pController->GetResourceManager()->GetPanelDescriptor(rsPanelId);
74 if (!xPanelDescriptor)
75 return;
77 // This should be a lot more sophisticated:
78 // - Make the deck switching asynchronous
79 // - Make sure to use a context that really shows the panel
81 // All that is not necessary for the current use cases so lets
82 // keep it simple for the time being.
83 pController->OpenThenSwitchToDeck(xPanelDescriptor->msDeckId);
85 if (bFocus)
86 pController->GetFocusManager().GrabFocusPanel();
89 void Sidebar::TogglePanel (
90 std::u16string_view rsPanelId,
91 const css::uno::Reference<frame::XFrame>& rxFrame)
93 SidebarController* pController = SidebarController::GetSidebarControllerForFrame(rxFrame);
94 if (!pController)
95 return;
97 std::shared_ptr<PanelDescriptor> xPanelDescriptor = pController->GetResourceManager()->GetPanelDescriptor(rsPanelId);
99 if (!xPanelDescriptor)
100 return;
102 // This should be a lot more sophisticated:
103 // - Make the deck switching asynchronous
104 // - Make sure to use a context that really shows the panel
106 // All that is not necessary for the current use cases so lets
107 // keep it simple for the time being.
108 pController->OpenThenToggleDeck(xPanelDescriptor->msDeckId);
111 bool Sidebar::IsPanelVisible(
112 std::u16string_view rsPanelId,
113 const css::uno::Reference<frame::XFrame>& rxFrame)
115 SidebarController* pController = SidebarController::GetSidebarControllerForFrame(rxFrame);
116 if (!pController)
117 return false;
119 std::shared_ptr<PanelDescriptor> xPanelDescriptor = pController->GetResourceManager()->GetPanelDescriptor(rsPanelId);
120 if (!xPanelDescriptor)
121 return false;
123 return pController->IsDeckVisible(xPanelDescriptor->msDeckId);
126 } // end of namespace sfx2::sidebar
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */