1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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"
25 DevelopmentToolDockingWindow::DevelopmentToolDockingWindow(SfxBindings
* pInputBindings
,
26 SfxChildWindow
* pChildWindow
,
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
&,
59 if (mpDomToolbar
->get_item_active("dom_current_selection_toggle"))
62 OUString sID
= rView
.get_selected_id();
63 auto xObject
= DocumentModelTreeHandler::getObjectByID(sID
);
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")
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();
99 mpDocumentModelTreeView
.reset();
101 SfxDockingWindow::dispose();
104 void DevelopmentToolDockingWindow::updateSelection()
106 bool bActive
= mpDomToolbar
->get_item_active("dom_current_selection_toggle");
109 maObjectInspectorTreeHandler
.introspect(mxCurrentSelection
);
110 maDocumentModelTreeHandler
.selectObject(mxCurrentSelection
);
114 mpDocumentModelTreeView
->set_sensitive(true);
118 void DevelopmentToolDockingWindow::ToggleFloatingMode()
120 SfxDockingWindow::ToggleFloatingMode();
122 if (GetFloatingWindow())
123 GetFloatingWindow()->SetMinOutputSizePixel(Size(300, 300));
128 void DevelopmentToolDockingWindow::selectionChanged(
129 uno::Reference
<uno::XInterface
> const& xInterface
)
131 mxCurrentSelection
= xInterface
;
135 void DevelopmentToolDockingWindow::changeToCurrentSelection()
137 if (mxSelectionSupplier
.is())
139 css::uno::Any aAny
= mxSelectionSupplier
->getSelection();
142 auto xInterface
= aAny
.get
<css::uno::Reference
<css::uno::XInterface
>>();
145 maObjectInspectorTreeHandler
.introspect(xInterface
);
146 mpDomToolbar
->set_item_active("dom_current_selection_toggle", true);
151 mpDomToolbar
->set_item_active("dom_current_selection_toggle", false);
152 maObjectInspectorTreeHandler
.introspect(mxRoot
);
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */