summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2024-04-15 16:47:59 +0200
committerMiklos Vajna <vmiklos@collabora.com>2024-04-16 11:25:51 +0200
commit875d99c6e5286b9d56bba32a3abbc37068df61c1 (patch)
treeb045610644f902e75ba4048d5ff12aed44266bb8 /sfx2
parentcb4698626f17e005c820a7138c63a03c21120ecd (diff)
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/+/166139 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/source/control/unoctitm.cxx35
1 files changed, 13 insertions, 22 deletions
diff --git a/sfx2/source/control/unoctitm.cxx b/sfx2/source/control/unoctitm.cxx
index 9cbd29034a46..0691a6bad444 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: */