sfx2/source/view/lokhelper.cxx |   59 +++++++++++++++++++----------------------
 1 file changed, 28 insertions(+), 31 deletions(-)

New commits:
commit 64f9abf4de93ed0d7006970dec70e22f9085fcc3
Author:     Aron Budea <aron.bu...@collabora.com>
AuthorDate: Tue Jan 9 12:39:56 2024 +1030
Commit:     Aron Budea <aron.bu...@collabora.com>
CommitDate: Thu Jan 11 11:41:46 2024 +0100

    lok: Replace loop with std::find_if(...)
    
    Change-Id: Icfe912f7b79454b9d208c39382ba187d0a0c16c5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161810
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Attila Szűcs <attila.sz...@collabora.com>
    Reviewed-by: Aron Budea <aron.bu...@collabora.com>

diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index c54551b1637f..0deb4d6a65a2 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -185,44 +185,41 @@ void SfxLokHelper::setView(int nId)
     const ViewShellId nViewShellId(nId);
     std::vector<SfxViewShell*>& rViewArr = pApp->GetViewShells_Impl();
 
-    for (const SfxViewShell* pViewShell : rViewArr)
-    {
-        if (pViewShell->GetViewShellId() == nViewShellId)
-        {
-            DisableCallbacks dc;
+    const auto itViewShell = std::find_if(rViewArr.begin(), rViewArr.end(), 
[nViewShellId](SfxViewShell* pViewShell){ return pViewShell->GetViewShellId() 
== nViewShellId; });
+    if (itViewShell == rViewArr.end())
+        return;
 
-            bool bIsCurrShell = (pViewShell == SfxViewShell::Current());
-            if (bIsCurrShell && 
comphelper::LibreOfficeKit::getLanguageTag().getBcp47() == 
pViewShell->GetLOKLanguageTag().getBcp47())
-                return;
+    const SfxViewShell* pViewShell = *itViewShell;
+    DisableCallbacks dc;
 
-            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());
-            }
+    bool bIsCurrShell = (pViewShell == SfxViewShell::Current());
+    if (bIsCurrShell && 
comphelper::LibreOfficeKit::getLanguageTag().getBcp47() == 
pViewShell->GetLOKLanguageTag().getBcp47())
+        return;
 
-            // update the current LOK language and locale for the dialog 
tunneling
-            
comphelper::LibreOfficeKit::setLanguageTag(pViewShell->GetLOKLanguageTag());
-            comphelper::LibreOfficeKit::setLocale(pViewShell->GetLOKLocale());
+    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());
+    }
 
-            if (bIsCurrShell)
-                return;
+    // update the current LOK language and locale for the dialog tunneling
+    
comphelper::LibreOfficeKit::setLanguageTag(pViewShell->GetLOKLanguageTag());
+    comphelper::LibreOfficeKit::setLocale(pViewShell->GetLOKLocale());
 
-            SfxViewFrame* pViewFrame = pViewShell->GetViewFrame();
-            pViewFrame->MakeActive_Impl(false);
+    if (bIsCurrShell)
+        return;
 
-            // Make comphelper::dispatchCommand() find the correct frame.
-            uno::Reference<frame::XFrame> xFrame = 
pViewFrame->GetFrame().GetFrameInterface();
-            uno::Reference<frame::XDesktop2> xDesktop = 
frame::Desktop::create(comphelper::getProcessComponentContext());
-            xDesktop->setActiveFrame(xFrame);
-            return;
-        }
-    }
+    SfxViewFrame* pViewFrame = pViewShell->GetViewFrame();
+    pViewFrame->MakeActive_Impl(false);
 
+    // Make comphelper::dispatchCommand() find the correct frame.
+    uno::Reference<frame::XFrame> xFrame = 
pViewFrame->GetFrame().GetFrameInterface();
+    uno::Reference<frame::XDesktop2> xDesktop = 
frame::Desktop::create(comphelper::getProcessComponentContext());
+    xDesktop->setActiveFrame(xFrame);
 }
 
 SfxViewShell* SfxLokHelper::getViewOfId(int nId)

Reply via email to