From 208757f4d359260afe27633d589a0c25444bbb67 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Wed, 24 Jan 2024 12:57:17 +0200 Subject: 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 --- sc/source/ui/view/tabvwshf.cxx | 109 +++++++++++++++++++++++++---------------- 1 file changed, 68 insertions(+), 41 deletions(-) (limited to 'sc/source/ui/view/tabvwshf.cxx') 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 pDlg(pFact->CreateScTabBgColorDlg( + VclPtr 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(rReq); + rReq.Ignore(); // the 'old' request is not relevant any more + ExecuteTableBackgroundDialog(pDlg, xRequest, aTabBgColor, nSlot); + } +} + +void ScTabViewShell::ExecuteTableBackgroundDialog(const VclPtr& pDlg, + const std::shared_ptr& 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& pDlg, + const std::shared_ptr& 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 + pTabColorList(new ScUndoTabColorInfo::List); + if ( nTabSelCount > 1 ) + { + for (const auto& rTab : rMark) + { + if ( !rDoc.IsTabProtected(rTab) ) { - Color aSelectedColor; - pDlg->GetSelectedColor(aSelectedColor); - std::unique_ptr - 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: */ -- cgit