sd/inc/sdfilter.hxx | 2 + sd/source/filter/xml/sdxmlwrp.cxx | 34 ++++++++++++++++++- sd/source/ui/slidesorter/controller/SlsClipboard.cxx | 15 ++++++++ 3 files changed, 50 insertions(+), 1 deletion(-)
New commits: commit 92a8731e0bab5509ff51064e02ac4d5bdb4e9668 Author: Caolán McNamara <caolan.mcnam...@collabora.com> AuthorDate: Wed Apr 16 14:36:46 2025 +0100 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Thu Apr 17 11:55:21 2025 +0200 Ignore pastes that don't originate from a Slide Sorter so we only do the creation of new pages when pasting entire slides, and do the usual paste otherwise. if this doesn't work out then an alternative idea is to extend TransferableObjectDescriptor with some additional information. Change-Id: I3630ff46c118350e8988e0c8cbd03b83a5a4e1ae Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184279 Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> Reviewed-by: Pranam Lashkari <lpra...@collabora.com> Tested-by: Caolán McNamara <caolan.mcnam...@collabora.com> (cherry picked from commit f57727e8ea65edbc8e6c25730f2b6574d4fa9b6e) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184314 Tested-by: Jenkins diff --git a/sd/inc/sdfilter.hxx b/sd/inc/sdfilter.hxx index ef3fb7763210..cfd4d85e735b 100644 --- a/sd/inc/sdfilter.hxx +++ b/sd/inc/sdfilter.hxx @@ -69,4 +69,6 @@ SD_DLLPUBLIC bool ImportPPT( SD_DLLPUBLIC bool SaveVBA( SfxObjectShell& rDocShell, SvMemoryStream*& pBas ); +SD_DLLPUBLIC bool IsSlideSorterPaste(::sd::DrawDocShell& rDocSh); + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/source/filter/xml/sdxmlwrp.cxx b/sd/source/filter/xml/sdxmlwrp.cxx index b8cc7bf10226..8bf962a7ede0 100644 --- a/sd/source/filter/xml/sdxmlwrp.cxx +++ b/sd/source/filter/xml/sdxmlwrp.cxx @@ -77,6 +77,9 @@ #include <tools/debug.hxx> #include <comphelper/diagnose_ex.hxx> +#include <com/sun/star/beans/XPropertyContainer.hpp> +#include <com/sun/star/document/XDocumentProperties.hpp> + using namespace com::sun::star; using namespace com::sun::star::uno; using namespace com::sun::star::lang; @@ -728,6 +731,28 @@ bool SdXMLFilter::Import( ErrCode& nError ) return nRet == ERRCODE_NONE; } +bool IsSlideSorterPaste(::sd::DrawDocShell& rDocSh) +{ + uno::Reference<document::XDocumentProperties> xSource = rDocSh.getDocProperties(); + uno::Reference<beans::XPropertyContainer> xSourcePropertyContainer = xSource->getUserDefinedProperties(); + uno::Reference<beans::XPropertySet> xSourcePropertySet(xSourcePropertyContainer, uno::UNO_QUERY); + if (!xSourcePropertySet) + return false; + + const uno::Sequence<beans::Property> lProps = xSourcePropertySet->getPropertySetInfo()->getProperties(); + for (const beans::Property& rProp : lProps) + { + if (rProp.Name != "slidesorter") + continue; + uno::Any aFromSlideSorter = xSourcePropertySet->getPropertyValue("slidesorter"); + bool bFromSlideSorter(false); + aFromSlideSorter >>= bFromSlideSorter; + return bFromSlideSorter; + } + + return false; +} + bool SdXMLFilter::Export() { rtl::Reference<SvXMLEmbeddedObjectHelper> xObjectHelper; @@ -853,7 +878,14 @@ bool SdXMLFilter::Export() aServices[i ].mpService = pServiceNames->mpSettings; aServices[i++].mpStream = "settings.xml"; - if( mrDocShell.GetCreateMode() != SfxObjectCreateMode::EMBEDDED ) + bool bExportMeta = mrDocShell.GetCreateMode() != SfxObjectCreateMode::EMBEDDED; + if (!bExportMeta) + { + // Export meta information anyway when this is a copy from the + // slide sorter so we can distinguish that at paste time + bExportMeta = IsSlideSorterPaste(mrDocShell); + } + if (bExportMeta) { aServices[i ].mpService = pServiceNames->mpMeta; aServices[i++].mpStream = "meta.xml"; diff --git a/sd/source/ui/slidesorter/controller/SlsClipboard.cxx b/sd/source/ui/slidesorter/controller/SlsClipboard.cxx index 8df0ca101768..10f673b01071 100644 --- a/sd/source/ui/slidesorter/controller/SlsClipboard.cxx +++ b/sd/source/ui/slidesorter/controller/SlsClipboard.cxx @@ -53,10 +53,14 @@ #include <ins_paste.hxx> #include <drawdoc.hxx> #include <DrawDocShell.hxx> +#include <sdfilter.hxx> #include <sdpage.hxx> #include <sdtreelb.hxx> #include <app.hrc> +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/beans/XPropertyContainer.hpp> +#include <com/sun/star/document/XDocumentProperties.hpp> #include <com/sun/star/datatransfer/dnd/DNDConstants.hpp> #include <com/sun/star/uno/Reference.h> #include <com/sun/star/embed/XStorage.hpp> @@ -441,6 +445,11 @@ void Clipboard::CreateSlideTransferable ( pTransferable->GetWorkDocument()->GetDocSh() ->FillTransferableObjectDescriptor (*pObjDesc); + // Makes it possible at paste site to determine that the origin is the slide sorter + uno::Reference<document::XDocumentProperties> xDestination = pTransferable->GetWorkDocument()->GetDocSh()->getDocProperties(); + uno::Reference<beans::XPropertyContainer> xDestinationPropertyContainer = xDestination->getUserDefinedProperties(); + xDestinationPropertyContainer->addProperty("slidesorter", beans::PropertyAttribute::REMOVABLE, uno::Any(true)); + if (pDataDocSh != nullptr) pObjDesc->maDisplayName = pDataDocSh->GetMedium()->GetURLObject().GetURLNoPass(); @@ -934,6 +943,12 @@ bool Clipboard::PasteSlidesFromSystemClipboard() pDocument->GetDocumentType())); SfxMedium* pMedium = new SfxMedium(xStore, OUString()); xDocShRef->DoLoad(pMedium); + + // Only accept pastes that originated in a slide sorter here, so we + // don't create a new page for other types of pastes + if (!IsSlideSorterPaste(*xDocShRef)) + return false; + std::vector<OUString> aBookmarkList; std::vector<OUString> aExchangeList;