sw/source/ui/dialog/swdlgfact.cxx |   22 +++++++++++++-
 sw/source/ui/dialog/swdlgfact.hxx |   14 +++++++++
 sw/source/uibase/shells/tabsh.cxx |   58 ++++++++++++++++++++------------------
 vcl/jsdialog/enabled.cxx          |    4 +-
 4 files changed, 69 insertions(+), 29 deletions(-)

New commits:
commit e6bfcb1e5d64d3cd76ede9019b4ddaac00159144
Author:     Skyler Grey <skyler3...@gmail.com>
AuthorDate: Fri Aug 12 10:31:42 2022 +0100
Commit:     Szymon Kłos <szymon.k...@collabora.com>
CommitDate: Mon Aug 22 14:46:14 2022 +0200

    Make the number format dialog an async jsdialog
    
    - The dialog needs to be async in order for multiple people to be able
      to use it at once
    - If we don't make the item set a shared pointer, we will crash out with
      an error when we try to copy it after the OK button is pressed
    - As the dialog is tabbed, we need to enable the dialog for all UI files
      that the dialog uses rather than just the main dialog UI file
    
    Change-Id: I8d684e9e9ad49b8a85ee940864d7219b4115a6e4
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138270
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Szymon Kłos <szymon.k...@collabora.com>

diff --git a/sw/source/ui/dialog/swdlgfact.cxx 
b/sw/source/ui/dialog/swdlgfact.cxx
index ba883398486a..4c9eac2c2834 100644
--- a/sw/source/ui/dialog/swdlgfact.cxx
+++ b/sw/source/ui/dialog/swdlgfact.cxx
@@ -110,6 +110,16 @@ short SwAbstractSfxController_Impl::Execute()
     return m_xDlg->run();
 }
 
+short AbstractNumFormatDlg_Impl::Execute()
+{
+    return m_xDlg->run();
+}
+
+bool AbstractNumFormatDlg_Impl::StartExecuteAsync(AsyncContext &rCtx)
+{
+    return SfxSingleTabDialogController::runAsync(m_xDlg, rCtx.maEndDialogFn);
+}
+
 short AbstractSwAsciiFilterDlg_Impl::Execute()
 {
     return m_xDlg->run();
@@ -356,11 +366,21 @@ const SfxItemSet* 
SwAbstractSfxController_Impl::GetOutputItemSet() const
     return m_xDlg->GetOutputItemSet();
 }
 
+const SfxItemSet* AbstractNumFormatDlg_Impl::GetOutputItemSet() const
+{
+    return m_xDlg->GetOutputItemSet();
+}
+
 void SwAbstractSfxController_Impl::SetText(const OUString& rStr)
 {
     m_xDlg->set_title(rStr);
 }
 
+void AbstractNumFormatDlg_Impl::SetText(const OUString& rStr)
+{
+    m_xDlg->set_title(rStr);
+}
+
 void AbstractSwAsciiFilterDlg_Impl::FillOptions( SwAsciiOptions& rOptions )
 {
     m_xDlg->FillOptions(rOptions);
@@ -832,7 +852,7 @@ VclPtr<SfxAbstractDialog> 
SwAbstractDialogFactory_Impl::CreateSwBackgroundDialog
 
 VclPtr<SfxAbstractDialog> 
SwAbstractDialogFactory_Impl::CreateNumFormatDialog(weld::Widget* pParent, 
const SfxItemSet& rSet)
 {
-    return 
VclPtr<SwAbstractSfxController_Impl>::Create(std::make_unique<SwNumFormatDlg>(pParent,
 rSet));
+    return 
VclPtr<AbstractNumFormatDlg_Impl>::Create(std::make_shared<SwNumFormatDlg>(pParent,
 rSet));
 }
 
 VclPtr<AbstractSwAsciiFilterDlg> 
SwAbstractDialogFactory_Impl::CreateSwAsciiFilterDlg(weld::Window* pParent,
diff --git a/sw/source/ui/dialog/swdlgfact.hxx 
b/sw/source/ui/dialog/swdlgfact.hxx
index b756a4de614e..ce809d3eaaa4 100644
--- a/sw/source/ui/dialog/swdlgfact.hxx
+++ b/sw/source/ui/dialog/swdlgfact.hxx
@@ -125,6 +125,20 @@ public:
     virtual void SetText(const OUString& rStr) override;
 };
 
+class AbstractNumFormatDlg_Impl : public SfxAbstractDialog
+{
+    std::shared_ptr<SfxSingleTabDialogController> m_xDlg;
+public:
+    explicit 
AbstractNumFormatDlg_Impl(std::shared_ptr<SfxSingleTabDialogController> p)
+        : m_xDlg(std::move(p))
+    {
+    }
+    virtual short Execute() override;
+    virtual bool StartExecuteAsync(AsyncContext &rCtx) override;
+    virtual const SfxItemSet* GetOutputItemSet() const override;
+    virtual void SetText(const OUString& rStr) override;
+};
+
 class AbstractSwAsciiFilterDlg_Impl : public AbstractSwAsciiFilterDlg
 {
     std::unique_ptr<SwAsciiFilterDlg> m_xDlg;
diff --git a/sw/source/uibase/shells/tabsh.cxx 
b/sw/source/uibase/shells/tabsh.cxx
index 4d83dd1ec756..9fbd241f3f20 100644
--- a/sw/source/uibase/shells/tabsh.cxx
+++ b/sw/source/uibase/shells/tabsh.cxx
@@ -695,57 +695,61 @@ void SwTableShell::Execute(SfxRequest &rReq)
                 FieldUnit eMetric = ::GetDfltMetric(dynamic_cast<SwWebView*>( 
pView) !=  nullptr );
                 SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< 
sal_uInt16 >(eMetric)));
                 SvNumberFormatter* pFormatter = rSh.GetNumberFormatter();
-                SfxItemSetFixed<SID_ATTR_NUMBERFORMAT_VALUE, 
SID_ATTR_NUMBERFORMAT_INFO>
-                    aCoreSet( GetPool() );
+                auto pCoreSet = 
std::make_shared<SfxItemSetFixed<SID_ATTR_NUMBERFORMAT_VALUE, 
SID_ATTR_NUMBERFORMAT_INFO>>( GetPool() );
 
                 SfxItemSetFixed<RES_BOXATR_FORMAT, RES_BOXATR_FORMAT,
                                 RES_BOXATR_VALUE, RES_BOXATR_VALUE>
-                     aBoxSet( *aCoreSet.GetPool() );
+                     aBoxSet( *pCoreSet->GetPool() );
                 rSh.GetTableBoxFormulaAttrs( aBoxSet );
 
                 SfxItemState eState = aBoxSet.GetItemState(RES_BOXATR_FORMAT);
                 if(eState == SfxItemState::DEFAULT)
                 {
-                    aCoreSet.Put( SfxUInt32Item( SID_ATTR_NUMBERFORMAT_VALUE,
+                    pCoreSet->Put( SfxUInt32Item( SID_ATTR_NUMBERFORMAT_VALUE,
                     pFormatter->GetFormatIndex(NF_TEXT, LANGUAGE_SYSTEM)));
                 }
                 else
-                    aCoreSet.Put( SfxUInt32Item( SID_ATTR_NUMBERFORMAT_VALUE,
+                    pCoreSet->Put( SfxUInt32Item( SID_ATTR_NUMBERFORMAT_VALUE,
                                     aBoxSet.Get(
                                     RES_BOXATR_FORMAT ).GetValue() ));
 
                 OUString sCurText( rSh.GetTableBoxText() );
-                aCoreSet.Put( SvxNumberInfoItem( pFormatter,
+                pCoreSet->Put( SvxNumberInfoItem( pFormatter,
                                     aBoxSet.Get(
                                         RES_BOXATR_VALUE).GetValue(),
                                     sCurText, SID_ATTR_NUMBERFORMAT_INFO ));
 
+                SwWrtShell* pSh = &rSh;
                 SwAbstractDialogFactory* pFact = 
SwAbstractDialogFactory::Create();
-                ScopedVclPtr<SfxAbstractDialog> 
pDlg(pFact->CreateNumFormatDialog(GetView().GetFrameWeld(), aCoreSet));
-
-                if (RET_OK == pDlg->Execute())
-                {
-                    const SvxNumberInfoItem* pNumberFormatItem
-                        = GetView().GetDocShell()->GetItem( 
SID_ATTR_NUMBERFORMAT_INFO );
+                VclPtr<SfxAbstractDialog> 
pDlg(pFact->CreateNumFormatDialog(GetView().GetFrameWeld(), *pCoreSet));
 
-                    if( pNumberFormatItem )
+                pDlg->StartExecuteAsync([pDlg, pCoreSet, pSh](sal_uInt32 
nResult){
+                    if (RET_OK == nResult)
                     {
-                        for ( sal_uInt32 key : 
pNumberFormatItem->GetDelFormats() )
-                            
pNumberFormatItem->GetNumberFormatter()->DeleteEntry( key );
+                        const SvxNumberInfoItem* pNumberFormatItem
+                            = pSh->GetView().GetDocShell()->GetItem( 
SID_ATTR_NUMBERFORMAT_INFO );
+
+                        if( pNumberFormatItem )
+                        {
+                            for ( sal_uInt32 key : 
pNumberFormatItem->GetDelFormats() )
+                                
pNumberFormatItem->GetNumberFormatter()->DeleteEntry( key );
+                        }
+
+                        const SfxPoolItem* pNumberFormatValueItem = nullptr;
+                        if( SfxItemState::SET == 
pDlg->GetOutputItemSet()->GetItemState(
+                            SID_ATTR_NUMBERFORMAT_VALUE, false, 
&pNumberFormatValueItem ))
+                        {
+                            SfxItemSetFixed<RES_BOXATR_FORMAT, 
RES_BOXATR_FORMAT>
+                                    aBoxFormatSet( *pCoreSet->GetPool() );
+                            aBoxFormatSet.Put( SwTableBoxNumFormat(
+                                    static_cast<const 
SfxUInt32Item*>(pNumberFormatValueItem)->GetValue() ));
+                            pSh->SetTableBoxFormulaAttrs( aBoxFormatSet );
+
+                        }
                     }
 
-                    const SfxPoolItem* pNumberFormatValueItem = nullptr;
-                    if( SfxItemState::SET == 
pDlg->GetOutputItemSet()->GetItemState(
-                        SID_ATTR_NUMBERFORMAT_VALUE, false, 
&pNumberFormatValueItem ))
-                    {
-                        SfxItemSetFixed<RES_BOXATR_FORMAT, RES_BOXATR_FORMAT>
-                                aBoxFormatSet( *aCoreSet.GetPool() );
-                        aBoxFormatSet.Put( SwTableBoxNumFormat(
-                                static_cast<const 
SfxUInt32Item*>(pNumberFormatValueItem)->GetValue() ));
-                        rSh.SetTableBoxFormulaAttrs( aBoxFormatSet );
-
-                    }
-                }
+                    pDlg->disposeOnce();
+                });
             }
             break;
         }
diff --git a/vcl/jsdialog/enabled.cxx b/vcl/jsdialog/enabled.cxx
index 2b4e2fcf3957..8a8550107981 100644
--- a/vcl/jsdialog/enabled.cxx
+++ b/vcl/jsdialog/enabled.cxx
@@ -68,7 +68,9 @@ bool isBuilderEnabled(std::u16string_view rUIFile, bool 
bMobile)
         || rUIFile == u"sfx/ui/descriptioninfopage.ui" || rUIFile == 
u"sfx/ui/documentinfopage.ui"
         || rUIFile == u"sfx/ui/linefragment.ui" || rUIFile == 
u"sfx/ui/editdurationdialog.ui"
         || rUIFile == u"modules/swriter/ui/insertcaption.ui"
-        || rUIFile == u"modules/swriter/ui/captionoptions.ui")
+        || rUIFile == u"modules/swriter/ui/captionoptions.ui"
+        || rUIFile == u"cui/ui/formatnumberdialog.ui"
+        || rUIFile == u"cui/ui/numberingformatpage.ui")
     {
         return true;
     }

Reply via email to