From f8d1c8d1cdbe074c701b98b9e91c1f0b798c39ad Mon Sep 17 00:00:00 2001 From: Szymon Kłos Date: Fri, 9 Sep 2022 16:05:12 +0200 Subject: lok: create sidebar on demand Change-Id: I5393bba647aa4667643262e77acc6b6873afb571 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139729 Reviewed-by: Ashod Nakashian Tested-by: Jenkins CollaboraOffice --- desktop/qa/desktop_lib/test_desktop_lib.cxx | 37 ++++++++++++++++++++------- desktop/source/lib/init.cxx | 12 +++++++-- include/sfx2/sidebar/SidebarDockingWindow.hxx | 1 + sfx2/source/sidebar/SidebarDockingWindow.cxx | 14 ++++++++-- 4 files changed, 51 insertions(+), 13 deletions(-) diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index ad0412251455..0475e6c460e4 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -46,6 +46,8 @@ #include #include #include +#include +#include #include #include #include @@ -3267,10 +3269,35 @@ void DesktopLOKTest::testMultiDocuments() } } +namespace +{ + SfxChildWindow* lcl_initializeSidebar() + { + // in init.cxx we do setupSidebar which creaes the controller, do it here + + SfxViewShell* pViewShell = SfxViewShell::Current(); + CPPUNIT_ASSERT(pViewShell); + + SfxViewFrame* pViewFrame = pViewShell->GetViewFrame(); + CPPUNIT_ASSERT(pViewFrame); + + SfxChildWindow* pSideBar = pViewFrame->GetChildWindow(SID_SIDEBAR); + CPPUNIT_ASSERT(pSideBar); + + auto pDockingWin = dynamic_cast(pSideBar->GetWindow()); + CPPUNIT_ASSERT(pDockingWin); + + pDockingWin->GetOrCreateSidebarController(); // just to create the controller + + return pSideBar; + } +}; + void DesktopLOKTest::testControlState() { LibLODocument_Impl* pDocument = loadDoc("search.ods"); pDocument->pClass->postUnoCommand(pDocument, ".uno:StarShapes", nullptr, false); + lcl_initializeSidebar(); Scheduler::ProcessEventsToIdle(); boost::property_tree::ptree aState; @@ -3284,17 +3311,9 @@ void DesktopLOKTest::testMetricField() { LibLODocument_Impl* pDocument = loadDoc("search.ods"); pDocument->pClass->postUnoCommand(pDocument, ".uno:StarShapes", nullptr, false); + SfxChildWindow* pSideBar = lcl_initializeSidebar(); Scheduler::ProcessEventsToIdle(); - SfxViewShell* pViewShell = SfxViewShell::Current(); - CPPUNIT_ASSERT(pViewShell); - - SfxViewFrame* pViewFrame = pViewShell->GetViewFrame(); - CPPUNIT_ASSERT(pViewFrame); - - SfxChildWindow* pSideBar = pViewFrame->GetChildWindow(SID_SIDEBAR); - CPPUNIT_ASSERT(pSideBar); - vcl::Window* pWin = pSideBar->GetWindow(); CPPUNIT_ASSERT(pWin); diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 332ab3f96dfc..d0d1d29fc9bd 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -878,13 +878,21 @@ void setupSidebar(std::u16string_view sidebarDeckId = u"") if (!pDockingWin) return; + pViewFrame->ShowChildWindow( SID_SIDEBAR ); + + const rtl::Reference& xController + = pDockingWin->GetOrCreateSidebarController(); + + xController->FadeIn(); + xController->RequestOpenDeck(); + if (!sidebarDeckId.empty()) { - pDockingWin->GetSidebarController()->SwitchToDeck(sidebarDeckId); + xController->SwitchToDeck(sidebarDeckId); } else { - pDockingWin->GetSidebarController()->SwitchToDefaultDeck(); + xController->SwitchToDefaultDeck(); } pDockingWin->SyncUpdate(); diff --git a/include/sfx2/sidebar/SidebarDockingWindow.hxx b/include/sfx2/sidebar/SidebarDockingWindow.hxx index 9bad1f5a8464..b22aefcb34a9 100644 --- a/include/sfx2/sidebar/SidebarDockingWindow.hxx +++ b/include/sfx2/sidebar/SidebarDockingWindow.hxx @@ -46,6 +46,7 @@ public: void SyncUpdate(); auto& GetSidebarController() const { return mpSidebarController; } + rtl::Reference& GetOrCreateSidebarController(); using SfxDockingWindow::Close; private: diff --git a/sfx2/source/sidebar/SidebarDockingWindow.cxx b/sfx2/source/sidebar/SidebarDockingWindow.cxx index c8f847fffb3b..ff7b3d270980 100644 --- a/sfx2/source/sidebar/SidebarDockingWindow.cxx +++ b/sfx2/source/sidebar/SidebarDockingWindow.cxx @@ -52,11 +52,21 @@ SidebarDockingWindow::SidebarDockingWindow(SfxBindings* pSfxBindings, SidebarChi OSL_ASSERT(pSfxBindings!=nullptr); OSL_ASSERT(pSfxBindings->GetDispatcher()!=nullptr); } - else + else if (!comphelper::LibreOfficeKit::isActive()) { - const SfxViewFrame* pViewFrame = pSfxBindings->GetDispatcher()->GetFrame(); + GetOrCreateSidebarController(); + } +} + +rtl::Reference& SidebarDockingWindow::GetOrCreateSidebarController() +{ + if (!mpSidebarController) + { + const SfxViewFrame* pViewFrame = GetBindings().GetDispatcher()->GetFrame(); mpSidebarController = sfx2::sidebar::SidebarController::create(this, pViewFrame); } + + return mpSidebarController; } SidebarDockingWindow::~SidebarDockingWindow() -- cgit v1.2.3