From 09ac0b5b1b88c3e438ce98f175aef8e46f14f3b2 Mon Sep 17 00:00:00 2001 From: Szymon Kłos Date: Wed, 10 Aug 2022 14:43:51 +0200 Subject: Make Autofilter MessageBoxes async Change-Id: Ibfa13b423869d58dd42e398f46e209e170e02751 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138106 Tested-by: Jenkins CollaboraOffice Reviewed-by: Michael Meeks --- sc/source/ui/inc/dbfunc.hxx | 5 +++ sc/source/ui/view/dbfunc.cxx | 89 +++++++++++++++++++++++++++----------------- 2 files changed, 59 insertions(+), 35 deletions(-) diff --git a/sc/source/ui/inc/dbfunc.hxx b/sc/source/ui/inc/dbfunc.hxx index e953f4aefccb..4ab5688a2b0c 100644 --- a/sc/source/ui/inc/dbfunc.hxx +++ b/sc/source/ui/inc/dbfunc.hxx @@ -35,6 +35,11 @@ class SAL_DLLPUBLIC_RTTI ScDBFunc : public ScViewFunc { private: void GetSelectedMemberList(ScDPUniqueStringSet& rEntries, tools::Long& rDimension); + static void ModifiedAutoFilter(ScDocShell* pDocSh); + static void ApplyAutoFilter(ScDocShell* pDocSh, ScViewData* pViewData, ScDBData* pDBData, + SCCOL nCol, SCROW nRow, SCTAB nTab, ScQueryParam aParam); + + DECL_STATIC_LINK(ScDBFunc, InstallLOKNotifierHdl, void*, vcl::ILibreOfficeKitNotifier*); public: ScDBFunc( vcl::Window* pParent, ScDocShell& rDocSh, ScTabViewShell* pViewShell ); diff --git a/sc/source/ui/view/dbfunc.cxx b/sc/source/ui/view/dbfunc.cxx index 6cca326c45d3..c3f285125459 100644 --- a/sc/source/ui/view/dbfunc.cxx +++ b/sc/source/ui/view/dbfunc.cxx @@ -275,11 +275,11 @@ void ScDBFunc::Query( const ScQueryParam& rQueryParam, const ScRange* pAdvSource void ScDBFunc::ToggleAutoFilter() { - ScDocShell* pDocSh = GetViewData().GetDocShell(); - ScDocShellModificator aModificator( *pDocSh ); + ScViewData* pViewData = &GetViewData(); + ScDocShell* pDocSh = pViewData->GetDocShell(); ScQueryParam aParam; - ScDocument& rDoc = GetViewData().GetDocument(); + ScDocument& rDoc = pViewData->GetDocument(); ScDBData* pDBData = GetDBData(false, SC_DB_AUTOFILTER, ScGetDBSelection::RowDown); pDBData->SetByRow( true ); //! undo, retrieve beforehand ?? @@ -287,11 +287,10 @@ void ScDBFunc::ToggleAutoFilter() SCCOL nCol; SCROW nRow = aParam.nRow1; - SCTAB nTab = GetViewData().GetTabNo(); + SCTAB nTab = pViewData->GetTabNo(); ScMF nFlag; bool bHasAuto = true; bool bHeader = pDBData->HasHeader(); - bool bPaint = false; //! instead retrieve from DB-range? @@ -316,7 +315,7 @@ void ScDBFunc::ToggleAutoFilter() // use a list action for the AutoFilter buttons (ScUndoAutoFilter) and the filter operation OUString aUndo = ScResId( STR_UNDO_QUERY ); - pDocSh->GetUndoManager()->EnterListAction( aUndo, aUndo, 0, GetViewData().GetViewShell()->GetViewShellId() ); + pDocSh->GetUndoManager()->EnterListAction( aUndo, aUndo, 0, pViewData->GetViewShell()->GetViewShellId() ); ScRange aRange; pDBData->GetArea( aRange ); @@ -335,7 +334,7 @@ void ScDBFunc::ToggleAutoFilter() pDocSh->GetUndoManager()->LeaveListAction(); - bPaint = true; + ScDBFunc::ModifiedAutoFilter(pDocSh); } else // show filter buttons { @@ -345,50 +344,70 @@ void ScDBFunc::ToggleAutoFilter() { if (!bHeader) { - std::unique_ptr xBox(Application::CreateMessageDialog(GetViewData().GetDialogParent(), + std::shared_ptr xBox(Application::CreateMessageDialog(pViewData->GetDialogParent(), VclMessageType::Question, VclButtonsType::YesNo, ScResId(STR_MSSG_MAKEAUTOFILTER_0))); // header from first row? xBox->set_title(ScResId(STR_MSSG_DOSUBTOTALS_0)); // "StarCalc" xBox->set_default_response(RET_YES); - if (xBox->run() == RET_YES) - { - pDBData->SetHeader( true ); //! Undo ?? - } - } - - ScRange aRange; - pDBData->GetArea( aRange ); - pDocSh->GetUndoManager()->AddUndoAction( - std::make_unique( pDocSh, aRange, pDBData->GetName(), true ) ); - - pDBData->SetAutoFilter(true); + xBox->SetInstallLOKNotifierHdl(LINK(this, ScDBFunc, InstallLOKNotifierHdl)); + xBox->runAsync(xBox, [pDocSh, pViewData, pDBData, nCol, nRow, nTab, aParam] (sal_Int32 nResult) { + if (nResult == RET_YES) + { + pDBData->SetHeader( true ); //! Undo ?? + } - for (nCol=aParam.nCol1; nCol<=aParam.nCol2; nCol++) - { - nFlag = rDoc.GetAttr( nCol, nRow, nTab, ATTR_MERGE_FLAG )->GetValue(); - rDoc.ApplyAttr( nCol, nRow, nTab, ScMergeFlagAttr( nFlag | ScMF::Auto ) ); + ApplyAutoFilter(pDocSh, pViewData, pDBData, nCol, nRow, nTab, aParam); + }); } - pDocSh->PostPaint(ScRange(aParam.nCol1, nRow, nTab, aParam.nCol2, nRow, nTab), - PaintPartFlags::Grid); - bPaint = true; + else + ApplyAutoFilter(pDocSh, pViewData, pDBData, nCol, nRow, nTab, aParam); } else { - std::unique_ptr xErrorBox(Application::CreateMessageDialog(GetViewData().GetDialogParent(), + std::shared_ptr xErrorBox(Application::CreateMessageDialog(pViewData->GetDialogParent(), VclMessageType::Warning, VclButtonsType::Ok, ScResId(STR_ERR_AUTOFILTER))); - xErrorBox->run(); + xErrorBox->SetInstallLOKNotifierHdl(LINK(this, ScDBFunc, InstallLOKNotifierHdl)); + xErrorBox->runAsync(xErrorBox, [] (sal_Int32) {}); } } +} - if ( bPaint ) - { - aModificator.SetDocumentModified(); +IMPL_STATIC_LINK_NOARG(ScDBFunc, InstallLOKNotifierHdl, void*, vcl::ILibreOfficeKitNotifier*) +{ + return GetpApp(); +} - SfxBindings& rBindings = GetViewData().GetBindings(); - rBindings.Invalidate( SID_AUTO_FILTER ); - rBindings.Invalidate( SID_AUTOFILTER_HIDE ); +void ScDBFunc::ApplyAutoFilter(ScDocShell* pDocSh, ScViewData* pViewData, ScDBData* pDBData, + SCCOL nCol, SCROW nRow, SCTAB nTab, ScQueryParam aParam) +{ + ScDocument& rDoc = pViewData->GetDocument(); + ScRange aRange; + pDBData->GetArea(aRange); + pDocSh->GetUndoManager()->AddUndoAction( + std::make_unique(pDocSh, aRange, pDBData->GetName(), true)); + + pDBData->SetAutoFilter(true); + + for (nCol=aParam.nCol1; nCol<=aParam.nCol2; nCol++) + { + ScMF nFlag = rDoc.GetAttr(nCol, nRow, nTab, ATTR_MERGE_FLAG)->GetValue(); + rDoc.ApplyAttr(nCol, nRow, nTab, ScMergeFlagAttr(nFlag | ScMF::Auto)); } + pDocSh->PostPaint(ScRange(aParam.nCol1, nRow, nTab, aParam.nCol2, nRow, nTab), + PaintPartFlags::Grid); + + ScDBFunc::ModifiedAutoFilter(pDocSh); +} + +void ScDBFunc::ModifiedAutoFilter(ScDocShell* pDocSh) +{ + ScDocShellModificator aModificator(*pDocSh); + aModificator.SetDocumentModified(); + + SfxBindings* pBindings = pDocSh->GetViewBindings(); + pBindings->Invalidate(SID_AUTO_FILTER); + pBindings->Invalidate(SID_AUTOFILTER_HIDE); } // just hide, no data change -- cgit