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>
20 #include <sfx2/sfxresid.hxx>
21 #include <sfx2/strings.hrc>
23 #include "SelectionChangeHandler.hxx"
27 DevelopmentToolDockingWindow::DevelopmentToolDockingWindow(SfxBindings
* pInputBindings
,
28 SfxChildWindow
* pChildWindow
,
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
&,
63 if (mpDomToolbar
->get_item_active("dom_current_selection_toggle"))
66 OUString sID
= rView
.get_selected_id();
67 auto xObject
= DocumentModelTreeHandler::getObjectByID(sID
);
69 maObjectInspectorTreeHandler
.introspect(xObject
);
72 IMPL_LINK(DevelopmentToolDockingWindow
, DomToolbarButtonClicked
, const OUString
&, rSelectionId
,
75 if (rSelectionId
== "dom_refresh_button")
77 maDocumentModelTreeHandler
.inspectDocument();
79 else if (rSelectionId
== "dom_current_selection_toggle")
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");
114 maObjectInspectorTreeHandler
.introspect(mxCurrentSelection
);
115 maDocumentModelTreeHandler
.selectObject(mxCurrentSelection
);
119 mpDocumentModelTreeView
->set_sensitive(true);
123 void DevelopmentToolDockingWindow::ToggleFloatingMode()
125 SfxDockingWindow::ToggleFloatingMode();
127 if (GetFloatingWindow())
128 GetFloatingWindow()->SetMinOutputSizePixel(Size(300, 300));
133 void DevelopmentToolDockingWindow::selectionChanged(
134 uno::Reference
<uno::XInterface
> const& xInterface
)
136 mxCurrentSelection
= xInterface
;
140 void DevelopmentToolDockingWindow::changeToCurrentSelection()
142 if (mxSelectionSupplier
.is())
144 css::uno::Any aAny
= mxSelectionSupplier
->getSelection();
147 auto xInterface
= aAny
.get
<css::uno::Reference
<css::uno::XInterface
>>();
150 maObjectInspectorTreeHandler
.introspect(xInterface
);
151 mpDomToolbar
->set_item_active("dom_current_selection_toggle", true);
156 mpDomToolbar
->set_item_active("dom_current_selection_toggle", false);
157 maObjectInspectorTreeHandler
.introspect(mxRoot
);
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */