From d6188f8c3803490f75fbd1931a0bd6f821c4d700 Mon Sep 17 00:00:00 2001 From: Jan-Marek Glogowski Date: Fri, 7 Feb 2020 23:16:50 +0000 Subject: tdf#126700 allow replacing the default documents Per default, a document opened by a user action will always open in a new frame. For tdf#83722, this behaviour was extended to documents created from templates. But this currently also affects the default factory templates, if these are replaced by a config setting with a real template, which was not intentional. So this patch introduces a new MediaDescriptor property, which allows to mark a document as replaceable and automatically sets it for factory default documents. If this property is set to true, a document just acts as a placeholder while it's unmodified. I.e. the next opened document from its frame will close and replace it. For this backport the documentation in MediaDescriptor.idl is dropped, so people won't rely on this as a feature before 7.0. Change-Id: I45ffa8709f7cdda949fac78f3b363f120f0c4a03 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88257 Tested-by: Jenkins Reviewed-by: Thorsten Behrens (cherry picked from commit 61e1e0413296928d929f99c0f006c6cbbcf4ac40) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88537 --- framework/source/loadenv/loadenv.cxx | 10 ++++------ include/sfx2/sfxsids.hrc | 2 +- include/unotools/mediadescriptor.hxx | 1 + sfx2/source/appl/appuno.cxx | 18 ++++++++++++++++++ sfx2/source/doc/sfxbasemodel.cxx | 5 +++++ sfx2/source/view/frmload.cxx | 4 +++- sw/qa/python/check_xmodel.py | 4 +++- unotools/source/misc/mediadescriptor.cxx | 6 ++++++ 8 files changed, 41 insertions(+), 9 deletions(-) diff --git a/framework/source/loadenv/loadenv.cxx b/framework/source/loadenv/loadenv.cxx index 5c1414f3cbdf..3d04e17a23c2 100644 --- a/framework/source/loadenv/loadenv.cxx +++ b/framework/source/loadenv/loadenv.cxx @@ -1098,10 +1098,11 @@ bool LoadEnv::impl_loadContent() bool bHidden = m_lMediaDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_HIDDEN(), false); bool bMinimized = m_lMediaDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_MINIMIZED(), false); bool bPreview = m_lMediaDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_PREVIEW(), false); - css::uno::Reference< css::task::XStatusIndicator > xProgress = m_lMediaDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_STATUSINDICATOR(), css::uno::Reference< css::task::XStatusIndicator >()); if (!bHidden && !bMinimized && !bPreview) { + css::uno::Reference xProgress = m_lMediaDescriptor.getUnpackedValueOrDefault( + utl::MediaDescriptor::PROP_STATUSINDICATOR(), css::uno::Reference()); if (!xProgress.is()) { // Note: it's an optional interface! @@ -1524,12 +1525,9 @@ css::uno::Reference< css::frame::XFrame > LoadEnv::impl_searchRecycleTarget() if (xOldDoc.is()) { utl::MediaDescriptor lOldDocDescriptor(xModel->getArgs()); - bool bFromTemplate = lOldDocDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_ASTEMPLATE() , false); - OUString sReferrer = lOldDocDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_REFERRER(), OUString()); - // tdf#83722: valid but unmodified document, either from template - // or opened by the user (via File > New, referrer is set to private:user) - if (bFromTemplate || (sReferrer == "private:user")) + // replaceable document + if (!lOldDocDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_REPLACEABLE(), false)) return css::uno::Reference< css::frame::XFrame >(); bReactivateOldControllerOnError = xOldDoc->suspend(true); diff --git a/include/sfx2/sfxsids.hrc b/include/sfx2/sfxsids.hrc index 9fa90a5f6226..eb8e0e5c0360 100644 --- a/include/sfx2/sfxsids.hrc +++ b/include/sfx2/sfxsids.hrc @@ -269,8 +269,8 @@ class SvxSearchItem; #define SID_LOCK_PRINT (SID_SFX_START + 1736) #define SID_LOCK_SAVE (SID_SFX_START + 1737) #define SID_LOCK_EDITDOC (SID_SFX_START + 1738) +#define SID_REPLACEABLE (SID_SFX_START + 1739) -// SID_SFX_free_START (SID_SFX_START + 1739) // SID_SFX_free_END (SID_SFX_START + 3999) #define SID_OPEN_NEW_VIEW (SID_SFX_START + 520) diff --git a/include/unotools/mediadescriptor.hxx b/include/unotools/mediadescriptor.hxx index 6a826ce309ac..da94f4188b3c 100644 --- a/include/unotools/mediadescriptor.hxx +++ b/include/unotools/mediadescriptor.hxx @@ -84,6 +84,7 @@ class UNOTOOLS_DLLPUBLIC MediaDescriptor : public comphelper::SequenceAsHashMap static const OUString& PROP_PREVIEW(); static const OUString& PROP_READONLY(); static const OUString& PROP_REFERRER(); + static const OUString& PROP_REPLACEABLE(); static const OUString& PROP_SALVAGEDFILE(); static const OUString& PROP_STATUSINDICATOR(); static const OUString& PROP_STREAM(); diff --git a/sfx2/source/appl/appuno.cxx b/sfx2/source/appl/appuno.cxx index bfbe90dc896b..ff3fdfe91b6e 100644 --- a/sfx2/source/appl/appuno.cxx +++ b/sfx2/source/appl/appuno.cxx @@ -174,6 +174,7 @@ static char const sLockExport[] = "LockExport"; static char const sLockPrint[] = "LockPrint"; static char const sLockSave[] = "LockSave"; static char const sLockEditDoc[] = "LockEditDoc"; +static char const sReplaceable[] = "Replaceable"; static bool isMediaDescriptor( sal_uInt16 nSlotId ) { @@ -888,6 +889,14 @@ void TransformParameters( sal_uInt16 nSlotId, const uno::Sequence>= bVal); + DBG_ASSERT(bOK, "invalid type for Replaceable"); + if (bOK) + rSet.Put(SfxBoolItem(SID_REPLACEABLE, bVal)); + } #ifdef DBG_UTIL else --nFoundArgs; @@ -1115,6 +1124,8 @@ void TransformItems( sal_uInt16 nSlotId, const SfxItemSet& rSet, uno::Sequence(nId)); @@ -1699,6 +1712,11 @@ void TransformItems( sal_uInt16 nSlotId, const SfxItemSet& rSet, uno::Sequence(pItem)->GetValue(); } + if (rSet.GetItemState(SID_REPLACEABLE, false, &pItem) == SfxItemState::SET) + { + pValue[nActProp].Name = sReplaceable; + pValue[nActProp++].Value <<= static_cast(pItem)->GetValue(); + } } rArgs = aSequ; diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx index 394475c40129..a136f74f2886 100644 --- a/sfx2/source/doc/sfxbasemodel.cxx +++ b/sfx2/source/doc/sfxbasemodel.cxx @@ -1099,6 +1099,11 @@ void SAL_CALL SfxBaseModel::setArgs(const Sequence& aArgs) rArg.Value >>= bValue; pMedium->GetItemSet()->Put(SfxBoolItem(SID_LOCK_EDITDOC, bValue)); } + else if (rArg.Name == "Replaceable") + { + rArg.Value >>= bValue; + pMedium->GetItemSet()->Put(SfxBoolItem(SID_REPLACEABLE, bValue)); + } else { throw lang::IllegalArgumentException("Setting property not supported: " + rArg.Name, diff --git a/sfx2/source/view/frmload.cxx b/sfx2/source/view/frmload.cxx index d098ac5c00e2..b16d9b471048 100644 --- a/sfx2/source/view/frmload.cxx +++ b/sfx2/source/view/frmload.cxx @@ -624,7 +624,9 @@ sal_Bool SAL_CALL SfxFrameLoader_Impl::load( const Sequence< PropertyValue >& rA const OUString sURL = aDescriptor.getOrDefault( "URL", OUString() ); const bool bIsFactoryURL = sURL.startsWith( "private:factory/" ); bool bInitNewModel = bIsFactoryURL; - if ( bIsFactoryURL && !bExternalModel ) + const bool bIsDefault = bIsFactoryURL && !bExternalModel; + aDescriptor.put("Replaceable", bIsDefault); + if (bIsDefault) { const OUString sFactory = sURL.copy( sizeof( "private:factory/" ) -1 ); // special handling for some weird factory URLs a la private:factory/swriter?slot=21053 diff --git a/sw/qa/python/check_xmodel.py b/sw/qa/python/check_xmodel.py index f6894dd21a3f..27740958ddb1 100644 --- a/sw/qa/python/check_xmodel.py +++ b/sw/qa/python/check_xmodel.py @@ -37,7 +37,8 @@ class TestXModel(unittest.TestCase): p5 = PropertyValue(Name="LockPrint", Value=True) p6 = PropertyValue(Name="LockSave", Value=True) p7 = PropertyValue(Name="LockEditDoc", Value=True) - xDoc.setArgs([p1, p2, p3, p4, p5, p6, p7]) + p8 = PropertyValue(Name="Replaceable", Value=True) + xDoc.setArgs([p1, p2, p3, p4, p5, p6, p7, p8]) # Make sure that all properties are returned with getArgs() args = xDoc.getArgs() @@ -48,6 +49,7 @@ class TestXModel(unittest.TestCase): self.assertTrue(p5 in args) self.assertTrue(p6 in args) self.assertTrue(p7 in args) + self.assertTrue(p8 in args) xDoc.close(True) diff --git a/unotools/source/misc/mediadescriptor.cxx b/unotools/source/misc/mediadescriptor.cxx index 0d0839f62b18..1b830fb4e7d9 100644 --- a/unotools/source/misc/mediadescriptor.cxx +++ b/unotools/source/misc/mediadescriptor.cxx @@ -222,6 +222,12 @@ const OUString& MediaDescriptor::PROP_REFERRER() return sProp; } +const OUString& MediaDescriptor::PROP_REPLACEABLE() +{ + static const OUString sProp("Replaceable"); + return sProp; +} + const OUString& MediaDescriptor::PROP_STATUSINDICATOR() { static const OUString sProp("StatusIndicator"); -- cgit