From 1bc6a730ecb7db289e7f72db3c9bce4812e775ed Mon Sep 17 00:00:00 2001 From: Aron Budea Date: Tue, 9 Jan 2024 12:39:56 +1030 Subject: [PATCH] lok: Replace loop with std::find_if(...) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Icfe912f7b79454b9d208c39382ba187d0a0c16c5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161810 Tested-by: Jenkins CollaboraOffice Reviewed-by: Attila Szűcs Reviewed-by: Aron Budea Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162045 Tested-by: Jenkins --- sfx2/source/view/lokhelper.cxx | 67 ++++++++++++++++------------------ 1 file changed, 32 insertions(+), 35 deletions(-) diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx index 02cc7fe25230..2106168f459e 100644 --- a/sfx2/source/view/lokhelper.cxx +++ b/sfx2/source/view/lokhelper.cxx @@ -184,44 +184,41 @@ void SfxLokHelper::setView(int nId) const ViewShellId nViewShellId(nId); std::vector& rViewArr = pApp->GetViewShells_Impl(); - for (const SfxViewShell* pViewShell : rViewArr) + const auto itViewShell = std::find_if(rViewArr.begin(), rViewArr.end(), [nViewShellId](SfxViewShell* pViewShell){ return pViewShell->GetViewShellId() == nViewShellId; }); + if (itViewShell == rViewArr.end()) + return; + + const SfxViewShell* pViewShell = *itViewShell; + DisableCallbacks dc; + + bool bIsCurrShell = (pViewShell == SfxViewShell::Current()); + if (bIsCurrShell && comphelper::LibreOfficeKit::getLanguageTag().getBcp47() == pViewShell->GetLOKLanguageTag().getBcp47()) + return; + + if (bIsCurrShell) { - if (pViewShell->GetViewShellId() == nViewShellId) - { - DisableCallbacks dc; - - bool bIsCurrShell = (pViewShell == SfxViewShell::Current()); - if (bIsCurrShell && comphelper::LibreOfficeKit::getLanguageTag().getBcp47() == pViewShell->GetLOKLanguageTag().getBcp47()) - return; - - if (bIsCurrShell) - { - // If we wanted to set the SfxViewShell that is actually set, we could skip it. - // But it looks like that the language can go wrong, so we have to fix that. - // This can happen, when someone sets the language or SfxViewShell::Current() separately. - SAL_WARN("lok", "LANGUAGE mismatch at setView! ... old (wrong) lang:" - << comphelper::LibreOfficeKit::getLanguageTag().getBcp47() - << " new lang:" << pViewShell->GetLOKLanguageTag().getBcp47()); - } - - // update the current LOK language and locale for the dialog tunneling - comphelper::LibreOfficeKit::setLanguageTag(pViewShell->GetLOKLanguageTag()); - comphelper::LibreOfficeKit::setLocale(pViewShell->GetLOKLocale()); - - if (bIsCurrShell) - return; - - SfxViewFrame& rViewFrame = pViewShell->GetViewFrame(); - rViewFrame.MakeActive_Impl(false); - - // Make comphelper::dispatchCommand() find the correct frame. - uno::Reference xFrame = rViewFrame.GetFrame().GetFrameInterface(); - uno::Reference xDesktop = frame::Desktop::create(comphelper::getProcessComponentContext()); - xDesktop->setActiveFrame(xFrame); - return; - } + // If we wanted to set the SfxViewShell that is actually set, we could skip it. + // But it looks like that the language can go wrong, so we have to fix that. + // This can happen, when someone sets the language or SfxViewShell::Current() separately. + SAL_WARN("lok", "LANGUAGE mismatch at setView! ... old (wrong) lang:" + << comphelper::LibreOfficeKit::getLanguageTag().getBcp47() + << " new lang:" << pViewShell->GetLOKLanguageTag().getBcp47()); } + // update the current LOK language and locale for the dialog tunneling + comphelper::LibreOfficeKit::setLanguageTag(pViewShell->GetLOKLanguageTag()); + comphelper::LibreOfficeKit::setLocale(pViewShell->GetLOKLocale()); + + if (bIsCurrShell) + return; + + SfxViewFrame& rViewFrame = pViewShell->GetViewFrame(); + rViewFrame.MakeActive_Impl(false); + + // Make comphelper::dispatchCommand() find the correct frame. + uno::Reference xFrame = rViewFrame.GetFrame().GetFrameInterface(); + uno::Reference xDesktop = frame::Desktop::create(comphelper::getProcessComponentContext()); + xDesktop->setActiveFrame(xFrame); } SfxViewShell* SfxLokHelper::getViewOfId(int nId)