sw/source/ui/dialog/swdlgfact.cxx | 5 +++++ sw/source/ui/dialog/swdlgfact.hxx | 1 + sw/source/ui/dialog/uiregionsw.cxx | 7 +++++-- sw/source/uibase/dialog/regionsw.cxx | 16 +++++++++------- vcl/jsdialog/enabled.cxx | 1 + 5 files changed, 21 insertions(+), 9 deletions(-)
New commits: commit 0ffa0f103f928da3785f8b6a71d2956ba51b6989 Author: Méven Car <[email protected]> AuthorDate: Tue Jan 9 15:15:23 2024 +0100 Commit: Andras Timar <[email protected]> CommitDate: Tue Jan 16 07:59:51 2024 +0100 cool#1770 sw: make Edit Sections dialog async and mark it a jsdialog We want our dialogs to be async so they don't lock documents when opened and to allow concurrent edition. In SwEditRegionDlg, we need to make sure the reference to the SwWrtShell isn't read from 'this' after `response()`, as it is now the dialog is disposed of earlier in the async case. How to test: Create a new Writer document, insert a section, right-click inside the section, pick the 'edit section' menu item to trigger this dialog. Change-Id: Ibafca69542f13d16beef5a8fca006428cbcfe5c1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161828 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Miklos Vajna <[email protected]> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161830 Tested-by: Jenkins Reviewed-by: Andras Timar <[email protected]> diff --git a/sw/source/ui/dialog/swdlgfact.cxx b/sw/source/ui/dialog/swdlgfact.cxx index 66ac1ec21a25..30e41e4edaf4 100644 --- a/sw/source/ui/dialog/swdlgfact.cxx +++ b/sw/source/ui/dialog/swdlgfact.cxx @@ -307,6 +307,11 @@ short AbstractEditRegionDlg_Impl::Execute() return m_xDlg->run(); } +bool AbstractEditRegionDlg_Impl::StartExecuteAsync(AsyncContext &rCtx) +{ + return weld::DialogController::runAsync(m_xDlg, rCtx.maEndDialogFn); +} + short AbstractInsertSectionTabDialog_Impl::Execute() { return m_xDlg->run(); diff --git a/sw/source/ui/dialog/swdlgfact.hxx b/sw/source/ui/dialog/swdlgfact.hxx index d5c1c43806d8..c2c043bb3eb6 100644 --- a/sw/source/ui/dialog/swdlgfact.hxx +++ b/sw/source/ui/dialog/swdlgfact.hxx @@ -663,6 +663,7 @@ public: { } virtual short Execute() override; + virtual bool StartExecuteAsync(AsyncContext &rCtx) override; virtual void SelectSection(const OUString& rSectionName) override; }; diff --git a/sw/source/ui/dialog/uiregionsw.cxx b/sw/source/ui/dialog/uiregionsw.cxx index e3b56283f5cc..f1499b6a28ca 100644 --- a/sw/source/ui/dialog/uiregionsw.cxx +++ b/sw/source/ui/dialog/uiregionsw.cxx @@ -820,12 +820,15 @@ IMPL_LINK_NOARG(SwEditRegionDlg, OkHdl, weld::Button&, void) aOrigArray.clear(); + SwWrtShell& rSh = m_rSh; + // response must be called ahead of EndAction's end, // otherwise ScrollError can occur. m_xDialog->response(RET_OK); - m_rSh.EndUndo(); - m_rSh.EndAllAction(); + // accessing 'this' after response isn't safe, as the callback might cause the dialog to be disposed + rSh.EndUndo(); + rSh.EndAllAction(); } // Toggle protect diff --git a/sw/source/uibase/dialog/regionsw.cxx b/sw/source/uibase/dialog/regionsw.cxx index 9eaa64c89456..71f0c165b458 100644 --- a/sw/source/uibase/dialog/regionsw.cxx +++ b/sw/source/uibase/dialog/regionsw.cxx @@ -217,15 +217,17 @@ void SwBaseShell::EditRegionDialog(SfxRequest const & rReq) case FN_EDIT_CURRENT_REGION: { weld::Window* pParentWin = GetView().GetFrameWeld(); + + SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); + VclPtr<AbstractEditRegionDlg> pEditRegionDlg(pFact->CreateEditRegionDlg(pParentWin, rWrtShell)); + + if(auto pStringItem = dynamic_cast< const SfxStringItem *>( pItem )) { - SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); - ScopedVclPtr<AbstractEditRegionDlg> pEditRegionDlg(pFact->CreateEditRegionDlg(pParentWin, rWrtShell)); - if(auto pStringItem = dynamic_cast< const SfxStringItem *>( pItem )) - { - pEditRegionDlg->SelectSection(pStringItem->GetValue()); - } - pEditRegionDlg->Execute(); + pEditRegionDlg->SelectSection(pStringItem->GetValue()); } + pEditRegionDlg->StartExecuteAsync([pEditRegionDlg](sal_Int32 /*nResult */){ + pEditRegionDlg->disposeOnce(); + }); } break; } diff --git a/vcl/jsdialog/enabled.cxx b/vcl/jsdialog/enabled.cxx index 058880a97835..c8ed0d73efad 100644 --- a/vcl/jsdialog/enabled.cxx +++ b/vcl/jsdialog/enabled.cxx @@ -178,6 +178,7 @@ bool isBuilderEnabled(std::u16string_view rUIFile, bool bMobile) || rUIFile == u"modules/swriter/ui/contentcontrollistitemdlg.ui" || rUIFile == u"modules/swriter/ui/dropcapspage.ui" || rUIFile == u"modules/swriter/ui/dropdownfielddialog.ui" + || rUIFile == u"modules/swriter/ui/editsectiondialog.ui" || rUIFile == u"modules/swriter/ui/endnotepage.ui" || rUIFile == u"modules/swriter/ui/footendnotedialog.ui" || rUIFile == u"modules/swriter/ui/footnoteareapage.ui"
