diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2022-11-23 14:30:50 +0100 |
---|---|---|
committer | Szymon Kłos <szymon.klos@collabora.com> | 2022-12-02 07:17:42 +0000 |
commit | c3919d7ab8bd65ce8f6bed16c9e8058da31cd34f (patch) | |
tree | 8a7df1c2f34674f7613e0e5c5ff8460acb1899ae | |
parent | 864e4e8c7d1586a86c6268854c513fdce8e2080c (diff) |
jsdialogs: make Content Control List Item Dialog async
Change-Id: I9801fb1cbcfed6b38a94a567e66f1a3f275454c7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143148
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Pedro Silva <pedro.silva@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143555
Tested-by: Jenkins
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
-rw-r--r-- | sw/source/ui/dialog/swdlgfact.cxx | 7 | ||||
-rw-r--r-- | sw/source/ui/dialog/swdlgfact.hxx | 5 | ||||
-rw-r--r-- | sw/source/ui/misc/contentcontroldlg.cxx | 86 | ||||
-rw-r--r-- | sw/source/uibase/inc/contentcontroldlg.hxx | 3 |
4 files changed, 58 insertions, 43 deletions
diff --git a/sw/source/ui/dialog/swdlgfact.cxx b/sw/source/ui/dialog/swdlgfact.cxx index a21b6e60b70a..671f0c1c753a 100644 --- a/sw/source/ui/dialog/swdlgfact.cxx +++ b/sw/source/ui/dialog/swdlgfact.cxx @@ -226,6 +226,11 @@ short AbstractSwRenameXNamedDlg_Impl::Execute() return m_xDlg->run(); } +bool AbstractSwContentControlListItemDlg_Impl::StartExecuteAsync(VclAbstractDialog::AsyncContext& rCtx) +{ + return weld::DialogController::runAsync(m_xDlg, rCtx.maEndDialogFn); +} + short AbstractSwContentControlListItemDlg_Impl::Execute() { return m_xDlg->run(); @@ -884,7 +889,7 @@ SwAbstractDialogFactory_Impl::CreateSwContentControlListItemDlg(weld::Window* pP SwContentControlListItem& rItem) { return VclPtr<AbstractSwContentControlListItemDlg_Impl>::Create( - std::make_unique<SwContentControlListItemDlg>(pParent, rItem)); + std::make_shared<SwContentControlListItemDlg>(pParent, rItem)); } std::shared_ptr<AbstractSwBreakDlg> SwAbstractDialogFactory_Impl::CreateSwBreakDlg(weld::Window* pParent, SwWrtShell &rSh) diff --git a/sw/source/ui/dialog/swdlgfact.hxx b/sw/source/ui/dialog/swdlgfact.hxx index 5e110dfbdd59..bf35cfdbaba6 100644 --- a/sw/source/ui/dialog/swdlgfact.hxx +++ b/sw/source/ui/dialog/swdlgfact.hxx @@ -445,16 +445,17 @@ public: */ class AbstractSwContentControlListItemDlg_Impl : public AbstractSwContentControlListItemDlg { - std::unique_ptr<SwContentControlListItemDlg> m_xDlg; + std::shared_ptr<SwContentControlListItemDlg> m_xDlg; public: explicit AbstractSwContentControlListItemDlg_Impl( - std::unique_ptr<SwContentControlListItemDlg> xDlg) + std::shared_ptr<SwContentControlListItemDlg> xDlg) : m_xDlg(std::move(xDlg)) { } short Execute() override; + bool StartExecuteAsync(VclAbstractDialog::AsyncContext &) override; }; class AbstractSwModalRedlineAcceptDlg_Impl : public AbstractSwModalRedlineAcceptDlg diff --git a/sw/source/ui/misc/contentcontroldlg.cxx b/sw/source/ui/misc/contentcontroldlg.cxx index 799f722945ff..3aeeab3c6306 100644 --- a/sw/source/ui/misc/contentcontroldlg.cxx +++ b/sw/source/ui/misc/contentcontroldlg.cxx @@ -173,7 +173,11 @@ SwContentControlDlg::SwContentControlDlg(weld::Window* pParent, SwWrtShell& rWrt } } -SwContentControlDlg::~SwContentControlDlg() {} +SwContentControlDlg::~SwContentControlDlg() +{ + if (m_xListItemDialog) + m_xListItemDialog.disposeAndClear(); +} IMPL_LINK_NOARG(SwContentControlDlg, OkHdl, weld::Button&, void) { @@ -291,29 +295,30 @@ IMPL_LINK(SwContentControlDlg, SelectCharHdl, weld::Button&, rButton, void) IMPL_LINK_NOARG(SwContentControlDlg, InsertHdl, weld::Button&, void) { - SwContentControlListItem aItem; + std::shared_ptr<SwContentControlListItem> aItem = std::make_shared<SwContentControlListItem>(); SwAbstractDialogFactory& rFact = swui::GetFactory(); - ScopedVclPtr<VclAbstractDialog> pDlg( - rFact.CreateSwContentControlListItemDlg(m_xDialog.get(), aItem)); - if (!pDlg->Execute()) - { - return; - } + m_xListItemDialog = rFact.CreateSwContentControlListItemDlg(m_xDialog.get(), *aItem); + m_xListItemDialog->StartExecuteAsync([this, aItem](sal_Int32 nResult) { + if (nResult == RET_OK) + { + if (aItem->m_aDisplayText.isEmpty() && aItem->m_aValue.isEmpty()) + { + // Maintain the invariant that value can't be empty. + return; + } - if (aItem.m_aDisplayText.isEmpty() && aItem.m_aValue.isEmpty()) - { - // Maintain the invariant that value can't be empty. - return; - } + if (aItem->m_aValue.isEmpty()) + { + aItem->m_aValue = aItem->m_aDisplayText; + } - if (aItem.m_aValue.isEmpty()) - { - aItem.m_aValue = aItem.m_aDisplayText; - } + int nRow = m_xListItems->n_children(); + m_xListItems->append_text(aItem->m_aDisplayText); + m_xListItems->set_text(nRow, aItem->m_aValue, 1); + } - int nRow = m_xListItems->n_children(); - m_xListItems->append_text(aItem.m_aDisplayText); - m_xListItems->set_text(nRow, aItem.m_aValue, 1); + m_xListItemDialog.disposeAndClear(); + }); } IMPL_LINK_NOARG(SwContentControlDlg, RenameHdl, weld::Button&, void) @@ -324,30 +329,31 @@ IMPL_LINK_NOARG(SwContentControlDlg, RenameHdl, weld::Button&, void) return; } - SwContentControlListItem aItem; - aItem.m_aDisplayText = m_xListItems->get_text(nRow, 0); - aItem.m_aValue = m_xListItems->get_text(nRow, 1); + std::shared_ptr<SwContentControlListItem> aItem = std::make_shared<SwContentControlListItem>(); + aItem->m_aDisplayText = m_xListItems->get_text(nRow, 0); + aItem->m_aValue = m_xListItems->get_text(nRow, 1); SwAbstractDialogFactory& rFact = swui::GetFactory(); - ScopedVclPtr<VclAbstractDialog> pDlg( - rFact.CreateSwContentControlListItemDlg(m_xDialog.get(), aItem)); - if (!pDlg->Execute()) - { - return; - } + m_xListItemDialog = rFact.CreateSwContentControlListItemDlg(m_xDialog.get(), *aItem); + m_xListItemDialog->StartExecuteAsync([this, aItem, nRow](sal_Int32 nResult) { + if (nResult == RET_OK) + { + if (aItem->m_aDisplayText.isEmpty() && aItem->m_aValue.isEmpty()) + { + // Maintain the invariant that value can't be empty. + return; + } - if (aItem.m_aDisplayText.isEmpty() && aItem.m_aValue.isEmpty()) - { - // Maintain the invariant that value can't be empty. - return; - } + if (aItem->m_aValue.isEmpty()) + { + aItem->m_aValue = aItem->m_aDisplayText; + } - if (aItem.m_aValue.isEmpty()) - { - aItem.m_aValue = aItem.m_aDisplayText; - } + m_xListItems->set_text(nRow, aItem->m_aDisplayText, 0); + m_xListItems->set_text(nRow, aItem->m_aValue, 1); + } - m_xListItems->set_text(nRow, aItem.m_aDisplayText, 0); - m_xListItems->set_text(nRow, aItem.m_aValue, 1); + m_xListItemDialog.disposeAndClear(); + }); } IMPL_LINK_NOARG(SwContentControlDlg, DeleteHdl, weld::Button&, void) diff --git a/sw/source/uibase/inc/contentcontroldlg.hxx b/sw/source/uibase/inc/contentcontroldlg.hxx index df4830e7cd9f..efeadbfa76b8 100644 --- a/sw/source/uibase/inc/contentcontroldlg.hxx +++ b/sw/source/uibase/inc/contentcontroldlg.hxx @@ -19,6 +19,7 @@ #pragma once #include <sfx2/basedlgs.hxx> +#include <vcl/abstdlg.hxx> #include <vcl/weld.hxx> class SwWrtShell; @@ -57,6 +58,8 @@ class SwContentControlDlg final : public SfxDialogController std::unique_ptr<weld::Button> m_xOk; + VclPtr<VclAbstractDialog> m_xListItemDialog; + DECL_LINK(InsertHdl, weld::Button&, void); DECL_LINK(RenameHdl, weld::Button&, void); DECL_LINK(DeleteHdl, weld::Button&, void); |