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 <mike.kaganski@collabora.com>
diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx
index 1bc1f53..6a5da58 100644
--- a/include/sfx2/objsh.hxx
+++ b/include/sfx2/objsh.hxx
@@ -218,6 +218,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)
@@ -775,6 +782,13 @@ public:
/// Gets the certificate that is already picked by the user but not yet used for signing.
css::uno::Reference<css::security::XCertificate> GetSignPDFCertificate() const;
// Lock all unlocked views, and returns a guard object which unlocks those views when destructed
virtual std::unique_ptr<LockAllViewsGuard> LockAllViews()
{
return std::make_unique<LockAllViewsGuard>();
}
};
#define SFX_GLOBAL_CLASSID \
diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx
index f3a6b22..0d4f047 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -1134,6 +1134,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<const SfxFilter> pFilter = rMedium.GetFilter();
if ( !pFilter )
diff --git a/sw/inc/docsh.hxx b/sw/inc/docsh.hxx
index 225305a..6dc7fdf 100644
--- a/sw/inc/docsh.hxx
+++ b/sw/inc/docsh.hxx
@@ -319,16 +319,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 SAL_DLLPRIVATE LockAllViewsGuard
// Lock all unlocked views, and returns a guard object which unlocks those views when destructed
virtual std::unique_ptr<LockAllViewsGuard> LockAllViews() override;
protected:
class LockAllViewsGuard_Impl : public LockAllViewsGuard
{
std::vector<SwViewShell*> 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<LockAllViewsGuard> 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 f323d7a..9846c17 100644
--- a/sw/source/uibase/app/docsh.cxx
+++ b/sw/source/uibase/app/docsh.cxx
@@ -349,7 +349,7 @@ bool SwDocShell::Save()
return !nErr.IsError();
}
SwDocShell::LockAllViewsGuard::LockAllViewsGuard(SwViewShell* pViewShell)
SwDocShell::LockAllViewsGuard_Impl::LockAllViewsGuard_Impl(SwViewShell* pViewShell)
{
if (!pViewShell)
return;
@@ -363,23 +363,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::LockAllViewsGuard> SwDocShell::LockAllViews()
std::unique_ptr<SfxObjectShell::LockAllViewsGuard> SwDocShell::LockAllViews()
{
return std::make_unique<LockAllViewsGuard>(GetEditShell());
return std::make_unique<LockAllViewsGuard_Impl>(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();