sd/source/ui/slidesorter/controller/SlsClipboard.cxx     |   45 +++++++++++++++
 sd/source/ui/slidesorter/controller/SlsSlotManager.cxx   |    5 +
 sd/source/ui/slidesorter/inc/controller/SlsClipboard.hxx |    6 ++
 sd/source/ui/view/drviewse.cxx                           |   16 +++++
 sd/source/ui/view/sdview3.cxx                            |   15 ++++-
 sfx2/source/control/unoctitm.cxx                         |    1 
 6 files changed, 87 insertions(+), 1 deletion(-)

New commits:
commit 911a9a1a9f2e83b6c899ea409a0a7f16aa61bc46
Author:     Pranam Lashkari <lpra...@collabora.com>
AuthorDate: Tue Apr 15 21:19:43 2025 +0530
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Wed Apr 16 11:31:19 2025 +0200

    sd: copy slides from instance to another
    
    in core this works between multiple instances (ie: multi users)
    in online now its will be possible to copy slides from one
    presentation to another
    
    in core to test with multiple instance:
    ./instdir/program/soffice -env:UserInstallation=file:///tmp/test1 &
    ./instdir/program/soffice -env:UserInstallation=file:///tmp/test2 &
    
    Co-authored-by: Pranam Lashkari <lpra...@collabora.com>
    Co-authored-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Change-Id: I95b4d332968fd8895b1d950ea620ea37a85524c8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184232
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sd/source/ui/slidesorter/controller/SlsClipboard.cxx 
b/sd/source/ui/slidesorter/controller/SlsClipboard.cxx
index 5d7a90eacda2..102211ae911a 100644
--- a/sd/source/ui/slidesorter/controller/SlsClipboard.cxx
+++ b/sd/source/ui/slidesorter/controller/SlsClipboard.cxx
@@ -58,6 +58,8 @@
 #include <app.hrc>
 
 #include <com/sun/star/datatransfer/dnd/DNDConstants.hpp>
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/embed/XStorage.hpp>
 #include <sfx2/request.hxx>
 #include <sfx2/viewfrm.hxx>
 #include <sfx2/bindings.hxx>
@@ -67,6 +69,10 @@
 #include <rtl/ustring.hxx>
 #include <vcl/svapp.hxx>
 
+#include <comphelper/storagehelper.hxx>
+
+using namespace ::com::sun::star;
+
 namespace sd::slidesorter::controller {
 
 namespace {
@@ -917,6 +923,45 @@ sal_Int8 Clipboard::ExecuteOrAcceptShapeDrop (
     return nResult;
 }
 
+bool Clipboard::PasteSlidesFromSystemClipboard()
+{
+    ViewShellBase* pBase = mrSlideSorter.GetViewShellBase();
+    std::shared_ptr<DrawViewShell> pDrawViewShell(
+        std::dynamic_pointer_cast<DrawViewShell>(pBase->GetMainViewShell()));
+    TransferableDataHelper aDataHelper(
+        
TransferableDataHelper::CreateFromSystemClipboard(pDrawViewShell->GetActiveWindow()));
+
+    SdDrawDocument* pDocument = mrSlideSorter.GetModel().GetDocument();
+    assert(pDocument);
+    OUString aDocShellID = 
SfxObjectShell::CreateShellID(pDocument->GetDocSh());
+    auto xStm = aDataHelper.GetInputStream(SotClipboardFormatId::EMBED_SOURCE, 
aDocShellID);
+
+    if (xStm.is())
+    {
+        uno::Reference<embed::XStorage> xStore(
+            ::comphelper::OStorageHelper::GetStorageFromInputStream(xStm));
+        ::sd::DrawDocShellRef xDocShRef(new 
::sd::DrawDocShell(SfxObjectCreateMode::EMBEDDED, true,
+                                                               
pDocument->GetDocumentType()));
+        SfxMedium* pMedium = new SfxMedium(xStore, OUString());
+        xDocShRef->DoLoad(pMedium);
+        std::vector<OUString> aBookmarkList;
+        std::vector<OUString> aExchangeList;
+
+        auto insertPos = mrSlideSorter.GetModel().GetCoreIndex(
+            
mrSlideSorter.GetController().GetClipboard().GetInsertionPosition());
+        pDocument->InsertBookmarkAsPage(aBookmarkList, &aExchangeList, false 
/*bLink*/,
+                                        false /*bReplace*/, insertPos 
/*nPos*/, true,
+                                        xDocShRef.get(), true, true, false);
+
+        std::vector<OUString> aObjectBookmarkList;
+        pDocument->InsertBookmarkAsObject(aObjectBookmarkList, aExchangeList, 
xDocShRef.get(),
+                                          nullptr, false);
+
+        return true;
+    }
+    return false;
+}
+
 } // end of namespace ::sd::slidesorter::controller
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sd/source/ui/slidesorter/controller/SlsSlotManager.cxx 
b/sd/source/ui/slidesorter/controller/SlsSlotManager.cxx
index 7c749e318692..a9051bc41059 100644
--- a/sd/source/ui/slidesorter/controller/SlsSlotManager.cxx
+++ b/sd/source/ui/slidesorter/controller/SlsSlotManager.cxx
@@ -368,6 +368,11 @@ void SlotManager::FuSupport (SfxRequest& rRequest)
         case SID_PASTE_SLIDE:
         {
             SdTransferable* pTransferClip = SdModule::get()->pTransferClip;
+            if (!pTransferClip)
+            {
+                if 
(mrSlideSorter.GetController().GetClipboard().PasteSlidesFromSystemClipboard())
+                    return;
+            }
             if( pTransferClip )
             {
                 SfxObjectShell* pTransferDocShell = 
pTransferClip->GetDocShell().get();
diff --git a/sd/source/ui/slidesorter/inc/controller/SlsClipboard.hxx 
b/sd/source/ui/slidesorter/inc/controller/SlsClipboard.hxx
index 6ced17486efe..b95a501623b7 100644
--- a/sd/source/ui/slidesorter/inc/controller/SlsClipboard.hxx
+++ b/sd/source/ui/slidesorter/inc/controller/SlsClipboard.hxx
@@ -120,6 +120,7 @@ private:
         vcl::Window* pWindow,
         bool bDrag);
 
+public:
     /** Determine the position of where to insert the pages in the current
         transferable of the sd module.
         @return
@@ -128,6 +129,11 @@ private:
     */
     sal_Int32 GetInsertionPosition ();
 
+    /** Paste the slides copied from another instance of the LibreOffice
+    */
+    bool PasteSlidesFromSystemClipboard();
+
+private:
     /** Paste the pages of the transferable of the sd module at the given
         position.
         @param nInsertPosition
diff --git a/sd/source/ui/view/drviewse.cxx b/sd/source/ui/view/drviewse.cxx
index cb8b10cd1b53..d05a0bf9aa13 100644
--- a/sd/source/ui/view/drviewse.cxx
+++ b/sd/source/ui/view/drviewse.cxx
@@ -100,6 +100,10 @@
 #include <officecfg/Office/Draw.hxx>
 #include <officecfg/Office/Impress.hxx>
 #include <sfx2/lokhelper.hxx>
+#include <SlideSorter.hxx>
+#include <SlideSorterViewShell.hxx>
+#include <controller/SlideSorterController.hxx>
+#include <controller/SlsClipboard.hxx>
 
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::uno;
@@ -950,6 +954,18 @@ void DrawViewShell::FuSupport(SfxRequest& rReq)
         }
         break;
 
+        case SID_PASTE_SLIDE:
+        case SID_COPY_SLIDE:
+        {
+            
sd::slidesorter::SlideSorterViewShell::GetSlideSorter(GetViewShellBase())
+                ->GetSlideSorter()
+                .GetController()
+                .FuSupport(rReq);
+            Cancel();
+            rReq.Done();
+        }
+        break;
+
         case SID_UNICODE_NOTATION_TOGGLE:
         {
             if( mpDrawView->IsTextEdit() )
diff --git a/sd/source/ui/view/sdview3.cxx b/sd/source/ui/view/sdview3.cxx
index 37455c28b1bb..3c95d40da059 100644
--- a/sd/source/ui/view/sdview3.cxx
+++ b/sd/source/ui/view/sdview3.cxx
@@ -70,7 +70,10 @@
 #include <svx/sdrhittesthelper.hxx>
 #include <svx/xbtmpit.hxx>
 #include <memory>
-
+#include <SlideSorter.hxx>
+#include <SlideSorterViewShell.hxx>
+#include <controller/SlideSorterController.hxx>
+#include <controller/SlsClipboard.hxx>
 
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::lang;
@@ -699,6 +702,16 @@ bool View::InsertData( const TransferableDataHelper& 
rDataHelper,
         }
     }
 
+    if (!bReturn && CHECK_FORMAT_TRANS(SotClipboardFormatId::EMBED_SOURCE))
+    {
+        sd::slidesorter::SlideSorter& xSlideSorter
+            = ::sd::slidesorter::SlideSorterViewShell::GetSlideSorter(
+                  mrDoc.GetDocSh()->GetViewShell()->GetViewShellBase())
+                  ->GetSlideSorter();
+        if 
(xSlideSorter.GetController().GetClipboard().PasteSlidesFromSystemClipboard())
+            return true;
+    }
+
     if(!bReturn && CHECK_FORMAT_TRANS( SotClipboardFormatId::DRAWING ))
     {
         if (std::unique_ptr<SvStream> xStm = rDataHelper.GetSotStorageStream( 
SotClipboardFormatId::DRAWING ))
diff --git a/sfx2/source/control/unoctitm.cxx b/sfx2/source/control/unoctitm.cxx
index 8dcb14d2b1ee..029cb676cbb6 100644
--- a/sfx2/source/control/unoctitm.cxx
+++ b/sfx2/source/control/unoctitm.cxx
@@ -1244,6 +1244,7 @@ const std::map<std::u16string_view, KitUnoCommand>& 
GetKitUnoCommandList()
 
         { u"Cut", { PayloadType::EnabledPayload, true } },
         { u"Copy", { PayloadType::EnabledPayload, true } },
+        { u"CopySlide", { PayloadType::EnabledPayload, true } },
         { u"Paste", { PayloadType::EnabledPayload, true } },
         { u"SelectAll", { PayloadType::EnabledPayload, true } },
         { u"InsertAnnotation", { PayloadType::EnabledPayload, true } },

Reply via email to