/src/libreoffice/include/sfx2/dialogrequesthelper.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | */ |
9 | | |
10 | | #pragma once |
11 | | |
12 | | #include <sal/config.h> |
13 | | |
14 | | #include <memory> |
15 | | #include <type_traits> |
16 | | |
17 | | #include <sfx2/bindings.hxx> |
18 | | #include <sfx2/request.hxx> |
19 | | #include <vcl/abstdlg.hxx> |
20 | | |
21 | | namespace sfx2 |
22 | | { |
23 | | // Helper that executes the dialog according to the call mode defined in the passed request: |
24 | | // synchronously or asynchronously. User-provided callback endDialogFn(sal_Int32, SfxRequest&) |
25 | | // is called, and the result of the dialog execution is passed to it, along with the request, to |
26 | | // set the necessary return values. After endDialogFn exits, the dialog is disposed. Intended |
27 | | // for use in request handlers. |
28 | | template <class Fn> |
29 | | requires(std::is_invocable_v<Fn, sal_Int32, SfxRequest&>) void ExecDialogPerRequestAndDispose( |
30 | | const VclPtr<VclAbstractDialog>& dlg, SfxRequest& req, const Fn& endDialogFn) |
31 | 0 | { |
32 | 0 | if (req.GetCallMode() & SfxCallMode::SYNCHRON) |
33 | 0 | { |
34 | 0 | endDialogFn(dlg->Execute(), req); |
35 | 0 | dlg->disposeOnce(); |
36 | 0 | } |
37 | 0 | else |
38 | 0 | { |
39 | 0 | dlg->StartExecuteAsync( |
40 | 0 | [ dlg, endDialogFn, pRequest = std::make_shared<SfxRequest>(req) ](sal_Int32 result) { |
41 | 0 | endDialogFn(result, *pRequest); |
42 | 0 | dlg->disposeOnce(); |
43 | 0 | }); |
44 | 0 | req.Ignore(); |
45 | 0 | } |
46 | 0 | } |
47 | | } |
48 | | |
49 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |