sw/source/ui/fldui/fldtdlg.cxx                      |    7 ++++-
 sw/source/ui/index/swuiidxmrk.cxx                   |   15 ++++++++----
 sw/source/uibase/app/docst.cxx                      |    3 +-
 sw/source/uibase/envelp/syncbtn.cxx                 |    3 +-
 sw/source/uibase/ribbar/workctrl.cxx                |   14 +++++++----
 sw/source/uibase/sidebar/PageOrientationControl.cxx |   25 +++++++++++---------
 6 files changed, 43 insertions(+), 24 deletions(-)

New commits:
commit 30d73367f40c375121609a9878b1c9717429eae1
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Thu Dec 15 16:48:09 2022 +0000
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Thu Dec 15 21:05:17 2022 +0000

    sw: check SfxViewFrame::Current()
    
    these ones looks potentially worth backporting
    
    Change-Id: I294fa029b53fa9d43cb738f07278301e2a06c210
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144246
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/sw/source/ui/fldui/fldtdlg.cxx b/sw/source/ui/fldui/fldtdlg.cxx
index 53e5a51c6eaf..f2d0768d34c2 100644
--- a/sw/source/ui/fldui/fldtdlg.cxx
+++ b/sw/source/ui/fldui/fldtdlg.cxx
@@ -180,8 +180,11 @@ void SwFieldDlg::ReInitDlg()
 
     if (bNewMode != m_bHtmlMode)
     {
-        SfxViewFrame::Current()->GetDispatcher()->
-            Execute(FN_INSERT_FIELD, 
SfxCallMode::ASYNCHRON|SfxCallMode::RECORD);
+        if (SfxViewFrame* pViewFrm = SfxViewFrame::Current())
+        {
+            pViewFrm->GetDispatcher()->
+                Execute(FN_INSERT_FIELD, 
SfxCallMode::ASYNCHRON|SfxCallMode::RECORD);
+        }
         Close();
     }
 
diff --git a/sw/source/ui/index/swuiidxmrk.cxx 
b/sw/source/ui/index/swuiidxmrk.cxx
index 442dbed88f8b..1075d75f4d2b 100644
--- a/sw/source/ui/index/swuiidxmrk.cxx
+++ b/sw/source/ui/index/swuiidxmrk.cxx
@@ -685,8 +685,11 @@ IMPL_LINK_NOARG(SwIndexMarkPane, CloseHdl, weld::Button&, 
void)
 {
     if (m_bNewMark)
     {
-        
SfxViewFrame::Current()->GetDispatcher()->Execute(FN_INSERT_IDX_ENTRY_DLG,
-                    SfxCallMode::ASYNCHRON|SfxCallMode::RECORD);
+        if (SfxViewFrame* pViewFrm = SfxViewFrame::Current())
+        {
+            pViewFrm->GetDispatcher()->Execute(FN_INSERT_IDX_ENTRY_DLG,
+                        SfxCallMode::ASYNCHRON|SfxCallMode::RECORD);
+        }
     }
     else
     {
@@ -818,7 +821,8 @@ IMPL_LINK_NOARG(SwIndexMarkPane, DelHdl, weld::Button&, 
void)
     else
     {
         CloseHdl(*m_xCloseBT);
-        
SfxViewFrame::Current()->GetBindings().Invalidate(FN_EDIT_IDX_ENTRY_DLG);
+        if (SfxViewFrame* pViewFrm = SfxViewFrame::Current())
+            pViewFrm->GetBindings().Invalidate(FN_EDIT_IDX_ENTRY_DLG);
     }
 }
 
@@ -1217,8 +1221,11 @@ IMPL_LINK_NOARG(SwAuthorMarkPane, CloseHdl, 
weld::Button&, void)
 {
     if(bNewEntry)
     {
-        
SfxViewFrame::Current()->GetDispatcher()->Execute(FN_INSERT_AUTH_ENTRY_DLG,
+        if (SfxViewFrame* pViewFrm = SfxViewFrame::Current())
+        {
+            pViewFrm->GetDispatcher()->Execute(FN_INSERT_AUTH_ENTRY_DLG,
                     SfxCallMode::ASYNCHRON|SfxCallMode::RECORD);
+        }
     }
     else
     {
diff --git a/sw/source/uibase/app/docst.cxx b/sw/source/uibase/app/docst.cxx
index 2d34c0e51e3a..6ab7e659ae92 100644
--- a/sw/source/uibase/app/docst.cxx
+++ b/sw/source/uibase/app/docst.cxx
@@ -1180,7 +1180,8 @@ SfxStyleFamily SwDocShell::ApplyStyles(const OUString 
&rName, SfxStyleFamily nFa
             const SwNumRule* pNumRule = pStyle->GetNumRule();
             if (pNumRule->GetName() == SwResId(STR_POOLNUMRULE_NOLIST))
             {
-                
SfxViewFrame::Current()->GetDispatcher()->Execute(FN_NUM_BULLET_OFF);
+                if (SfxViewFrame* pViewFrm = SfxViewFrame::Current())
+                    pViewFrm->GetDispatcher()->Execute(FN_NUM_BULLET_OFF);
                 break;
             }
             const OUString sListIdForStyle =pNumRule->GetDefaultListId();
diff --git a/sw/source/uibase/envelp/syncbtn.cxx 
b/sw/source/uibase/envelp/syncbtn.cxx
index 009525d02ce5..d00ff4913cbe 100644
--- a/sw/source/uibase/envelp/syncbtn.cxx
+++ b/sw/source/uibase/envelp/syncbtn.cxx
@@ -81,7 +81,8 @@ SwSyncBtnDlg::~SwSyncBtnDlg()
 
 IMPL_STATIC_LINK_NOARG(SwSyncBtnDlg, BtnHdl, weld::Button&, void)
 {
-    SfxViewFrame::Current()->GetDispatcher()->Execute(FN_UPDATE_ALL_LINKS, 
SfxCallMode::ASYNCHRON);
+    if (SfxViewFrame* pViewFrm = SfxViewFrame::Current())
+        pViewFrm->GetDispatcher()->Execute(FN_UPDATE_ALL_LINKS, 
SfxCallMode::ASYNCHRON);
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/ribbar/workctrl.cxx 
b/sw/source/uibase/ribbar/workctrl.cxx
index e65a376f7592..da64e0df90ac 100644
--- a/sw/source/uibase/ribbar/workctrl.cxx
+++ b/sw/source/uibase/ribbar/workctrl.cxx
@@ -419,10 +419,11 @@ void SwZoomBox_Impl::Select()
             m_xWidget->set_entry_text(m_xWidget->get_saved_value());
         }
 
-        SfxObjectShell* pCurrentShell = SfxObjectShell::Current();
-
-        pCurrentShell->GetDispatcher()->ExecuteList(SID_ATTR_ZOOM,
-                SfxCallMode::ASYNCHRON, { &aZoom });
+        if (SfxObjectShell* pCurrentShell = SfxObjectShell::Current())
+        {
+            pCurrentShell->GetDispatcher()->ExecuteList(SID_ATTR_ZOOM,
+                    SfxCallMode::ASYNCHRON, { &aZoom });
+        }
     }
     ReleaseFocus();
 }
@@ -625,11 +626,14 @@ IMPL_STATIC_LINK(NavElementBox_Base, SelectHdl, 
weld::ComboBox&, rComboBox, void
 {
     if (!rComboBox.changed_by_direct_pick())  // only when picked from the list
         return;
+    SfxViewFrame* pViewFrm = SfxViewFrame::Current();
+    if (!pViewFrm)
+        return;
     SfxUInt32Item aParam(FN_NAV_ELEMENT, rComboBox.get_active_id().toUInt32());
     const SfxPoolItem* aArgs[2];
     aArgs[0] = &aParam;
     aArgs[1] = nullptr;
-    SfxDispatcher* pDispatch = 
SfxViewFrame::Current()->GetBindings().GetDispatcher();
+    SfxDispatcher* pDispatch = pViewFrm->GetBindings().GetDispatcher();
     pDispatch->Execute(FN_NAV_ELEMENT, SfxCallMode::SYNCHRON, aArgs);
 }
 
diff --git a/sw/source/uibase/sidebar/PageOrientationControl.cxx 
b/sw/source/uibase/sidebar/PageOrientationControl.cxx
index 7f512d25516a..b123273ff3dc 100644
--- a/sw/source/uibase/sidebar/PageOrientationControl.cxx
+++ b/sw/source/uibase/sidebar/PageOrientationControl.cxx
@@ -78,7 +78,8 @@ void PageOrientationControl::ExecuteMarginLRChange(
 {
     mpPageLRMarginItem->SetLeft( nPageLeftMargin );
     mpPageLRMarginItem->SetRight( nPageRightMargin );
-    
SfxViewShell::Current()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_LRSPACE,
+    if (SfxViewFrame* pViewFrm = SfxViewFrame::Current())
+        pViewFrm->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_LRSPACE,
             SfxCallMode::RECORD, { mpPageLRMarginItem.get() });
 }
 
@@ -88,20 +89,25 @@ void PageOrientationControl::ExecuteMarginULChange(
 {
     mpPageULMarginItem->SetUpper( nPageTopMargin );
     mpPageULMarginItem->SetLower( nPageBottomMargin );
-    
SfxViewShell::Current()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_ULSPACE,
+    if (SfxViewFrame* pViewFrm = SfxViewFrame::Current())
+        pViewFrm->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_ULSPACE,
             SfxCallMode::RECORD, { mpPageULMarginItem.get() });
 }
 
 void PageOrientationControl::ExecuteOrientationChange( const bool bLandscape )
 {
+    SfxViewFrame* pViewFrm = SfxViewFrame::Current();
+    if (!pViewFrm)
+        return;
+
     css::uno::Reference< css::document::XUndoManager > mxUndoManager(
-                getUndoManager( 
SfxViewFrame::Current()->GetFrame().GetFrameInterface() ) );
+                getUndoManager( pViewFrm->GetFrame().GetFrameInterface() ) );
 
     if ( mxUndoManager.is() )
         mxUndoManager->enterUndoContext( "" );
 
     const SvxSizeItem* pSizeItem;
-    
SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState(SID_ATTR_PAGE_SIZE,
 pSizeItem);
+    pViewFrm->GetBindings().GetDispatcher()->QueryState(SID_ATTR_PAGE_SIZE, 
pSizeItem);
     mpPageSizeItem.reset( pSizeItem->Clone() );
 
     // Prevent accidental toggling of page orientation
@@ -113,11 +119,11 @@ void PageOrientationControl::ExecuteOrientationChange( 
const bool bLandscape )
     }
 
     const SvxLongLRSpaceItem* pLRSpaceItem;
-    
SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState(SID_ATTR_PAGE_LRSPACE,
 pLRSpaceItem);
+    pViewFrm->GetBindings().GetDispatcher()->QueryState(SID_ATTR_PAGE_LRSPACE, 
pLRSpaceItem);
     mpPageLRMarginItem.reset( pLRSpaceItem->Clone() );
 
     const SvxLongULSpaceItem* pULSpaceItem;
-    
SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState(SID_ATTR_PAGE_ULSPACE,
 pULSpaceItem);
+    pViewFrm->GetBindings().GetDispatcher()->QueryState(SID_ATTR_PAGE_ULSPACE, 
pULSpaceItem);
     mpPageULMarginItem.reset( pULSpaceItem->Clone() );
 
     {
@@ -130,11 +136,8 @@ void PageOrientationControl::ExecuteOrientationChange( 
const bool bLandscape )
         mpPageSizeItem->SetSize(Size(nRotatedWidth, nRotatedHeight));
 
         // apply changed attributes
-        if (SfxViewShell::Current())
-        {
-            
SfxViewShell::Current()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_SIZE,
-                SfxCallMode::RECORD, { mpPageSizeItem.get(), mpPageItem.get() 
});
-        }
+        pViewFrm->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_SIZE,
+            SfxCallMode::RECORD, { mpPageSizeItem.get(), mpPageItem.get() });
     }
 
     // check, if margin values still fit to the changed page size.

Reply via email to