diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2024-01-24 12:57:17 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2024-01-29 11:35:21 +0100 |
commit | 208757f4d359260afe27633d589a0c25444bbb67 (patch) | |
tree | afef8637cb9e9870894a7ec60a291b6397983266 /sc/source/ui/view/tabvwshf.cxx | |
parent | 405e3f8815d9117d3f6d93ac4d0031e308a284f0 (diff) |
make set-tab-bg-col dialog async
and adjust the logic in Dialog::EndDialog to cope with
dialogs that can loop.
Change-Id: I71c88d8fb0512e92e7890566143c762ec9650e28
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162511
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sc/source/ui/view/tabvwshf.cxx')
-rw-r--r-- | sc/source/ui/view/tabvwshf.cxx | 109 |
1 files changed, 68 insertions, 41 deletions
diff --git a/sc/source/ui/view/tabvwshf.cxx b/sc/source/ui/view/tabvwshf.cxx index f302d83aaf24..fb66f62a5f67 100644 --- a/sc/source/ui/view/tabvwshf.cxx +++ b/sc/source/ui/view/tabvwshf.cxx @@ -1220,59 +1220,86 @@ void ScTabViewShell::ExecuteSetTableBackgroundCol(SfxRequest& rReq) } else { - sal_uInt16 nRet = RET_OK; /// temp - bool bDone = false; /// temp - Color aTabBgColor = rDoc.GetTabBgColor( nCurrentTab ); ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); - ScopedVclPtr<AbstractScTabBgColorDlg> pDlg(pFact->CreateScTabBgColorDlg( + VclPtr<AbstractScTabBgColorDlg> pDlg(pFact->CreateScTabBgColorDlg( GetFrameWeld(), ScResId(SCSTR_SET_TAB_BG_COLOR), ScResId(SCSTR_NO_TAB_BG_COLOR), aTabBgColor)); - while ( !bDone && nRet == RET_OK ) + + auto xRequest = std::make_shared<SfxRequest>(rReq); + rReq.Ignore(); // the 'old' request is not relevant any more + ExecuteTableBackgroundDialog(pDlg, xRequest, aTabBgColor, nSlot); + } +} + +void ScTabViewShell::ExecuteTableBackgroundDialog(const VclPtr<AbstractScTabBgColorDlg>& pDlg, + const std::shared_ptr<SfxRequest>& xReq, + Color aOldTabBgColor, sal_uInt16 nSlot) +{ + pDlg->StartExecuteAsync( + [this, pDlg, xReq, aOldTabBgColor, nSlot] (sal_Int32 nResult)->void { - nRet = pDlg->Execute(); - if( nRet == RET_OK ) + if (DoTableBackgroundDialog(nResult, pDlg, xReq, aOldTabBgColor, nSlot)) + ExecuteTableBackgroundDialog(pDlg, xReq, aOldTabBgColor, nSlot); + else + pDlg->disposeOnce(); + } + ); +} + +bool ScTabViewShell::DoTableBackgroundDialog(sal_Int32 nResult, const VclPtr<AbstractScTabBgColorDlg>& pDlg, + const std::shared_ptr<SfxRequest>& xReq, + Color aOldTabBgColor, sal_uInt16 nSlot) +{ + if (nResult != RET_OK) + return false; + + ScViewData& rViewData = GetViewData(); + ScDocument& rDoc = rViewData.GetDocument(); + ScMarkData& rMark = rViewData.GetMarkData(); + SCTAB nCurrentTab = rViewData.GetTabNo(); + SCTAB nTabSelCount = rMark.GetSelectCount(); + bool bDone = false; /// temp + Color aSelectedColor; + pDlg->GetSelectedColor(aSelectedColor); + std::unique_ptr<ScUndoTabColorInfo::List> + pTabColorList(new ScUndoTabColorInfo::List); + if ( nTabSelCount > 1 ) + { + for (const auto& rTab : rMark) + { + if ( !rDoc.IsTabProtected(rTab) ) { - Color aSelectedColor; - pDlg->GetSelectedColor(aSelectedColor); - std::unique_ptr<ScUndoTabColorInfo::List> - pTabColorList(new ScUndoTabColorInfo::List); - if ( nTabSelCount > 1 ) - { - for (const auto& rTab : rMark) - { - if ( !rDoc.IsTabProtected(rTab) ) - { - ScUndoTabColorInfo aTabColorInfo(rTab); - aTabColorInfo.maNewTabBgColor = aSelectedColor; - pTabColorList->push_back(aTabColorInfo); - } - } - bDone = SetTabBgColor( *pTabColorList ); - } - else - { - bDone = SetTabBgColor( aSelectedColor, nCurrentTab ); //ScViewFunc.SetTabBgColor - } + ScUndoTabColorInfo aTabColorInfo(rTab); + aTabColorInfo.maNewTabBgColor = aSelectedColor; + pTabColorList->push_back(aTabColorInfo); + } + } + bDone = SetTabBgColor( *pTabColorList ); + } + else + { + bDone = SetTabBgColor( aSelectedColor, nCurrentTab ); //ScViewFunc.SetTabBgColor + } - if ( bDone ) - { - rReq.AppendItem( SvxColorItem( aTabBgColor, nSlot ) ); - rReq.Done(); - } - else - { - if( rReq.IsAPI() ) - { + if ( bDone ) + { + xReq->AppendItem( SvxColorItem( aOldTabBgColor, nSlot ) ); + xReq->Done(); + } + else + { + if( xReq->IsAPI() ) + { #if HAVE_FEATURE_SCRIPTING - StarBASIC::Error( ERRCODE_BASIC_SETPROP_FAILED ); + StarBASIC::Error( ERRCODE_BASIC_SETPROP_FAILED ); #endif - } - } - } } } + + return !bDone; } + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |