[Libreoffice-commits] core.git: include/svx svx/source
Tomaž Vajngerl (via logerrit)
logerrit at kemper.freedesktop.org
Mon Feb 8 06:25:29 UTC 2021
include/svx/devtools/DevelopmentToolDockingWindow.hxx | 2 +
svx/source/devtools/DevelopmentToolDockingWindow.cxx | 36 ++++++++++++------
2 files changed, 26 insertions(+), 12 deletions(-)
New commits:
commit 48a8901a205000e9878c7ee5b4fb26e07ea0a607
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Fri Jan 29 15:09:59 2021 +0900
Commit: Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Mon Feb 8 07:24:50 2021 +0100
tdf#139767 fix crash caused by the selection listener
When development tools window was closed, the selection listener
was still listening and tried to change the selection because it
was never unregistered from the selection supplier. This caused
a crash as it tried to change the object on an non existing
tree view.
This change modifies the selection change listener so that is adds
itself to the selection supplier when constructed and removes
itself from the selection supplier, when the development tools
window is disposed.
Change-Id: Ifcb56aaee8f3c5c71ec609e68ffc78573f1b4179
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110121
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
diff --git a/include/svx/devtools/DevelopmentToolDockingWindow.hxx b/include/svx/devtools/DevelopmentToolDockingWindow.hxx
index c17711868c3d..8e24c2d0cd8d 100644
--- a/include/svx/devtools/DevelopmentToolDockingWindow.hxx
+++ b/include/svx/devtools/DevelopmentToolDockingWindow.hxx
@@ -17,6 +17,7 @@
#include <com/sun/star/uno/XInterface.hpp>
#include <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/view/XSelectionChangeListener.hpp>
#include <svx/devtools/DocumentModelTreeHandler.hxx>
@@ -32,6 +33,7 @@ private:
css::uno::Reference<css::uno::XInterface> mxRoot;
css::uno::Reference<css::uno::XInterface> mxCurrentSelection;
+ css::uno::Reference<css::view::XSelectionChangeListener> mxSelectionListener;
DocumentModelTreeHandler maDocumentModelTreeHandler;
diff --git a/svx/source/devtools/DevelopmentToolDockingWindow.cxx b/svx/source/devtools/DevelopmentToolDockingWindow.cxx
index c6adf1f5f0a5..40e5bcc76857 100644
--- a/svx/source/devtools/DevelopmentToolDockingWindow.cxx
+++ b/svx/source/devtools/DevelopmentToolDockingWindow.cxx
@@ -34,13 +34,11 @@
#include <sfx2/viewfrm.hxx>
#include <com/sun/star/frame/XController.hpp>
-#include <com/sun/star/view/XSelectionChangeListener.hpp>
+#include <com/sun/star/view/XSelectionSupplier.hpp>
#include <cppuhelper/compbase.hxx>
#include <cppuhelper/basemutex.hxx>
-#include <com/sun/star/view/XSelectionSupplier.hpp>
-
using namespace css;
namespace
@@ -62,6 +60,7 @@ public:
, mxController(rxController)
, mpDockingWindow(pDockingWindow)
{
+ connect();
}
~SelectionChangeHandler() { mpDockingWindow.disposeAndClear(); }
@@ -76,6 +75,19 @@ public:
mpDockingWindow->selectionChanged(xInterface);
}
}
+
+ void connect()
+ {
+ uno::Reference<view::XSelectionSupplier> xSupplier(mxController, uno::UNO_QUERY);
+ xSupplier->addSelectionChangeListener(this);
+ }
+
+ void disconnect()
+ {
+ uno::Reference<view::XSelectionSupplier> xSupplier(mxController, uno::UNO_QUERY);
+ xSupplier->removeSelectionChangeListener(this);
+ }
+
virtual void SAL_CALL disposing(const css::lang::EventObject& /*rEvent*/) override {}
virtual void SAL_CALL disposing() override {}
@@ -110,14 +122,7 @@ DevelopmentToolDockingWindow::DevelopmentToolDockingWindow(SfxBindings* pInputBi
introspect(mxRoot);
maDocumentModelTreeHandler.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);
- }
+ mxSelectionListener.set(new SelectionChangeHandler(xController, this));
}
IMPL_LINK(DevelopmentToolDockingWindow, LeftSideSelected, weld::TreeView&, rView, void)
@@ -140,10 +145,17 @@ DevelopmentToolDockingWindow::~DevelopmentToolDockingWindow() { disposeOnce(); }
void DevelopmentToolDockingWindow::dispose()
{
+ auto* pSelectionChangeHandler
+ = dynamic_cast<SelectionChangeHandler*>(mxSelectionListener.get());
+ if (pSelectionChangeHandler)
+ pSelectionChangeHandler->disconnect();
+
+ mxSelectionListener = uno::Reference<view::XSelectionChangeListener>();
+ maDocumentModelTreeHandler.dispose();
+
mpClassNameLabel.reset();
mpClassListBox.reset();
mpSelectionToggle.reset();
- maDocumentModelTreeHandler.dispose();
mpLeftSideTreeView.reset();
SfxDockingWindow::dispose();
More information about the Libreoffice-commits
mailing list