summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2021-01-29 15:09:59 +0900
committerTomaž Vajngerl <quikee@gmail.com>2021-02-08 07:24:50 +0100
commit48a8901a205000e9878c7ee5b4fb26e07ea0a607 (patch)
tree5710154a0637b0a5d59a29143b3d8cfd308dc933 /svx
parent70a1d5258648a442525bd0b365ce92763f2a79fb (diff)
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@gmail.com>
Diffstat (limited to 'svx')
-rw-r--r--svx/source/devtools/DevelopmentToolDockingWindow.cxx36
1 files changed, 24 insertions, 12 deletions
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();