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 803d572838d8075e79d001fe6548f45878ea466f Author: Méven Car <meven....@collabora.com> AuthorDate: Tue Jan 9 15:15:23 2024 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Fri Jan 12 10:38:57 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 <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/source/ui/dialog/swdlgfact.cxx b/sw/source/ui/dialog/swdlgfact.cxx index f9e05b3f0d35..8c6cabae64cc 100644 --- a/sw/source/ui/dialog/swdlgfact.cxx +++ b/sw/source/ui/dialog/swdlgfact.cxx @@ -302,6 +302,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 359af1bc2e31..e0f21d170b57 100644 --- a/sw/source/ui/dialog/swdlgfact.hxx +++ b/sw/source/ui/dialog/swdlgfact.hxx @@ -644,6 +644,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 89248e7eed8d..b3dff074fdc1 100644 --- a/sw/source/ui/dialog/uiregionsw.cxx +++ b/sw/source/ui/dialog/uiregionsw.cxx @@ -818,12 +818,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 834f1b332bc5..ad020e28b92d 100644 --- a/sw/source/uibase/dialog/regionsw.cxx +++ b/sw/source/uibase/dialog/regionsw.cxx @@ -218,15 +218,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"