From 8b84691d5e2c02429c53fe9a8dc2f20e39a9d35c Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Tue, 9 Jul 2024 20:45:21 +0100 Subject: make query set ins mode dialog async MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I1951abc34cca59aaffb85540d38e2f002ddc3f09 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170256 Reviewed-by: Caolán McNamara Tested-by: Jenkins --- sw/source/uibase/inc/wrtsh.hxx | 2 ++ sw/source/uibase/wrtsh/select.cxx | 66 +++++++++++++++++++++++++++------------ 2 files changed, 48 insertions(+), 20 deletions(-) diff --git a/sw/source/uibase/inc/wrtsh.hxx b/sw/source/uibase/inc/wrtsh.hxx index 58f3865827a1..395aa4b36c82 100644 --- a/sw/source/uibase/inc/wrtsh.hxx +++ b/sw/source/uibase/inc/wrtsh.hxx @@ -640,6 +640,8 @@ private: bool bSelect, bool bDontMoveRegion = false); bool GoEnd(bool KeepArea = false, const bool * = nullptr); + SAL_DLLPRIVATE void ImplSetInsMode(bool bOn); + enum BookMarkMove { BOOKMARK_INDEX, diff --git a/sw/source/uibase/wrtsh/select.cxx b/sw/source/uibase/wrtsh/select.cxx index 404ee207e5c6..fdac5dc57cb3 100644 --- a/sw/source/uibase/wrtsh/select.cxx +++ b/sw/source/uibase/wrtsh/select.cxx @@ -713,27 +713,8 @@ void SwWrtShell::LeaveBlockMode() // Insert mode -void SwWrtShell::SetInsMode( bool bOn ) +void SwWrtShell::ImplSetInsMode(bool bOn) { - const bool bDoAsk = officecfg::Office::Common::Misc::QuerySetInsMode::get(); - if (!bOn && bDoAsk) { - std::unique_ptr xBuilder(Application::CreateBuilder(GetView().GetFrameWeld(), u"cui/ui/querysetinsmodedialog.ui"_ustr)); - std::unique_ptr xQuery(xBuilder->weld_dialog(u"SetInsModeDialog"_ustr)); - std::unique_ptr xImage(xBuilder->weld_image(u"imSetInsMode"_ustr)); - std::unique_ptr xCheckBox(xBuilder->weld_check_button(u"cbDontShowAgain"_ustr)); - - xImage->set_from_icon_name(RID_BMP_QUERYINSMODE); - - const int nResult = xQuery->run(); - - std::shared_ptr xChanges( - comphelper::ConfigurationChanges::create()); - officecfg::Office::Common::Misc::QuerySetInsMode::set(!xCheckBox->get_active(), xChanges); - xChanges->commit(); - - if ( nResult == static_cast(RET_NO) ) - return; - } m_bIns = bOn; SwCursorShell::SetOverwriteCursor( !m_bIns ); const SfxBoolItem aTmp( SID_ATTR_INSERT, m_bIns ); @@ -742,6 +723,51 @@ void SwWrtShell::SetInsMode( bool bOn ) EndAction(); Invalidate(); } + +namespace +{ + class QuerySetInsModeDialog : public weld::GenericDialogController + { + std::unique_ptr m_xImage; + std::unique_ptr m_xCheckBox; + public: + QuerySetInsModeDialog(weld::Window* pParent) + : GenericDialogController(pParent, u"cui/ui/querysetinsmodedialog.ui"_ustr, u"SetInsModeDialog"_ustr) + , m_xImage(m_xBuilder->weld_image(u"imSetInsMode"_ustr)) + , m_xCheckBox(m_xBuilder->weld_check_button(u"cbDontShowAgain"_ustr)) + { + m_xImage->set_from_icon_name(RID_BMP_QUERYINSMODE); + } + bool GetDoNotShowAgain() const + { + return m_xCheckBox->get_active(); + } + }; +} + +void SwWrtShell::SetInsMode( bool bOn ) +{ + const bool bDoAsk = officecfg::Office::Common::Misc::QuerySetInsMode::get(); + if (!bOn && bDoAsk) + { + auto xDialog = std::make_shared(GetView().GetFrameWeld()); + weld::DialogController::runAsync(xDialog, [this, bOn, xDialog](sal_Int32 nResult){ + + std::shared_ptr xChanges( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Common::Misc::QuerySetInsMode::set(!xDialog->GetDoNotShowAgain(), xChanges); + xChanges->commit(); + + if ( nResult == static_cast(RET_NO) ) + return; + + ImplSetInsMode(bOn); + }); + return; + } + ImplSetInsMode(bOn); +} + //Overwrite mode is incompatible with red-lining void SwWrtShell::SetRedlineFlagsAndCheckInsMode( RedlineFlags eMode ) { -- cgit