diff options
author | Caolán McNamara <caolan.mcnamara@collabora.com> | 2024-07-09 20:45:21 +0100 |
---|---|---|
committer | Caolán McNamara <caolan.mcnamara@collabora.com> | 2024-07-10 13:31:50 +0200 |
commit | 8b84691d5e2c02429c53fe9a8dc2f20e39a9d35c (patch) | |
tree | 06e0817e062c763844dd2a77e8392f0bca961a5f | |
parent | cda866cff5131c80f65895c5e14ce252a0ae2060 (diff) |
make query set ins mode dialog async
Change-Id: I1951abc34cca59aaffb85540d38e2f002ddc3f09
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170256
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Tested-by: Jenkins
-rw-r--r-- | sw/source/uibase/inc/wrtsh.hxx | 2 | ||||
-rw-r--r-- | 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<weld::Builder> xBuilder(Application::CreateBuilder(GetView().GetFrameWeld(), u"cui/ui/querysetinsmodedialog.ui"_ustr)); - std::unique_ptr<weld::Dialog> xQuery(xBuilder->weld_dialog(u"SetInsModeDialog"_ustr)); - std::unique_ptr<weld::Image> xImage(xBuilder->weld_image(u"imSetInsMode"_ustr)); - std::unique_ptr<weld::CheckButton> xCheckBox(xBuilder->weld_check_button(u"cbDontShowAgain"_ustr)); - - xImage->set_from_icon_name(RID_BMP_QUERYINSMODE); - - const int nResult = xQuery->run(); - - std::shared_ptr<comphelper::ConfigurationChanges> xChanges( - comphelper::ConfigurationChanges::create()); - officecfg::Office::Common::Misc::QuerySetInsMode::set(!xCheckBox->get_active(), xChanges); - xChanges->commit(); - - if ( nResult == static_cast<int>(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<weld::Image> m_xImage; + std::unique_ptr<weld::CheckButton> 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<QuerySetInsModeDialog>(GetView().GetFrameWeld()); + weld::DialogController::runAsync(xDialog, [this, bOn, xDialog](sal_Int32 nResult){ + + std::shared_ptr<comphelper::ConfigurationChanges> xChanges( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Common::Misc::QuerySetInsMode::set(!xDialog->GetDoNotShowAgain(), xChanges); + xChanges->commit(); + + if ( nResult == static_cast<int>(RET_NO) ) + return; + + ImplSetInsMode(bOn); + }); + return; + } + ImplSetInsMode(bOn); +} + //Overwrite mode is incompatible with red-lining void SwWrtShell::SetRedlineFlagsAndCheckInsMode( RedlineFlags eMode ) { |