LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / sfx2 / source / devtools / DevelopmentToolDockingWindow.cxx
blob817647ca97544d09e3a971efde439effa6cc6968
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 <memory>
13 #include <sfx2/devtools/DevelopmentToolDockingWindow.hxx>
15 #include <com/sun/star/view/XSelectionSupplier.hpp>
17 #include <sfx2/dispatch.hxx>
18 #include <sfx2/objsh.hxx>
19 #include <sfx2/viewfrm.hxx>
21 #include "SelectionChangeHandler.hxx"
23 using namespace css;
25 DevelopmentToolDockingWindow::DevelopmentToolDockingWindow(SfxBindings* pInputBindings,
26 SfxChildWindow* pChildWindow,
27 vcl::Window* pParent)
28 : SfxDockingWindow(pInputBindings, pChildWindow, pParent, "DevelopmentTool",
29 "sfx/ui/developmenttool.ui")
30 , mpObjectInspectorWidgets(new ObjectInspectorWidgets(m_xBuilder))
31 , mpDocumentModelTreeView(m_xBuilder->weld_tree_view("leftside_treeview_id"))
32 , mpDomToolbar(m_xBuilder->weld_toolbar("dom_toolbar"))
33 , maDocumentModelTreeHandler(
34 mpDocumentModelTreeView,
35 pInputBindings->GetDispatcher()->GetFrame()->GetObjectShell()->GetBaseModel())
36 , maObjectInspectorTreeHandler(mpObjectInspectorWidgets)
38 mpDocumentModelTreeView->connect_changed(
39 LINK(this, DevelopmentToolDockingWindow, DocumentModelTreeViewSelectionHandler));
40 mpDomToolbar->connect_clicked(
41 LINK(this, DevelopmentToolDockingWindow, DomToolbarButtonClicked));
43 auto* pViewFrame = pInputBindings->GetDispatcher()->GetFrame();
45 uno::Reference<frame::XController> xController = pViewFrame->GetFrame().GetController();
47 mxRoot = pInputBindings->GetDispatcher()->GetFrame()->GetObjectShell()->GetBaseModel();
49 maDocumentModelTreeHandler.inspectDocument();
50 mxSelectionListener.set(new SelectionChangeHandler(xController, this));
51 mxSelectionSupplier.set(xController, css::uno::UNO_QUERY);
53 maObjectInspectorTreeHandler.introspect(mxRoot);
56 IMPL_LINK(DevelopmentToolDockingWindow, DocumentModelTreeViewSelectionHandler, weld::TreeView&,
57 rView, void)
59 if (mpDomToolbar->get_item_active("dom_current_selection_toggle"))
60 return;
62 OUString sID = rView.get_selected_id();
63 auto xObject = DocumentModelTreeHandler::getObjectByID(sID);
64 if (xObject.is())
65 maObjectInspectorTreeHandler.introspect(xObject);
68 IMPL_LINK(DevelopmentToolDockingWindow, DomToolbarButtonClicked, const OString&, rSelectionId, void)
70 if (rSelectionId == "dom_refresh_button")
72 maDocumentModelTreeHandler.inspectDocument();
74 else if (rSelectionId == "dom_current_selection_toggle")
76 updateSelection();
80 DevelopmentToolDockingWindow::~DevelopmentToolDockingWindow() { disposeOnce(); }
82 void DevelopmentToolDockingWindow::dispose()
84 // Stop and remove the listener
85 auto* pSelectionChangeHandler
86 = dynamic_cast<SelectionChangeHandler*>(mxSelectionListener.get());
87 if (pSelectionChangeHandler)
88 pSelectionChangeHandler->stopListening();
90 mxSelectionListener = uno::Reference<view::XSelectionChangeListener>();
92 // dispose DOM and object inspector handlers
93 maDocumentModelTreeHandler.dispose();
94 maObjectInspectorTreeHandler.dispose();
96 // dispose welded objects
97 mpObjectInspectorWidgets.reset();
98 mpDomToolbar.reset();
99 mpDocumentModelTreeView.reset();
101 SfxDockingWindow::dispose();
104 void DevelopmentToolDockingWindow::updateSelection()
106 bool bActive = mpDomToolbar->get_item_active("dom_current_selection_toggle");
107 if (bActive)
109 maObjectInspectorTreeHandler.introspect(mxCurrentSelection);
110 maDocumentModelTreeHandler.selectObject(mxCurrentSelection);
112 else
114 mpDocumentModelTreeView->set_sensitive(true);
118 void DevelopmentToolDockingWindow::ToggleFloatingMode()
120 SfxDockingWindow::ToggleFloatingMode();
122 if (GetFloatingWindow())
123 GetFloatingWindow()->SetMinOutputSizePixel(Size(300, 300));
125 Invalidate();
128 void DevelopmentToolDockingWindow::selectionChanged(
129 uno::Reference<uno::XInterface> const& xInterface)
131 mxCurrentSelection = xInterface;
132 updateSelection();
135 void DevelopmentToolDockingWindow::changeToCurrentSelection()
137 if (mxSelectionSupplier.is())
139 css::uno::Any aAny = mxSelectionSupplier->getSelection();
140 if (aAny.hasValue())
142 auto xInterface = aAny.get<css::uno::Reference<css::uno::XInterface>>();
143 if (xInterface.is())
145 maObjectInspectorTreeHandler.introspect(xInterface);
146 mpDomToolbar->set_item_active("dom_current_selection_toggle", true);
147 return;
151 mpDomToolbar->set_item_active("dom_current_selection_toggle", false);
152 maObjectInspectorTreeHandler.introspect(mxRoot);
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */