include/sfx2/dialogrequesthelper.hxx | 49 +++++++++++++++++++++++++++++++++++ sc/source/ui/view/tabvwshf.cxx | 17 +++++------- 2 files changed, 56 insertions(+), 10 deletions(-)
New commits: commit b80c7b05d0dcb080c7182c9f8610f06e1124d3bb Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Wed May 28 13:40:10 2025 +0500 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Sat May 31 20:47:34 2025 +0200 tdf#166751: introduce sfx2::ExecDialogPerRequestAndDispose It is intended to choose automatically, which mode to use when executing dialogs in request handlers. The work on making dialogs async ignored the need of synchronous execution when necessary; this helper should make it transparent. Change-Id: If374bbf08159d1591579a278f7319e90f952f4f2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186088 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/include/sfx2/dialogrequesthelper.hxx b/include/sfx2/dialogrequesthelper.hxx new file mode 100644 index 000000000000..6273a3c5bdd2 --- /dev/null +++ b/include/sfx2/dialogrequesthelper.hxx @@ -0,0 +1,49 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include <sal/config.h> + +#include <memory> +#include <type_traits> + +#include <sfx2/bindings.hxx> +#include <sfx2/request.hxx> +#include <vcl/abstdlg.hxx> + +namespace sfx2 +{ +// Helper that executes the dialog according to the call mode defined in the passed request: +// synchronously or asynchronously. User-provided callback endDialogFn(sal_Int32, SfxRequest&) +// is called, and the result of the dialog execution is passed to it, along with the request, to +// set the necessary return values. After endDialogFn exits, the dialog is disposed. Intended +// for use in request handlers. +template <class Fn> +requires(std::is_invocable_v<Fn, sal_Int32, SfxRequest&>) void ExecDialogPerRequestAndDispose( + VclPtr<VclAbstractDialog> dlg, SfxRequest& req, Fn endDialogFn) +{ + if (req.GetCallMode() & SfxCallMode::SYNCHRON) + { + endDialogFn(dlg->Execute(), req); + dlg->disposeOnce(); + } + else + { + dlg->StartExecuteAsync( + [ dlg, endDialogFn, pRequest = std::make_shared<SfxRequest>(req) ](sal_Int32 result) { + endDialogFn(result, *pRequest); + dlg->disposeOnce(); + }); + req.Ignore(); + } +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/source/ui/view/tabvwshf.cxx b/sc/source/ui/view/tabvwshf.cxx index 19ccd034358d..1d6102fc78e6 100644 --- a/sc/source/ui/view/tabvwshf.cxx +++ b/sc/source/ui/view/tabvwshf.cxx @@ -21,6 +21,7 @@ #include <memory> +#include <sfx2/dialogrequesthelper.hxx> #include <sfx2/request.hxx> #include <sfx2/bindings.hxx> #include <sfx2/viewfrm.hxx> @@ -878,19 +879,15 @@ void ScTabViewShell::ExecuteInsertTable(SfxRequest& rReq) } else // dialog { - auto xRequest = std::make_shared<SfxRequest>(rReq); - rReq.Ignore(); // the 'old' request is not relevant any more ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); VclPtr<AbstractScInsertTableDlg> pDlg(pFact->CreateScInsertTableDlg(GetFrameWeld(), rViewData, nTabSelCount, nSlot == FID_INS_TABLE_EXT)); - pDlg->StartExecuteAsync( - [this, pDlg, xRequest=std::move(xRequest)] (sal_Int32 nResult)->void - { - if (nResult == RET_OK) - DoInsertTableFromDialog(*xRequest, pDlg); - pDlg->disposeOnce(); - } - ); + sfx2::ExecDialogPerRequestAndDispose(pDlg, rReq, + [this, pDlg](sal_Int32 nResult, SfxRequest& req) + { + if (nResult == RET_OK) + DoInsertTableFromDialog(req, pDlg); + }); } }