sfx2/source/control/unoctitm.cxx |   35 +++++++++++++----------------------
 1 file changed, 13 insertions(+), 22 deletions(-)

New commits:
commit 9e4de8c5f4a0c04d19d823b3deb1f4fcf0a49352
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Mon Apr 15 16:47:59 2024 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue Apr 16 08:16:59 2024 +0200

    sfx2 lok: simplify error handling in InterceptLOKStateChangeEvent()
    
    The whole function is pointless without a viewshell, move the check &
    short-circuit to the top of the function, and drop all the duplicate
    checks.
    
    Also drop two calls to SfxViewShell::Current(): getting it from the view
    frame is better than getting some global state.
    
    Change-Id: I4aa7aeb7c89841bbced760ce2e43d2312bc97f20
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166130
    Reviewed-by: Michael Meeks <michael.me...@collabora.com>
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>

diff --git a/sfx2/source/control/unoctitm.cxx b/sfx2/source/control/unoctitm.cxx
index d6d13f82f0a4..37286cc2d71d 100644
--- a/sfx2/source/control/unoctitm.cxx
+++ b/sfx2/source/control/unoctitm.cxx
@@ -893,7 +893,8 @@ void 
SfxDispatchController_Impl::StateChangedAtToolBoxControl( sal_uInt16 nSID,
 
 static void InterceptLOKStateChangeEvent(sal_uInt16 nSID, SfxViewFrame* 
pViewFrame, const css::frame::FeatureStateEvent& aEvent, const SfxPoolItem* 
pState)
 {
-    if (!comphelper::LibreOfficeKit::isActive())
+    const SfxViewShell* pViewShell = pViewFrame->GetViewShell();
+    if (!comphelper::LibreOfficeKit::isActive() || !pViewShell)
         return;
 
     OUStringBuffer aBuffer(aEvent.FeatureURL.Complete + "=");
@@ -1121,17 +1122,13 @@ static void InterceptLOKStateChangeEvent(sal_uInt16 
nSID, SfxViewFrame* pViewFra
     else if (aEvent.FeatureURL.Path == "ParaLeftToRight" ||
              aEvent.FeatureURL.Path == "ParaRightToLeft")
     {
-        const SfxViewShell* pViewShell = SfxViewShell::Current();
-        if (pViewShell)
-        {
-            tools::JsonWriter aTree;
-            bool bTemp = false;
-            aEvent.State >>= bTemp;
-            aTree.put("commandName", aEvent.FeatureURL.Complete);
-            aTree.put("disabled", !aEvent.IsEnabled);
-            aTree.put("state", bTemp ? "true" : "false");
-            pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED, 
aTree.finishAndGetAsOString());
-        }
+        tools::JsonWriter aTree;
+        bool bTemp = false;
+        aEvent.State >>= bTemp;
+        aTree.put("commandName", aEvent.FeatureURL.Complete);
+        aTree.put("disabled", !aEvent.IsEnabled);
+        aTree.put("state", bTemp ? "true" : "false");
+        pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED, 
aTree.finishAndGetAsOString());
         return;
     }
     else if (aEvent.FeatureURL.Path == "AssignLayout" ||
@@ -1152,8 +1149,7 @@ static void InterceptLOKStateChangeEvent(sal_uInt16 nSID, 
SfxViewFrame* pViewFra
              aEvent.FeatureURL.Path == "TransformWidth" ||
              aEvent.FeatureURL.Path == "TransformHeight")
     {
-        const SfxViewShell* pViewShell = SfxViewShell::Current();
-        if (aEvent.IsEnabled && pViewShell && pViewShell->isLOKMobilePhone())
+        if (aEvent.IsEnabled && pViewShell->isLOKMobilePhone())
         {
             boost::property_tree::ptree aTree;
             boost::property_tree::ptree aState;
@@ -1198,11 +1194,7 @@ static void InterceptLOKStateChangeEvent(sal_uInt16 
nSID, SfxViewFrame* pViewFra
         aTree.put("state", aString);
         std::stringstream aStream;
         boost::property_tree::write_json(aStream, aTree);
-        const SfxViewShell* pShell = pViewFrame->GetViewShell();
-        if (pShell)
-        {
-            pShell->libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED, 
OString(aStream.str()));
-        }
+        pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED, 
OString(aStream.str()));
         return;
     }
     else if (aEvent.FeatureURL.Path == "StateTableCell")
@@ -1316,14 +1308,13 @@ static void InterceptLOKStateChangeEvent(sal_uInt16 
nSID, SfxViewFrame* pViewFra
     else
     {
         // Try to send JSON state version
-        SfxLokHelper::sendUnoStatus(pViewFrame->GetViewShell(), pState);
+        SfxLokHelper::sendUnoStatus(pViewShell, pState);
 
         return;
     }
 
     OUString payload = aBuffer.makeStringAndClear();
-    if (const SfxViewShell* pViewShell = pViewFrame->GetViewShell())
-        pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED, 
payload.toUtf8());
+    pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED, 
payload.toUtf8());
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to