From 6bf428d354349995f7a20e6ce38a47c238911abe Mon Sep 17 00:00:00 2001 From: Szymon Kłos Date: Sat, 4 Nov 2023 12:05:16 +0100 Subject: lok: notebookbar: handle multiple sessions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes regression from commit db5a78c8ab1eae30e442151f07b0dc4dcd017550 lok: notebookbar: don't recreate toolbars too often When we had 2 sessions with notebookbar and one of them switched to compact mode - other session's notebookbar didn't work. Before previous change we recreated notebookbar and its welded wrapper on every StateMethod call for LOK case. So when it become destroyed we made it working again. But now we need to introduce better management and not rely on single instence we get from SystemWindow. Also it's bad idea to rely 100% on SfxNotebookBar::IsActive in LOK case as when other view will turn notebookbar off, but QueryState will be trigerred in our session - we will think that it should be destroyed (it reads config state which is shared between views). So trust only "true" value (it happens after calling SID_TOOLBAR_MODE), but destroy notebookbar only after explicit call of SfxNotebookBar::CloseMethod. It seems to have good result when tested with multiple views in Online. Maybe we can track Notebookbar state per view later to make things simpler in LOK case. Change-Id: Ie739c6441ca05884b0ef20bff23751467706b562 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158936 Tested-by: Jenkins Reviewed-by: Szymon Kłos --- sfx2/source/notebookbar/SfxNotebookBar.cxx | 89 ++++++++++++++++++++---------- 1 file changed, 60 insertions(+), 29 deletions(-) (limited to 'sfx2') diff --git a/sfx2/source/notebookbar/SfxNotebookBar.cxx b/sfx2/source/notebookbar/SfxNotebookBar.cxx index e9e85de271bd..8e9c2c9ca494 100644 --- a/sfx2/source/notebookbar/SfxNotebookBar.cxx +++ b/sfx2/source/notebookbar/SfxNotebookBar.cxx @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -43,6 +42,7 @@ const char MERGE_NOTEBOOKBAR_URL[] = "URL"; bool SfxNotebookBar::m_bLock = false; bool SfxNotebookBar::m_bHide = false; std::map> SfxNotebookBar::m_pNotebookBarWeldedWrapper; +std::map> SfxNotebookBar::m_pNotebookBarInstance; static void NotebookbarAddonValues( std::vector& aImageValues, @@ -195,6 +195,19 @@ static utl::OConfigurationNode lcl_getCurrentImplConfigNode(const Reference VclDisposeHdl + // which clears also m_pNotebookBarWeldedWrapper + aFound->second.disposeAndClear(); + m_pNotebookBarInstance.erase(aFound); + } +} + void SfxNotebookBar::CloseMethod(SfxBindings& rBindings) { SfxFrame& rFrame = rBindings.GetDispatcher_Impl()->GetFrame()->GetFrame(); @@ -203,6 +216,12 @@ void SfxNotebookBar::CloseMethod(SfxBindings& rBindings) void SfxNotebookBar::CloseMethod(SystemWindow* pSysWindow) { + if (comphelper::LibreOfficeKit::isActive()) + { + RemoveCurrentLOKWrapper(); + return; + } + if (pSysWindow) { if(pSysWindow->GetNotebookBar()) @@ -356,15 +375,19 @@ bool SfxNotebookBar::StateMethod(SystemWindow* pSysWindow, return false; } + const SfxViewShell* pViewShell = SfxViewShell::Current(); + bool hasWeldedWrapper = m_pNotebookBarWeldedWrapper.find(pViewShell) != m_pNotebookBarWeldedWrapper.end(); + if (IsActive()) { css::uno::Reference xContext = comphelper::getProcessComponentContext(); const Reference xModuleManager = frame::ModuleManager::create( xContext ); OUString aModuleName = xModuleManager->identify( xFrame ); vcl::EnumContext::Application eApp = vcl::EnumContext::GetApplicationEnum( aModuleName ); + bool bIsLOK = comphelper::LibreOfficeKit::isActive(); OUString sFile; - if (comphelper::LibreOfficeKit::isActive()) + if (bIsLOK) sFile = "notebookbar_online.ui"; else sFile = lcl_getNotebookbarFileName( eApp ); @@ -377,26 +400,12 @@ bool SfxNotebookBar::StateMethod(SystemWindow* pSysWindow, bool bChangedFile = sNewFile != sCurrentFile; - const SfxViewShell* pViewShell = SfxViewShell::Current(); - bool hasWeldedWrapper = m_pNotebookBarWeldedWrapper.find(pViewShell) != m_pNotebookBarWeldedWrapper.end(); - - if ((!sFile.isEmpty() && bChangedFile) || !pNotebookBar || !pNotebookBar->IsVisible() - || bReloadNotebookbar || (comphelper::LibreOfficeKit::isActive() && !hasWeldedWrapper)) + if ((!bIsLOK && ( + (!sFile.isEmpty() && bChangedFile) || + (!pNotebookBar || !pNotebookBar->IsVisible()) || + bReloadNotebookbar) + ) || (bIsLOK && !hasWeldedWrapper)) { - // Notebookbar was loaded too early what caused: - // * in LOK: Paste Special feature was incorrectly initialized - // Skip first request so Notebookbar will be initialized after document was loaded - static std::map bSkippedFirstInit; - if (comphelper::LibreOfficeKit::isActive() && eApp == vcl::EnumContext::Application::Writer - && bSkippedFirstInit.find(pViewShell) == bSkippedFirstInit.end()) - { - bSkippedFirstInit[pViewShell] = true; - ResetActiveToolbarModeToDefault(eApp); - return false; - } - - RemoveListeners(pSysWindow); - OUString aBuf = rUIFile + sFile; //Addons For Notebookbar @@ -407,20 +416,29 @@ bool SfxNotebookBar::StateMethod(SystemWindow* pSysWindow, aNotebookBarAddonsItem.aAddonValues = aExtensionValues; aNotebookBarAddonsItem.aImageValues = aImageValues; - // setup if necessary - if (comphelper::LibreOfficeKit::isActive()) + if (bIsLOK) { + // Notebookbar was loaded too early what caused: + // * in LOK: Paste Special feature was incorrectly initialized + // Skip first request so Notebookbar will be initialized after document was loaded + static std::map bSkippedFirstInit; + if (eApp == vcl::EnumContext::Application::Writer + && bSkippedFirstInit.find(pViewShell) == bSkippedFirstInit.end()) + { + bSkippedFirstInit[pViewShell] = true; + ResetActiveToolbarModeToDefault(eApp); + return false; + } + // update the current LOK language and locale for the dialog tunneling comphelper::LibreOfficeKit::setLanguageTag(pViewShell->GetLOKLanguageTag()); comphelper::LibreOfficeKit::setLocale(pViewShell->GetLOKLocale()); - } - pSysWindow->SetNotebookBar(aBuf, xFrame, aNotebookBarAddonsItem , bReloadNotebookbar); - pNotebookBar = pSysWindow->GetNotebookBar(); - pNotebookBar->Show(); + pNotebookBar = VclPtr::Create(pSysWindow, "NotebookBar", aBuf, xFrame, aNotebookBarAddonsItem); + m_pNotebookBarInstance.emplace(std::make_pair(pViewShell, pNotebookBar)); + + assert(pNotebookBar->IsWelded()); - if ((!hasWeldedWrapper || bReloadNotebookbar) && pNotebookBar->IsWelded()) - { sal_uInt64 nWindowId = reinterpret_cast(pViewShell); m_pNotebookBarWeldedWrapper.emplace(std::make_pair(pViewShell, new WeldedTabbedNotebookbar(pNotebookBar->GetMainContainer(), @@ -428,8 +446,16 @@ bool SfxNotebookBar::StateMethod(SystemWindow* pSysWindow, xFrame, nWindowId))); pNotebookBar->SetDisposeCallback(LINK(nullptr, SfxNotebookBar, VclDisposeHdl), pViewShell); + + return true; } + RemoveListeners(pSysWindow); + + pSysWindow->SetNotebookBar(aBuf, xFrame, aNotebookBarAddonsItem , bReloadNotebookbar); + pNotebookBar = pSysWindow->GetNotebookBar(); + pNotebookBar->Show(); + pNotebookBar->GetParent()->Resize(); utl::OConfigurationTreeRoot aRoot(lcl_getCurrentImplConfigRoot()); @@ -446,6 +472,11 @@ bool SfxNotebookBar::StateMethod(SystemWindow* pSysWindow, return true; } + else if (comphelper::LibreOfficeKit::isActive()) + { + // don't do anything to not close notebookbar of other session + return hasWeldedWrapper; + } else if (auto pNotebookBar = pSysWindow->GetNotebookBar()) { vcl::Window* pParent = pNotebookBar->GetParent(); -- cgit