summaryrefslogtreecommitdiff
path: root/sfx2/source
diff options
context:
space:
mode:
authorTamás Zolnai <tamas.zolnai@collabora.com>2021-01-21 12:12:53 +0100
committerTamás Zolnai <tamas.zolnai@collabora.com>2021-01-25 14:34:26 +0100
commit5864fcba2d7d285cb0f8628b0c24d0f31deb2ab0 (patch)
treef42d91d2fcb4c66329a05bd3a923e127c2534a5d /sfx2/source
parentaf234f4eb078ecd9cf5fdd6b0b022239b80c1adb (diff)
tdf#139830: keep the right sidebar context for chart after view switch (calc).
There is a general behavior to switch to the default sidebar context by view deactivation and switch back to the right context by view activation. See SfxShell::Activate() and SfxShell::Deactivate(). By activation, we use the selection to find out the right sidebar context. See GetContextForSelection_SC() method for example. However, for charts, this does not work, because the chart window is a separate environment and the shell does not know what is selected inside the chart window. So let's avoid context switches when we have a chart window active. Let the chart controller handle sidebar context changes. Change-Id: I272ee5c35ac30221eed2930201c4710a9a5877c4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109790 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Tamás Zolnai <tamas.zolnai@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109901
Diffstat (limited to 'sfx2/source')
-rw-r--r--sfx2/source/sidebar/SidebarController.cxx5
-rw-r--r--sfx2/source/sidebar/Tools.cxx28
2 files changed, 33 insertions, 0 deletions
diff --git a/sfx2/source/sidebar/SidebarController.cxx b/sfx2/source/sidebar/SidebarController.cxx
index ac3bd38f1743..e6a1cc2fb2c2 100644
--- a/sfx2/source/sidebar/SidebarController.cxx
+++ b/sfx2/source/sidebar/SidebarController.cxx
@@ -1600,6 +1600,11 @@ void SidebarController::frameAction(const css::frame::FrameActionEvent& rEvent)
}
}
+bool SidebarController::hasChartContextCurrently() const
+{
+ return GetCurrentContext().msApplication == "com.sun.star.chart2.ChartDocument";
+}
+
} } // end of namespace sfx2::sidebar
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/source/sidebar/Tools.cxx b/sfx2/source/sidebar/Tools.cxx
index dcd90eb29d3b..da25f6dbfbd7 100644
--- a/sfx2/source/sidebar/Tools.cxx
+++ b/sfx2/source/sidebar/Tools.cxx
@@ -24,10 +24,14 @@
#include <comphelper/processfactory.hxx>
#include <vcl/commandinfoprovider.hxx>
#include <vcl/gradient.hxx>
+#include <sfx2/viewsh.hxx>
#include <com/sun/star/frame/XDispatchProvider.hpp>
#include <com/sun/star/util/URLTransformer.hpp>
#include <com/sun/star/frame/ModuleManager.hpp>
+#include <sfx2/sidebar/SidebarController.hxx>
+#include <com/sun/star/ui/XSidebarProvider.hpp>
+#include <com/sun/star/frame/XController2.hpp>
#include <cstring>
@@ -135,6 +139,30 @@ OUString Tools::GetModuleName (
return OUString();
}
+sfx2::sidebar::SidebarController* Tools::GetSidebarController(SfxViewShell* pViewShell)
+{
+ if (!pViewShell)
+ return nullptr;
+
+ Reference<css::frame::XController2> xController(pViewShell->GetController(), UNO_QUERY);
+ if (!xController.is())
+ return nullptr;
+
+ // Make sure there is a model behind the controller, otherwise getSidebar() can crash.
+ if (!xController->getModel().is())
+ return nullptr;
+
+ Reference<css::ui::XSidebarProvider> xSidebarProvider = xController->getSidebar();
+ if (!xSidebarProvider.is())
+ return nullptr;
+
+ Reference<css::ui::XSidebar> xSidebar = xSidebarProvider->getSidebar();
+ if (!xSidebar.is())
+ return nullptr;
+
+ return dynamic_cast<sfx2::sidebar::SidebarController*>(xSidebar.get());
+}
+
} } // end of namespace sfx2::sidebar
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */