sfx2/source/control/dispatch.cxx |    5 +++--
 sfx2/source/dialog/basedlgs.cxx  |   13 +++++++++----
 sfx2/source/dialog/tabdlg.cxx    |   12 +++++++++---
 sfx2/source/doc/guisaveas.cxx    |   10 ++++++----
 sfx2/source/view/viewsh.cxx      |    6 +++---
 5 files changed, 30 insertions(+), 16 deletions(-)

New commits:
commit 064b335cf721db96fe556c78b15d0abe0edec70d
Author:     Caolán McNamara <[email protected]>
AuthorDate: Fri Apr 26 10:23:55 2024 +0100
Commit:     Caolán McNamara <[email protected]>
CommitDate: Mon Apr 29 09:28:32 2024 +0200

    call SfxViewShell::Current() just once
    
    Change-Id: Iea3777cfb86c64c01cf1029ff3ba6a834d8c3619
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166706
    Reviewed-by: Caolán McNamara <[email protected]>
    Tested-by: Jenkins

diff --git a/sfx2/source/control/dispatch.cxx b/sfx2/source/control/dispatch.cxx
index 300f0179b064..c761cb17830e 100644
--- a/sfx2/source/control/dispatch.cxx
+++ b/sfx2/source/control/dispatch.cxx
@@ -1125,10 +1125,11 @@ void SfxDispatcher::Update_Impl( bool bForce )
     if ( xLayoutManager.is() )
         xLayoutManager->unlock();
 
-    if ( SfxViewShell::Current() && SfxViewShell::Current()->GetDispatcher() )
+    const SfxViewShell* pViewShell = SfxViewShell::Current();
+    if (pViewShell && pViewShell->GetDispatcher())
     {
         SfxPoolItemHolder aItem;
-        SfxViewShell::Current()->GetDispatcher()->QueryState(SID_NOTEBOOKBAR, 
aItem);
+        pViewShell->GetDispatcher()->QueryState(SID_NOTEBOOKBAR, aItem);
     }
 }
 
diff --git a/sfx2/source/dialog/basedlgs.cxx b/sfx2/source/dialog/basedlgs.cxx
index 29f0cf6532cb..fb7c95e3cc32 100644
--- a/sfx2/source/dialog/basedlgs.cxx
+++ b/sfx2/source/dialog/basedlgs.cxx
@@ -200,12 +200,17 @@ void SfxModelessDialogController::Close()
     SfxDialogController::Close();
 }
 
+static bool isLOKMobilePhone()
+{
+    if (!comphelper::LibreOfficeKit::isActive())
+        return false;
+    const SfxViewShell* pCurrentShell = SfxViewShell::Current();
+    return pCurrentShell && pCurrentShell->isLOKMobilePhone();
+}
+
 SfxDialogController::SfxDialogController(weld::Widget* pParent, const 
OUString& rUIFile,
                                          const OUString& rDialogId)
-    : GenericDialogController(pParent, rUIFile, rDialogId,
-                                    comphelper::LibreOfficeKit::isActive()
-                                    && SfxViewShell::Current()
-                                    && 
SfxViewShell::Current()->isLOKMobilePhone())
+    : GenericDialogController(pParent, rUIFile, rDialogId, isLOKMobilePhone())
 {
     m_xDialog->SetInstallLOKNotifierHdl(LINK(this, SfxDialogController, 
InstallLOKNotifierHdl));
     m_xDialog->connect_container_focus_changed(LINK(this, SfxDialogController, 
FocusChangeHdl));
diff --git a/sfx2/source/dialog/tabdlg.cxx b/sfx2/source/dialog/tabdlg.cxx
index 01d6c0e440cf..d38be362dbea 100644
--- a/sfx2/source/dialog/tabdlg.cxx
+++ b/sfx2/source/dialog/tabdlg.cxx
@@ -137,10 +137,16 @@ css::uno::Reference< css::frame::XFrame > 
SfxTabPage::GetFrame() const
     return css::uno::Reference< css::frame::XFrame >();
 }
 
+static bool isLOKMobilePhone()
+{
+    if (!comphelper::LibreOfficeKit::isActive())
+        return false;
+    const SfxViewShell* pCurrentShell = SfxViewShell::Current();
+    return pCurrentShell && pCurrentShell->isLOKMobilePhone();
+}
+
 SfxTabPage::SfxTabPage(weld::Container* pPage, weld::DialogController* 
pController, const OUString& rUIXMLDescription, const OUString& rID, const 
SfxItemSet *rAttrSet)
-    : BuilderPage(pPage, pController, rUIXMLDescription, rID,
-                    comphelper::LibreOfficeKit::isActive() && 
SfxViewShell::Current()
-                    && SfxViewShell::Current()->isLOKMobilePhone())
+    : BuilderPage(pPage, pController, rUIXMLDescription, rID, 
isLOKMobilePhone())
     , mpSet(rAttrSet)
     , mbHasExchangeSupport(false)
     , mpImpl(new TabPageImpl)
diff --git a/sfx2/source/doc/guisaveas.cxx b/sfx2/source/doc/guisaveas.cxx
index 974aef7384d9..af5057b93beb 100644
--- a/sfx2/source/doc/guisaveas.cxx
+++ b/sfx2/source/doc/guisaveas.cxx
@@ -674,10 +674,12 @@ void SfxStoringHelper::CallFinishGUIStoreModel()
 
 IMPL_LINK( ModelData_Impl, OptionsDialogClosedHdl, 
css::ui::dialogs::DialogClosedEvent*, pEvt, void )
 {
+    SfxViewShell* pNotifier = comphelper::LibreOfficeKit::isActive() ? 
SfxViewShell::Current() : nullptr;
+
     if (pEvt->DialogResult == RET_OK && m_xFilterProperties)
     {
-        if ( comphelper::LibreOfficeKit::isActive() && SfxViewShell::Current() 
)
-            SfxViewShell::Current()->libreOfficeKitViewCallback( 
LOK_CALLBACK_EXPORT_FILE, "PENDING"_ostr );
+        if (pNotifier)
+            pNotifier->libreOfficeKitViewCallback( LOK_CALLBACK_EXPORT_FILE, 
"PENDING"_ostr );
 
         const uno::Sequence< beans::PropertyValue > aPropsFromDialog = 
m_xFilterProperties->getPropertyValues();
         for ( const auto& rProp : aPropsFromDialog )
@@ -685,9 +687,9 @@ IMPL_LINK( ModelData_Impl, OptionsDialogClosedHdl, 
css::ui::dialogs::DialogClose
 
         m_pOwner->CallFinishGUIStoreModel();
     }
-    else if ( comphelper::LibreOfficeKit::isActive() && 
SfxViewShell::Current() )
+    else if (pNotifier)
     {
-        SfxViewShell::Current()->libreOfficeKitViewCallback( 
LOK_CALLBACK_EXPORT_FILE, "ABORT"_ostr );
+        pNotifier->libreOfficeKitViewCallback( LOK_CALLBACK_EXPORT_FILE, 
"ABORT"_ostr );
     }
 }
 
diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx
index 52761a1fb5fb..66362a3f5ead 100644
--- a/sfx2/source/view/viewsh.cxx
+++ b/sfx2/source/view/viewsh.cxx
@@ -2844,10 +2844,10 @@ SfxViewShell* SfxViewShell::Current()
 
 bool SfxViewShell::IsCurrentLokViewReadOnly()
 {
-    if (!comphelper::LibreOfficeKit::isActive() || Current() == nullptr || 
!Current()->IsLokReadOnlyView())
+    if (!comphelper::LibreOfficeKit::isActive())
         return false;
-    else
-        return true;
+    SfxViewShell* pCurrent = Current();
+    return pCurrent && pCurrent->IsLokReadOnlyView();
 }
 
 SfxViewShell* SfxViewShell::Get( const Reference< XController>& i_rController )

Reply via email to