From 9d7d48d3603c246cf00ed34fe5336d2c19cfcd47 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Wed, 29 Jul 2020 17:45:03 +0300 Subject: tdf#135244: move LockAllViews to SfxObjectShell ... so that it may be called from SfxObjectShell::SaveTo_Impl, and handle export cases in addition to save (as) handled in tdf#41063. Change-Id: Ie39196656dd1a95dcb6bab3ae8138c2f5c8729e6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99714 Tested-by: Jenkins Reviewed-by: Mike Kaganski --- include/sfx2/objsh.hxx | 14 ++++++++++++++ sfx2/source/doc/objstor.cxx | 2 ++ sw/inc/docsh.hxx | 13 ++++++++----- sw/source/uibase/app/docsh.cxx | 10 ++++------ 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx index 4db1c5769e80..35210463240e 100644 --- a/include/sfx2/objsh.hxx +++ b/include/sfx2/objsh.hxx @@ -215,6 +215,13 @@ protected: // helper method void AddToRecentlyUsedList(); + // Parent class for actual guard objects that would do useful work + class LockAllViewsGuard + { + public: + virtual ~LockAllViewsGuard() {} + }; + public: SFX_DECL_INTERFACE(SFX_INTERFACE_SFXDOCSH) @@ -746,6 +753,13 @@ public: /** override this if you have a XmlIdRegistry. */ virtual const sfx2::IXmlIdRegistry* GetXmlIdRegistry() const { return nullptr; } + + // Lock all unlocked views, and returns a guard object which unlocks those views when destructed + virtual std::unique_ptr LockAllViews() + { + return std::make_unique(); + } + }; #define SFX_GLOBAL_CLASSID \ diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx index 36f58416a9e9..4b58cbe14ecb 100644 --- a/sfx2/source/doc/objstor.cxx +++ b/sfx2/source/doc/objstor.cxx @@ -1154,6 +1154,8 @@ bool SfxObjectShell::SaveTo_Impl UpdateDocInfoForSave(); ModifyBlocker_Impl aMod(this); + // tdf#41063, tdf#135244: prevent jumping to cursor at any temporary modification + auto aViewGuard(LockAllViews()); std::shared_ptr pFilter = rMedium.GetFilter(); if ( !pFilter ) diff --git a/sw/inc/docsh.hxx b/sw/inc/docsh.hxx index 291b20455c17..ba0a823ed258 100644 --- a/sw/inc/docsh.hxx +++ b/sw/inc/docsh.hxx @@ -322,16 +322,19 @@ public: void CallAutomationDocumentEventSinks(const OUString& Method, css::uno::Sequence< css::uno::Any >& Arguments); void RegisterAutomationDocumentObject(css::uno::Reference< ooo::vba::word::XDocument > const& xDocument); - class LockAllViewsGuard + // Lock all unlocked views, and returns a guard object which unlocks those views when destructed + virtual std::unique_ptr LockAllViews() override; + +protected: + class LockAllViewsGuard_Impl : public LockAllViewsGuard { std::vector m_aViewWasUnLocked; public: - explicit LockAllViewsGuard(SwViewShell* pViewShell); - ~LockAllViewsGuard(); + explicit LockAllViewsGuard_Impl(SwViewShell* pViewShell); + ~LockAllViewsGuard_Impl(); }; - // Lock all unlocked views, and returns a guard object which unlocks those views when destructed - std::unique_ptr LockAllViews(); + }; /** Find the right DocShell and create a new one: diff --git a/sw/source/uibase/app/docsh.cxx b/sw/source/uibase/app/docsh.cxx index 083b4ec6c648..a6a56fb33366 100644 --- a/sw/source/uibase/app/docsh.cxx +++ b/sw/source/uibase/app/docsh.cxx @@ -380,7 +380,7 @@ bool SwDocShell::Save() return !nErr.IsError(); } -SwDocShell::LockAllViewsGuard::LockAllViewsGuard(SwViewShell* pViewShell) +SwDocShell::LockAllViewsGuard_Impl::LockAllViewsGuard_Impl(SwViewShell* pViewShell) { if (!pViewShell) return; @@ -394,23 +394,21 @@ SwDocShell::LockAllViewsGuard::LockAllViewsGuard(SwViewShell* pViewShell) } } -SwDocShell::LockAllViewsGuard::~LockAllViewsGuard() +SwDocShell::LockAllViewsGuard_Impl::~LockAllViewsGuard_Impl() { for (SwViewShell* pShell : m_aViewWasUnLocked) pShell->LockView(false); } -std::unique_ptr SwDocShell::LockAllViews() +std::unique_ptr SwDocShell::LockAllViews() { - return std::make_unique(GetEditShell()); + return std::make_unique(GetEditShell()); } // Save using the Defaultformat bool SwDocShell::SaveAs( SfxMedium& rMedium ) { SwWait aWait( *this, true ); - // tdf#41063: prevent jumping to cursor at any temporary modification - auto aViewGuard(LockAllViews()); //#i3370# remove quick help to prevent saving of autocorrection suggestions if (m_pView) m_pView->GetEditWin().StopQuickHelp(); -- cgit