sw/source/ui/dialog/swdlgfact.cxx          |    7 ++
 sw/source/ui/dialog/swdlgfact.hxx          |    5 +
 sw/source/ui/misc/contentcontroldlg.cxx    |   86 +++++++++++++++--------------
 sw/source/uibase/inc/contentcontroldlg.hxx |    3 +
 4 files changed, 58 insertions(+), 43 deletions(-)

New commits:
commit 293f854778d3d7af70f690fc2442c65341ac73e1
Author:     Szymon Kłos <szymon.k...@collabora.com>
AuthorDate: Wed Nov 23 14:30:50 2022 +0100
Commit:     Pedro Silva <pedro.si...@collabora.com>
CommitDate: Fri Nov 25 17:29:55 2022 +0100

    jsdialogs: make Content Control List Item Dialog async
    
    Change-Id: I9801fb1cbcfed6b38a94a567e66f1a3f275454c7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143148
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Pedro Silva <pedro.si...@collabora.com>

diff --git a/sw/source/ui/dialog/swdlgfact.cxx 
b/sw/source/ui/dialog/swdlgfact.cxx
index 12d2dac52ef4..7578266db372 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();
@@ -885,7 +890,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 86235b29dddf..ccaa286828f9 100644
--- a/sw/source/ui/dialog/swdlgfact.hxx
+++ b/sw/source/ui/dialog/swdlgfact.hxx
@@ -444,16 +444,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 fadb4c1739fe..9d14a0427941 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);

Reply via email to