Bump version to 24.04.3.4
[LibreOffice.git] / sfx2 / source / devtools / DevelopmentToolDockingWindow.cxx
blob0095e3396cf852713ffa553a9e9f3d6e0d30ed2a
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>
20 #include <sfx2/sfxresid.hxx>
21 #include <sfx2/strings.hrc>
23 #include "SelectionChangeHandler.hxx"
25 using namespace css;
27 DevelopmentToolDockingWindow::DevelopmentToolDockingWindow(SfxBindings* pInputBindings,
28 SfxChildWindow* pChildWindow,
29 vcl::Window* pParent)
30 : SfxDockingWindow(pInputBindings, pChildWindow, pParent, "DevelopmentTool",
31 "sfx/ui/developmenttool.ui")
32 , mpObjectInspectorWidgets(new ObjectInspectorWidgets(m_xBuilder))
33 , mpDocumentModelTreeView(m_xBuilder->weld_tree_view("leftside_treeview_id"))
34 , mpDomToolbar(m_xBuilder->weld_toolbar("dom_toolbar"))
35 , maDocumentModelTreeHandler(
36 mpDocumentModelTreeView,
37 pInputBindings->GetDispatcher()->GetFrame()->GetObjectShell()->GetBaseModel())
38 , maObjectInspectorTreeHandler(mpObjectInspectorWidgets)
40 mpDocumentModelTreeView->connect_changed(
41 LINK(this, DevelopmentToolDockingWindow, DocumentModelTreeViewSelectionHandler));
42 mpDomToolbar->connect_clicked(
43 LINK(this, DevelopmentToolDockingWindow, DomToolbarButtonClicked));
45 auto* pViewFrame = pInputBindings->GetDispatcher()->GetFrame();
47 uno::Reference<frame::XController> xController = pViewFrame->GetFrame().GetController();
49 mxRoot = pInputBindings->GetDispatcher()->GetFrame()->GetObjectShell()->GetBaseModel();
51 maDocumentModelTreeHandler.inspectDocument();
52 mxSelectionListener.set(new SelectionChangeHandler(xController, this));
53 mxSelectionSupplier.set(xController, css::uno::UNO_QUERY);
55 maObjectInspectorTreeHandler.introspect(mxRoot);
57 SetText(SfxResId(STR_OBJECT_INSPECTOR));
60 IMPL_LINK(DevelopmentToolDockingWindow, DocumentModelTreeViewSelectionHandler, weld::TreeView&,
61 rView, void)
63 if (mpDomToolbar->get_item_active("dom_current_selection_toggle"))
64 return;
66 OUString sID = rView.get_selected_id();
67 auto xObject = DocumentModelTreeHandler::getObjectByID(sID);
68 if (xObject.is())
69 maObjectInspectorTreeHandler.introspect(xObject);
72 IMPL_LINK(DevelopmentToolDockingWindow, DomToolbarButtonClicked, const OUString&, rSelectionId,
73 void)
75 if (rSelectionId == "dom_refresh_button")
77 maDocumentModelTreeHandler.inspectDocument();
79 else if (rSelectionId == "dom_current_selection_toggle")
81 updateSelection();
85 DevelopmentToolDockingWindow::~DevelopmentToolDockingWindow() { disposeOnce(); }
87 void DevelopmentToolDockingWindow::dispose()
89 // Stop and remove the listener
90 auto* pSelectionChangeHandler
91 = dynamic_cast<SelectionChangeHandler*>(mxSelectionListener.get());
92 if (pSelectionChangeHandler)
93 pSelectionChangeHandler->stopListening();
95 mxSelectionListener = uno::Reference<view::XSelectionChangeListener>();
97 // dispose DOM and object inspector handlers
98 maDocumentModelTreeHandler.dispose();
99 maObjectInspectorTreeHandler.dispose();
101 // dispose welded objects
102 mpObjectInspectorWidgets.reset();
103 mpDomToolbar.reset();
104 mpDocumentModelTreeView.reset();
106 SfxDockingWindow::dispose();
109 void DevelopmentToolDockingWindow::updateSelection()
111 bool bActive = mpDomToolbar->get_item_active("dom_current_selection_toggle");
112 if (bActive)
114 maObjectInspectorTreeHandler.introspect(mxCurrentSelection);
115 maDocumentModelTreeHandler.selectObject(mxCurrentSelection);
117 else
119 mpDocumentModelTreeView->set_sensitive(true);
123 void DevelopmentToolDockingWindow::ToggleFloatingMode()
125 SfxDockingWindow::ToggleFloatingMode();
127 if (GetFloatingWindow())
128 GetFloatingWindow()->SetMinOutputSizePixel(Size(300, 300));
130 Invalidate();
133 void DevelopmentToolDockingWindow::selectionChanged(
134 uno::Reference<uno::XInterface> const& xInterface)
136 mxCurrentSelection = xInterface;
137 updateSelection();
140 void DevelopmentToolDockingWindow::changeToCurrentSelection()
142 if (mxSelectionSupplier.is())
144 css::uno::Any aAny = mxSelectionSupplier->getSelection();
145 if (aAny.hasValue())
147 auto xInterface = aAny.get<css::uno::Reference<css::uno::XInterface>>();
148 if (xInterface.is())
150 maObjectInspectorTreeHandler.introspect(xInterface);
151 mpDomToolbar->set_item_active("dom_current_selection_toggle", true);
152 return;
156 mpDomToolbar->set_item_active("dom_current_selection_toggle", false);
157 maObjectInspectorTreeHandler.introspect(mxRoot);
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */