[Libreoffice-commits] core.git: Branch 'private/mmeeks/copypaste' - desktop/qa sw/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Tue May 28 15:36:31 UTC 2019


 desktop/qa/desktop_lib/test_desktop_lib.cxx |   18 +++++++++++-------
 sw/source/uibase/dochdl/swdtflvr.cxx        |    4 +++-
 2 files changed, 14 insertions(+), 8 deletions(-)

New commits:
commit d2def7786b2a163208dc608b48c83333382e020b
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Tue May 28 14:02:47 2019 +0200
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Tue May 28 17:35:52 2019 +0200

    sw: LOK paste: don't require an object descriptor when importing ODF
    
    To avoid pasting content as OLE objects. The test is fixed up to pass,
    but the image paste part is still broken, I'll restore that in a
    follow-up commit.
    
    Change-Id: Ib9bc6ec506ba8eaa0301b311067ecbf1254ab8a7
    Reviewed-on: https://gerrit.libreoffice.org/73106
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
    Tested-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index a068137af535..78a219d5ca36 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -646,11 +646,9 @@ void DesktopLOKTest::testRichPaste()
 
     LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
 
-    OUString aFileURL;
-    createFileURL("paste.jpg", aFileURL);
-    std::ifstream aImageStream(aFileURL.toUtf8().copy(strlen("file://")).getStr());
-    std::vector<char> aImageContents((std::istreambuf_iterator<char>(aImageStream)), std::istreambuf_iterator<char>());
-    CPPUNIT_ASSERT(pDocument->pClass->paste(pDocument, "image/jpeg", aImageContents.data(), aImageContents.size()));
+    pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYINPUT, 't', 0);
+    pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYUP, 't', 0);
+    Scheduler::ProcessEventsToIdle();
 
     pDocument->pClass->postUnoCommand(pDocument, ".uno:SelectAll", nullptr, false);
     Scheduler::ProcessEventsToIdle();
@@ -663,10 +661,16 @@ void DesktopLOKTest::testRichPaste()
     CPPUNIT_ASSERT(pData != nullptr);
     CPPUNIT_ASSERT(pUsedMime && !strcmp(pUsedMime, pMadMime));
 
+    closeDoc();
+
     LibLODocument_Impl* pDocument2 = loadDoc("blank_text.odt");
-    CPPUNIT_ASSERT(pDocument->pClass->paste(pDocument2, pMadMime, pData, nSize));
+    CPPUNIT_ASSERT(pDocument2->pClass->paste(pDocument2, pMadMime, pData, nSize));
 
-    // FIXME: validate the paste actually occurred: which is the problem ...
+    uno::Reference<text::XTextDocument> xDocument(mxComponent, uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xDocument.is());
+    uno::Reference<text::XText> xText = xDocument->getText();
+    CPPUNIT_ASSERT(xText.is());
+    CPPUNIT_ASSERT_EQUAL(OUString("t"), xText->getString());
 }
 
 void DesktopLOKTest::testUndoWriter()
diff --git a/sw/source/uibase/dochdl/swdtflvr.cxx b/sw/source/uibase/dochdl/swdtflvr.cxx
index 1a2de3a86a9c..eb320d8cc4d5 100644
--- a/sw/source/uibase/dochdl/swdtflvr.cxx
+++ b/sw/source/uibase/dochdl/swdtflvr.cxx
@@ -1765,8 +1765,10 @@ bool SwTransferable::PasteOLE( TransferableDataHelper& rData, SwWrtShell& rSh,
     SotClipboardFormatId nId;
     if( rData.HasFormat( SotClipboardFormatId::EMBEDDED_OBJ ) )
         nId = SotClipboardFormatId::EMBEDDED_OBJ;
+    // LOK case: the clipboard only has the ODF content, no object description: still paste it using
+    // the ODF import, not as an OLE object.
     else if( rData.HasFormat( SotClipboardFormatId::EMBED_SOURCE ) &&
-             rData.HasFormat( SotClipboardFormatId::OBJECTDESCRIPTOR ))
+             (comphelper::LibreOfficeKit::isActive() || rData.HasFormat( SotClipboardFormatId::OBJECTDESCRIPTOR )))
         nId = SotClipboardFormatId::EMBED_SOURCE;
     else
         nId = SotClipboardFormatId::NONE;


More information about the Libreoffice-commits mailing list