LibreOffice Module sfx2 (master) 1
DevelopmentToolDockingWindow.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 */
10
11#include <memory>
12
14
15#include <com/sun/star/view/XSelectionSupplier.hpp>
16
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>
22
24
25using namespace css;
26
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)
39{
40 mpDocumentModelTreeView->connect_changed(
41 LINK(this, DevelopmentToolDockingWindow, DocumentModelTreeViewSelectionHandler));
42 mpDomToolbar->connect_clicked(
43 LINK(this, DevelopmentToolDockingWindow, DomToolbarButtonClicked));
44
45 auto* pViewFrame = pInputBindings->GetDispatcher()->GetFrame();
46
47 uno::Reference<frame::XController> xController = pViewFrame->GetFrame().GetController();
48
49 mxRoot = pInputBindings->GetDispatcher()->GetFrame()->GetObjectShell()->GetBaseModel();
50
53 mxSelectionSupplier.set(xController, css::uno::UNO_QUERY);
54
56
57 SetText(SfxResId(STR_OBJECT_INSPECTOR));
58}
59
60IMPL_LINK(DevelopmentToolDockingWindow, DocumentModelTreeViewSelectionHandler, weld::TreeView&,
61 rView, void)
62{
63 if (mpDomToolbar->get_item_active("dom_current_selection_toggle"))
64 return;
65
66 OUString sID = rView.get_selected_id();
68 if (xObject.is())
69 maObjectInspectorTreeHandler.introspect(xObject);
70}
71
72IMPL_LINK(DevelopmentToolDockingWindow, DomToolbarButtonClicked, const OUString&, rSelectionId,
73 void)
74{
75 if (rSelectionId == "dom_refresh_button")
76 {
77 maDocumentModelTreeHandler.inspectDocument();
78 }
79 else if (rSelectionId == "dom_current_selection_toggle")
80 {
81 updateSelection();
82 }
83}
84
86
88{
89 // Stop and remove the listener
90 auto* pSelectionChangeHandler
91 = dynamic_cast<SelectionChangeHandler*>(mxSelectionListener.get());
92 if (pSelectionChangeHandler)
93 pSelectionChangeHandler->stopListening();
94
95 mxSelectionListener = uno::Reference<view::XSelectionChangeListener>();
96
97 // dispose DOM and object inspector handlers
100
101 // dispose welded objects
103 mpDomToolbar.reset();
105
107}
108
110{
111 bool bActive = mpDomToolbar->get_item_active("dom_current_selection_toggle");
112 if (bActive)
113 {
116 }
117 else
118 {
119 mpDocumentModelTreeView->set_sensitive(true);
120 }
121}
122
124{
126
127 if (GetFloatingWindow())
129
130 Invalidate();
131}
132
134 uno::Reference<uno::XInterface> const& xInterface)
135{
136 mxCurrentSelection = xInterface;
138}
139
141{
142 if (mxSelectionSupplier.is())
143 {
144 css::uno::Any aAny = mxSelectionSupplier->getSelection();
145 if (aAny.hasValue())
146 {
147 auto xInterface = aAny.get<css::uno::Reference<css::uno::XInterface>>();
148 if (xInterface.is())
149 {
151 mpDomToolbar->set_item_active("dom_current_selection_toggle", true);
152 return;
153 }
154 }
155 }
156 mpDomToolbar->set_item_active("dom_current_selection_toggle", false);
158}
159
160/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
IMPL_LINK(DevelopmentToolDockingWindow, DocumentModelTreeViewSelectionHandler, weld::TreeView &, rView, void)
Development tool main docking window.
css::uno::Reference< css::view::XSelectionChangeListener > mxSelectionListener
DocumentModelTreeHandler maDocumentModelTreeHandler
DevelopmentToolDockingWindow(SfxBindings *pBindings, SfxChildWindow *pChildWindow, vcl::Window *pParent)
std::unique_ptr< ObjectInspectorWidgets > mpObjectInspectorWidgets
std::unique_ptr< weld::Toolbar > mpDomToolbar
ObjectInspectorTreeHandler maObjectInspectorTreeHandler
void selectionChanged(css::uno::Reference< css::uno::XInterface > const &xInterface)
css::uno::Reference< css::uno::XInterface > mxRoot
css::uno::Reference< css::view::XSelectionSupplier > mxSelectionSupplier
css::uno::Reference< css::uno::XInterface > mxCurrentSelection
std::unique_ptr< weld::TreeView > mpDocumentModelTreeView
virtual void SetText(const OUString &rStr) override
SystemWindow * GetFloatingWindow() const
static css::uno::Reference< css::uno::XInterface > getObjectByID(OUString const &rID)
void selectObject(css::uno::Reference< css::uno::XInterface > const &xInterface)
void introspect(css::uno::Reference< css::uno::XInterface > const &xInterface)
Selection change handler to listen to document selection changes.
SfxDispatcher * GetDispatcher() const
Definition: bindings.hxx:172
SfxViewFrame * GetFrame() const
Returns a pointer to the <SfxViewFrame> instance, which belongs to this SfxDispatcher.
Definition: dispatch.cxx:557
virtual void ToggleFloatingMode() override
Definition: dockwin.cxx:529
virtual void dispose() override
Definition: dockwin.cxx:1032
css::uno::Reference< css::frame::XModel3 > GetBaseModel() const
Definition: objxtor.cxx:854
virtual SfxObjectShell * GetObjectShell() override
Definition: viewfrm.cxx:2218
void SetMinOutputSizePixel(const Size &rSize)
void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
SfxDispatcher * GetDispatcher()
OUString SfxResId(TranslateId aId)
Definition: sfxresid.cxx:22
Reference< XController > xController