include/svx/devtools/DevelopmentToolDockingWindow.hxx | 14 + svx/source/devtools/DevelopmentToolDockingWindow.cxx | 87 +++++++ svx/uiconfig/ui/developmenttool.ui | 213 ++++++++++++------ 3 files changed, 244 insertions(+), 70 deletions(-)
New commits: commit e4a454f8a6e757739145689a445a9516f794b972 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Fri Jan 8 20:09:01 2021 +0900 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Wed Jan 13 11:59:29 2021 +0100 devtools: Add left-side tree of the document model This adds the graoundwork for displaying the DOM of the current document as a left-side tree and implements filling in the paragraphs for Writer. The content of the DOM tree is of course a WIP. Change-Id: I99c75b0c46d9a6a4ca398c46de0af759d459b7f7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108976 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/include/svx/devtools/DevelopmentToolDockingWindow.hxx b/include/svx/devtools/DevelopmentToolDockingWindow.hxx index a7c39480cf64..656f51a0fa13 100644 --- a/include/svx/devtools/DevelopmentToolDockingWindow.hxx +++ b/include/svx/devtools/DevelopmentToolDockingWindow.hxx @@ -18,6 +18,8 @@ #include <com/sun/star/uno/XInterface.hpp> #include <com/sun/star/uno/Reference.hxx> +#include <unordered_map> + class SAL_WARN_UNUSED SVX_DLLPUBLIC DevelopmentToolChildWindow final : public SfxChildWindow { SFX_DECL_CHILDWINDOW_WITHID(DevelopmentToolChildWindow); @@ -31,6 +33,14 @@ class SAL_WARN_UNUSED SVX_DLLPUBLIC DevelopmentToolDockingWindow final : public private: std::unique_ptr<weld::Label> mpClassNameLabel; std::unique_ptr<weld::TreeView> mpClassListBox; + std::unique_ptr<weld::TreeView> mpLeftSideTreeView; + + css::uno::Reference<css::uno::XInterface> mxRoot; + OUString msDocumentType; + + std::unordered_map<OUString, css::uno::Reference<css::uno::XInterface>> maUnoObjectMap; + + DECL_LINK(LeftSideSelected, weld::TreeView&, void); public: DevelopmentToolDockingWindow(SfxBindings* pBindings, SfxChildWindow* pChildWindow, @@ -38,8 +48,12 @@ public: virtual ~DevelopmentToolDockingWindow() override; + virtual void dispose() override; + virtual void ToggleFloatingMode() override; + void inspectDocument(); + void introspect(css::uno::Reference<css::uno::XInterface> const& xInterface); }; diff --git a/svx/source/devtools/DevelopmentToolDockingWindow.cxx b/svx/source/devtools/DevelopmentToolDockingWindow.cxx index b1f66a3037e5..ac97e9134b17 100644 --- a/svx/source/devtools/DevelopmentToolDockingWindow.cxx +++ b/svx/source/devtools/DevelopmentToolDockingWindow.cxx @@ -22,6 +22,8 @@ #include <com/sun/star/beans/MethodConcept.hpp> #include <com/sun/star/reflection/XIdlMethod.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/text/XTextDocument.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> #include <comphelper/processfactory.hxx> @@ -41,6 +43,8 @@ #include <com/sun/star/view/XSelectionSupplier.hpp> +#include <com/sun/star/drawing/XDrawPageSupplier.hpp> + using namespace css; namespace @@ -107,23 +111,104 @@ DevelopmentToolDockingWindow::DevelopmentToolDockingWindow(SfxBindings* pInputBi "svx/ui/developmenttool.ui") , mpClassNameLabel(m_xBuilder->weld_label("class_name_value_id")) , mpClassListBox(m_xBuilder->weld_tree_view("class_listbox_id")) + , mpLeftSideTreeView(m_xBuilder->weld_tree_view("leftside_treeview_id")) { + mpLeftSideTreeView->connect_changed(LINK(this, DevelopmentToolDockingWindow, LeftSideSelected)); + auto* pViewFrame = pInputBindings->GetDispatcher()->GetFrame(); uno::Reference<frame::XController> xController = pViewFrame->GetFrame().GetController(); + mxRoot = pInputBindings->GetDispatcher()->GetFrame()->GetObjectShell()->GetBaseModel(); + + introspect(mxRoot); + inspectDocument(); + uno::Reference<view::XSelectionSupplier> xSupplier(xController, uno::UNO_QUERY); if (xSupplier.is()) { uno::Reference<view::XSelectionChangeListener> xChangeListener( new SelectionChangeHandler(xController, this)); xSupplier->addSelectionChangeListener(xChangeListener); - introspect(pInputBindings->GetDispatcher()->GetFrame()->GetObjectShell()->GetBaseModel()); + } +} + +IMPL_LINK_NOARG(DevelopmentToolDockingWindow, LeftSideSelected, weld::TreeView&, void) +{ + OUString sID = mpLeftSideTreeView->get_selected_text(); + auto& rObject = maUnoObjectMap.at(sID); + if (rObject.is()) + introspect(rObject); +} + +void DevelopmentToolDockingWindow::inspectDocument() +{ + uno::Reference<lang::XServiceInfo> xDocument(mxRoot, uno::UNO_QUERY_THROW); + + if (xDocument->supportsService("com.sun.star.sheet.SpreadsheetDocument")) + { + msDocumentType = "Spreadsheet Document"; + } + else if (xDocument->supportsService("com.sun.star.presentation.PresentationDocument")) + { + msDocumentType = "Presentation Document"; + } + else if (xDocument->supportsService("com.sun.star.drawing.DrawingDocument")) + { + msDocumentType = "Drawing Document"; + } + else if (xDocument->supportsService("com.sun.star.text.TextDocument") + || xDocument->supportsService("com.sun.star.text.WebDocument")) + { + msDocumentType = "Text Document"; + + std::unique_ptr<weld::TreeIter> pParent = mpLeftSideTreeView->make_iterator(); + mpLeftSideTreeView->insert(nullptr, -1, &msDocumentType, nullptr, nullptr, nullptr, false, + pParent.get()); + maUnoObjectMap.emplace(msDocumentType, xDocument); + + uno::Reference<text::XTextDocument> xTextDocument(xDocument, uno::UNO_QUERY); + if (xTextDocument.is()) + { + uno::Reference<container::XEnumerationAccess> xParagraphEnumAccess( + xTextDocument->getText()->getText(), uno::UNO_QUERY); + if (xParagraphEnumAccess.is()) + { + uno::Reference<container::XEnumeration> xParagraphEnum + = xParagraphEnumAccess->createEnumeration(); + if (xParagraphEnum.is()) + { + sal_Int32 i = 0; + std::unique_ptr<weld::TreeIter> pCurrent = mpLeftSideTreeView->make_iterator(); + while (xParagraphEnum->hasMoreElements()) + { + OUString aString = "Paragraph " + OUString::number(i + 1); + mpLeftSideTreeView->insert(pParent.get(), -1, &aString, nullptr, nullptr, + nullptr, false, pCurrent.get()); + + uno::Reference<text::XTextContent> const xElem( + xParagraphEnum->nextElement(), uno::UNO_QUERY); + maUnoObjectMap.emplace(aString, xElem); + + i++; + } + } + } + } } } DevelopmentToolDockingWindow::~DevelopmentToolDockingWindow() { disposeOnce(); } +void DevelopmentToolDockingWindow::dispose() +{ + mpClassNameLabel.reset(); + mpClassListBox.reset(); + mpLeftSideTreeView.reset(); + + SfxDockingWindow::dispose(); +} + void DevelopmentToolDockingWindow::ToggleFloatingMode() { SfxDockingWindow::ToggleFloatingMode(); diff --git a/svx/uiconfig/ui/developmenttool.ui b/svx/uiconfig/ui/developmenttool.ui index 0a7670f4b94e..926afba3e666 100644 --- a/svx/uiconfig/ui/developmenttool.ui +++ b/svx/uiconfig/ui/developmenttool.ui @@ -4,108 +4,183 @@ <requires lib="gtk+" version="3.20"/> <object class="GtkTreeStore" id="liststore"> <columns> - <!-- column-name text1 --> + <!-- column-name class_column --> <column type="gchararray"/> - <!-- column-name text2 --> + </columns> + </object> + <object class="GtkTreeStore" id="liststore1"> + <columns> + <!-- column-name element_column --> <column type="gchararray"/> </columns> </object> - <!-- n-columns=2 n-rows=2 --> + <!-- n-columns=1 n-rows=1 --> <object class="GtkGrid" id="DevelopmentTool"> <property name="visible">True</property> <property name="can-focus">False</property> <property name="halign">baseline</property> - <property name="row-spacing">6</property> - <property name="column-spacing">6</property> - <child> - <object class="GtkLabel" id="class_name_label"> - <property name="visible">True</property> - <property name="can-focus">False</property> - <property name="hexpand">False</property> - <property name="vexpand">False</property> - <property name="label" translatable="yes" context="developmenttool|classname">Class name:</property> - <accessibility> - <relation type="label-for" target="class_name_value_id"/> - </accessibility> - </object> - <packing> - <property name="left-attach">0</property> - <property name="top-attach">0</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="class_name_value_id"> - <property name="name">class_name_id</property> - <property name="visible">True</property> - <property name="can-focus">False</property> - <property name="hexpand">True</property> - <property name="selectable">True</property> - <accessibility> - <relation type="labelled-by" target="class_name_label"/> - </accessibility> - </object> - <packing> - <property name="left-attach">1</property> - <property name="top-attach">0</property> - </packing> - </child> <child> - <object class="GtkScrolledWindow"> + <object class="GtkPaned"> <property name="visible">True</property> <property name="can-focus">True</property> <property name="hexpand">True</property> <property name="vexpand">True</property> - <property name="shadow-type">in</property> + <property name="position">800</property> + <property name="wide-handle">True</property> <child> - <object class="GtkTreeView" id="class_listbox_id"> + <!-- n-columns=1 n-rows=1 --> + <object class="GtkGrid"> <property name="visible">True</property> - <property name="can-focus">True</property> - <property name="receives-default">True</property> + <property name="can-focus">False</property> + <property name="margin-start">6</property> + <property name="margin-end">6</property> + <property name="margin-top">6</property> + <property name="margin-bottom">6</property> <property name="hexpand">True</property> <property name="vexpand">True</property> - <property name="model">liststore</property> - <property name="search-column">0</property> - <property name="enable-tree-lines">True</property> - <child internal-child="selection"> - <object class="GtkTreeSelection"/> - </child> <child> - <object class="GtkTreeViewColumn" id="treeviewcolumn1"> - <property name="resizable">True</property> - <property name="title" translatable="yes" context="developmenttool|class">Class</property> + <object class="GtkScrolledWindow"> + <property name="visible">True</property> + <property name="can-focus">True</property> + <property name="hexpand">True</property> + <property name="vexpand">True</property> + <property name="shadow-type">in</property> <child> - <object class="GtkCellRendererText" id="cellrenderertext1"> - <property name="ellipsize">end</property> + <object class="GtkTreeView" id="leftside_treeview_id"> + <property name="visible">True</property> + <property name="can-focus">True</property> + <property name="hexpand">True</property> + <property name="vexpand">True</property> + <property name="model">liststore1</property> + <property name="search-column">0</property> + <property name="enable-tree-lines">True</property> + <child internal-child="selection"> + <object class="GtkTreeSelection"/> + </child> + <child> + <object class="GtkTreeViewColumn" id="treecolumn"> + <property name="resizable">True</property> + <property name="title" translatable="yes" context="developmenttool|leftside_elementcolumn">Element</property> + <child> + <object class="GtkCellRendererText" id="cellrenderertext2"/> + <attributes> + <attribute name="text">0</attribute> + </attributes> + </child> + </object> + </child> </object> - <attributes> - <attribute name="sensitive">5</attribute> - <attribute name="text">0</attribute> - <attribute name="weight">3</attribute> - </attributes> </child> </object> + <packing> + <property name="left-attach">0</property> + <property name="top-attach">0</property> + </packing> </child> + </object> + <packing> + <property name="resize">False</property> + <property name="shrink">True</property> + </packing> + </child> + <child> + <!-- n-columns=2 n-rows=2 --> + <object class="GtkGrid"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="margin-start">6</property> + <property name="margin-end">6</property> + <property name="margin-top">6</property> + <property name="margin-bottom">6</property> + <property name="hexpand">True</property> + <property name="vexpand">True</property> <child> - <object class="GtkTreeViewColumn" id="treeviewcolumn2"> - <property name="resizable">True</property> - <property name="title" translatable="yes" context="developmenttool|value">X</property> + <object class="GtkLabel" id="class_name_label"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="hexpand">False</property> + <property name="vexpand">False</property> + <property name="label" translatable="yes" context="developmenttool|classname">Class name:</property> + <accessibility> + <relation type="label-for" target="class_name_value_id"/> + </accessibility> + </object> + <packing> + <property name="left-attach">0</property> + <property name="top-attach">0</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="class_name_value_id"> + <property name="name">class_name_id</property> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="hexpand">True</property> + <property name="selectable">True</property> + <accessibility> + <relation type="labelled-by" target="class_name_label"/> + </accessibility> + </object> + <packing> + <property name="left-attach">1</property> + <property name="top-attach">0</property> + </packing> + </child> + <child> + <object class="GtkScrolledWindow"> + <property name="visible">True</property> + <property name="can-focus">True</property> + <property name="hexpand">True</property> + <property name="vexpand">True</property> + <property name="shadow-type">in</property> <child> - <object class="GtkCellRendererText" id="cellrenderertext2"/> - <attributes> - <attribute name="sensitive">6</attribute> - <attribute name="text">1</attribute> - <attribute name="weight">4</attribute> - </attributes> + <object class="GtkTreeView" id="class_listbox_id"> + <property name="visible">True</property> + <property name="can-focus">True</property> + <property name="receives-default">True</property> + <property name="hexpand">True</property> + <property name="vexpand">True</property> + <property name="model">liststore</property> + <property name="search-column">0</property> + <property name="enable-tree-lines">True</property> + <child internal-child="selection"> + <object class="GtkTreeSelection"/> + </child> + <child> + <object class="GtkTreeViewColumn" id="treeviewcolumn1"> + <property name="resizable">True</property> + <property name="title" translatable="yes" context="developmenttool|class">Class</property> + <child> + <object class="GtkCellRendererText" id="cellrenderertext1"> + <property name="ellipsize">end</property> + </object> + <attributes> + <attribute name="sensitive">5</attribute> + <attribute name="text">0</attribute> + <attribute name="weight">3</attribute> + </attributes> + </child> + </object> + </child> + </object> </child> </object> + <packing> + <property name="left-attach">0</property> + <property name="top-attach">1</property> + <property name="width">2</property> + </packing> </child> </object> + <packing> + <property name="resize">True</property> + <property name="shrink">True</property> + </packing> </child> </object> <packing> <property name="left-attach">0</property> - <property name="top-attach">1</property> - <property name="width">2</property> + <property name="top-attach">0</property> </packing> </child> </object> _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits