sw/inc/swabstdlg.hxx                         |   10 +++++++++-
 sw/source/ui/dialog/swdlgfact.cxx            |   10 ++++++++--
 sw/source/ui/dialog/swdlgfact.hxx            |   10 ++++++----
 sw/source/uibase/inc/DateFormFieldDialog.hxx |    9 +--------
 sw/source/uibase/shells/textsh1.cxx          |   27 +++++++++++++++++++--------
 5 files changed, 43 insertions(+), 23 deletions(-)

New commits:
commit 1195df679859b2ebfafb60bd456dcba90ff6bfae
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Wed Jan 31 11:00:23 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Wed Jan 31 17:22:19 2024 +0100

    make date-form-field dialog async
    
    Change-Id: Ia43217c3218344bacde823aa52dc0776de822d60
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162807
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/inc/swabstdlg.hxx b/sw/inc/swabstdlg.hxx
index 2af7aea2ef29..019684b11317 100644
--- a/sw/inc/swabstdlg.hxx
+++ b/sw/inc/swabstdlg.hxx
@@ -460,6 +460,14 @@ public:
     virtual void UpdateFields() = 0;
 };
 
+class AbstractDateFormFieldDialog : public VclAbstractDialog
+{
+protected:
+    virtual ~AbstractDateFormFieldDialog() override = default;
+public:
+    virtual void Apply() = 0;
+};
+
 class SwAbstractDialogFactory
 {
 public:
@@ -500,7 +508,7 @@ public:
         SwField* pField, bool bPrevButton, bool bNextButton) = 0;
     virtual VclPtr<AbstractDropDownFormFieldDialog> 
CreateDropDownFormFieldDialog(weld::Widget* pParent, sw::mark::IFieldmark* 
pDropDownField) = 0;
 
-    virtual VclPtr<VclAbstractDialog> CreateDateFormFieldDialog(weld::Widget* 
pParent, sw::mark::IDateFieldmark* pDateField, SwDoc& rDoc) = 0;
+    virtual VclPtr<AbstractDateFormFieldDialog> 
CreateDateFormFieldDialog(weld::Widget* pParent, sw::mark::IDateFieldmark* 
pDateField, SwDoc& rDoc) = 0;
 
     virtual VclPtr<SfxAbstractTabDialog> CreateSwEnvDlg(weld::Window* pParent, 
const SfxItemSet& rSet, SwWrtShell* pWrtSh, Printer* pPrt, bool bInsert) = 0;
 
diff --git a/sw/source/ui/dialog/swdlgfact.cxx 
b/sw/source/ui/dialog/swdlgfact.cxx
index 6ae455d3600c..50498ab480db 100644
--- a/sw/source/ui/dialog/swdlgfact.cxx
+++ b/sw/source/ui/dialog/swdlgfact.cxx
@@ -243,7 +243,13 @@ bool 
AbstractDropDownFormFieldDialog_Impl::StartExecuteAsync(AsyncContext &rCtx)
 
 short AbstractDateFormFieldDialog_Impl::Execute()
 {
-    return m_xDlg->run();
+    assert(false);
+    return -1;
+}
+
+bool AbstractDateFormFieldDialog_Impl::StartExecuteAsync(AsyncContext &rCtx)
+{
+    return weld::GenericDialogController::runAsync(m_xDlg, rCtx.maEndDialogFn);
 }
 
 short AbstractSwLabDlg_Impl::Execute()
@@ -1116,7 +1122,7 @@ VclPtr<AbstractDropDownFormFieldDialog> 
SwAbstractDialogFactory_Impl::CreateDrop
     return 
VclPtr<AbstractDropDownFormFieldDialog_Impl>::Create(std::make_unique<sw::DropDownFormFieldDialog>(pParent,
 pDropDownField));
 }
 
-VclPtr<VclAbstractDialog> 
SwAbstractDialogFactory_Impl::CreateDateFormFieldDialog(weld::Widget *pParent, 
sw::mark::IDateFieldmark* pDateField, SwDoc& rDoc)
+VclPtr<AbstractDateFormFieldDialog> 
SwAbstractDialogFactory_Impl::CreateDateFormFieldDialog(weld::Widget *pParent, 
sw::mark::IDateFieldmark* pDateField, SwDoc& rDoc)
 {
     return 
VclPtr<AbstractDateFormFieldDialog_Impl>::Create(std::make_unique<sw::DateFormFieldDialog>(pParent,
 pDateField, rDoc));
 }
diff --git a/sw/source/ui/dialog/swdlgfact.hxx 
b/sw/source/ui/dialog/swdlgfact.hxx
index bb795127cf5e..d1f8f4c2b5bd 100644
--- a/sw/source/ui/dialog/swdlgfact.hxx
+++ b/sw/source/ui/dialog/swdlgfact.hxx
@@ -395,15 +395,17 @@ public:
     virtual void Apply() override { m_xDlg->Apply(); }
 };
 
-class AbstractDateFormFieldDialog_Impl : public VclAbstractDialog
+class AbstractDateFormFieldDialog_Impl : public AbstractDateFormFieldDialog
 {
-    std::unique_ptr<sw::DateFormFieldDialog> m_xDlg;
+    std::shared_ptr<sw::DateFormFieldDialog> m_xDlg;
 public:
-    explicit 
AbstractDateFormFieldDialog_Impl(std::unique_ptr<sw::DateFormFieldDialog> p)
+    explicit 
AbstractDateFormFieldDialog_Impl(std::shared_ptr<sw::DateFormFieldDialog> p)
         : m_xDlg(std::move(p))
     {
     }
     virtual short Execute() override;
+    virtual bool StartExecuteAsync(AsyncContext &rCtx) override;
+    virtual void Apply() override { m_xDlg->Apply(); }
 };
 
 class AbstractSwLabDlg_Impl  : public AbstractSwLabDlg
@@ -799,7 +801,7 @@ public:
     virtual VclPtr<AbstractDropDownFieldDialog> 
CreateDropDownFieldDialog(weld::Widget* pParent, SwWrtShell &rSh,
         SwField* pField, bool bPrevButton, bool bNextButton) override;
     virtual VclPtr<AbstractDropDownFormFieldDialog> 
CreateDropDownFormFieldDialog(weld::Widget* pParent, sw::mark::IFieldmark* 
pDropDownField) override;
-    virtual VclPtr<VclAbstractDialog> CreateDateFormFieldDialog(weld::Widget* 
pParent, sw::mark::IDateFieldmark* pDateField, SwDoc& rDoc) override;
+    virtual VclPtr<AbstractDateFormFieldDialog> 
CreateDateFormFieldDialog(weld::Widget* pParent, sw::mark::IDateFieldmark* 
pDateField, SwDoc& rDoc) override;
 
     virtual VclPtr<SfxAbstractTabDialog> CreateSwEnvDlg(weld::Window* pParent, 
const SfxItemSet& rSet, SwWrtShell* pWrtSh, Printer* pPrt, bool bInsert) 
override;
     virtual VclPtr<AbstractSwLabDlg> CreateSwLabDlg(weld::Window* pParent, 
const SfxItemSet& rSet,
diff --git a/sw/source/uibase/inc/DateFormFieldDialog.hxx 
b/sw/source/uibase/inc/DateFormFieldDialog.hxx
index 2b4573af7dea..81a0b790831c 100644
--- a/sw/source/uibase/inc/DateFormFieldDialog.hxx
+++ b/sw/source/uibase/inc/DateFormFieldDialog.hxx
@@ -31,20 +31,13 @@ private:
 
     std::unique_ptr<SwNumFormatTreeView> m_xFormatLB;
 
-    void Apply();
     void InitControls();
 
 public:
     DateFormFieldDialog(weld::Widget* pParent, sw::mark::IDateFieldmark* 
pDateField, SwDoc& rDoc);
     virtual ~DateFormFieldDialog() override;
 
-    virtual short run() override
-    {
-        short nRet = GenericDialogController::run();
-        if (nRet == RET_OK)
-            Apply();
-        return nRet;
-    }
+    void Apply();
 };
 
 } // namespace sw
diff --git a/sw/source/uibase/shells/textsh1.cxx 
b/sw/source/uibase/shells/textsh1.cxx
index 362a01899e39..e561cc449b59 100644
--- a/sw/source/uibase/shells/textsh1.cxx
+++ b/sw/source/uibase/shells/textsh1.cxx
@@ -2031,14 +2031,25 @@ void SwTextShell::Execute(SfxRequest &rReq)
         else if ( pFieldBM && pFieldBM->GetFieldname() == ODF_FORMDATE )
         {
             SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
-            sw::mark::DateFieldmark& rDateField = 
dynamic_cast<sw::mark::DateFieldmark&>(*pFieldBM);
-            ScopedVclPtr<VclAbstractDialog> 
pDlg(pFact->CreateDateFormFieldDialog(rWrtSh.GetView().GetFrameWeld(), 
&rDateField, *GetView().GetDocShell()->GetDoc()));
-            if (pDlg->Execute() == RET_OK)
-            {
-                rDateField.Invalidate();
-                rWrtSh.InvalidateWindows( 
SwRect(rWrtSh.GetView().GetVisArea()) );
-                rWrtSh.UpdateCursor(); // cursor position might be invalid
-            }
+            sw::mark::DateFieldmark* pDateField = 
&dynamic_cast<sw::mark::DateFieldmark&>(*pFieldBM);
+            VclPtr<AbstractDateFormFieldDialog> 
pDlg(pFact->CreateDateFormFieldDialog(rWrtSh.GetView().GetFrameWeld(), 
pDateField, *GetView().GetDocShell()->GetDoc()));
+            auto pWrtSh = &rWrtSh;
+            auto xRequest = std::make_shared<SfxRequest>(rReq);
+            rReq.Ignore(); // the 'old' request is not relevant any more
+            pDlg->StartExecuteAsync(
+                [pDlg, pWrtSh, pDateField, xRequest] (sal_Int32 nResult)->void
+                {
+                    if (nResult == RET_OK)
+                    {
+                        pDlg->Apply();
+                        pDateField->Invalidate();
+                        pWrtSh->InvalidateWindows( 
SwRect(pWrtSh->GetView().GetVisArea()) );
+                        pWrtSh->UpdateCursor(); // cursor position might be 
invalid
+                    }
+                    pDlg->disposeOnce();
+                    xRequest->Done();
+                }
+            );
         }
         else
         {

Reply via email to