[Libreoffice-commits] core.git: desktop/qa desktop/source sfx2/sdi sw/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Thu May 23 11:42:48 UTC 2019


 desktop/qa/desktop_lib/test_desktop_lib.cxx |   18 ++++++++++++++++++
 desktop/source/lib/init.cxx                 |    1 +
 sfx2/sdi/sfx.sdi                            |    2 +-
 sw/source/uibase/dochdl/swdtflvr.cxx        |   15 ++++++++++-----
 sw/source/uibase/inc/swdtflvr.hxx           |    5 +++--
 sw/source/uibase/shells/basesh.cxx          |   10 +++++++---
 6 files changed, 40 insertions(+), 11 deletions(-)

New commits:
commit dd5c9897c4930cb30bd8e5d6a0018b9515970111
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Thu May 23 13:06:54 2019 +0200
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Thu May 23 13:41:39 2019 +0200

    sw: add IgnoreComments parameter to .uno:Paste
    
    Which allows not hardcoding true for LOK.
    
    Change-Id: I644763ba052b148fc34283e361aa02f9bba2c5ee
    Reviewed-on: https://gerrit.libreoffice.org/72832
    Reviewed-by: Miklos Vajna <vmiklos 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 d57ae546c7de..280e0336f8bb 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -586,6 +586,24 @@ void DesktopLOKTest::testPasteWriter()
     CPPUNIT_ASSERT(!pDocument->pClass->paste(pDocument, "textt/plain;charset=utf-8", aText.getStr(), aText.getLength()));
     // Writer is expected to support text/html.
     CPPUNIT_ASSERT(pDocument->pClass->paste(pDocument, "text/html", aText.getStr(), aText.getLength()));
+
+    // Overwrite doc contents with a HTML paste.
+    pDocument->pClass->postUnoCommand(pDocument, ".uno:SelectAll", nullptr, false);
+    Scheduler::ProcessEventsToIdle();
+    OString aComment("foo <!-- bar --> baz");
+    CPPUNIT_ASSERT(pDocument->pClass->paste(pDocument, "text/html", aComment.getStr(), aComment.getLength()));
+
+    // Check if we have a comment.
+    uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
+    uno::Reference<container::XEnumerationAccess> xParagraphEnumerationAccess(xTextDocument->getText(), uno::UNO_QUERY);
+    uno::Reference<container::XEnumeration> xParagraphEnumeration = xParagraphEnumerationAccess->createEnumeration();
+    uno::Reference<container::XEnumerationAccess> xParagraph(xParagraphEnumeration->nextElement(), uno::UNO_QUERY);
+    uno::Reference<container::XEnumeration> xTextPortionEnumeration = xParagraph->createEnumeration();
+    uno::Reference<beans::XPropertySet> xTextPortion(xTextPortionEnumeration->nextElement(), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString("Text"), xTextPortion->getPropertyValue("TextPortionType").get<OUString>());
+    // Without the accompanying fix in place, this test would have failed, as we had a comment
+    // between "foo" and "baz".
+    CPPUNIT_ASSERT(!xTextPortionEnumeration->hasMoreElements());
 }
 
 void DesktopLOKTest::testPasteWriterJPEG()
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 646505603311..755d980139a2 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -3295,6 +3295,7 @@ static bool doc_paste(LibreOfficeKitDocument* pThis, const char* pMimeType, cons
     uno::Sequence<beans::PropertyValue> aPropertyValues(comphelper::InitPropertySequence(
     {
         {"AnchorType", uno::makeAny(static_cast<sal_uInt16>(text::TextContentAnchorType_AS_CHARACTER))},
+        {"IgnoreComments", uno::makeAny(true)},
     }));
     if (!comphelper::dispatchCommand(".uno:Paste", aPropertyValues))
     {
diff --git a/sfx2/sdi/sfx.sdi b/sfx2/sdi/sfx.sdi
index d3e1157d96e2..3d8cade70309 100644
--- a/sfx2/sdi/sfx.sdi
+++ b/sfx2/sdi/sfx.sdi
@@ -3022,7 +3022,7 @@ SfxTemplateItem ParaStyle SID_STYLE_FAMILY2
 
 
 SfxVoidItem Paste SID_PASTE
-(SfxUInt16Item AnchorType FN_PARAM_1)
+(SfxUInt16Item AnchorType FN_PARAM_1, SfxBoolItem IgnoreComments FN_PARAM_2)
 [
     AutoUpdate = FALSE,
     FastCall = TRUE,
diff --git a/sw/source/uibase/dochdl/swdtflvr.cxx b/sw/source/uibase/dochdl/swdtflvr.cxx
index 6912152d8f56..e5e71a251629 100644
--- a/sw/source/uibase/dochdl/swdtflvr.cxx
+++ b/sw/source/uibase/dochdl/swdtflvr.cxx
@@ -1249,7 +1249,7 @@ bool SwTransferable::IsPaste( const SwWrtShell& rSh,
     return bIsPaste;
 }
 
-bool SwTransferable::Paste(SwWrtShell& rSh, TransferableDataHelper& rData, RndStdIds nAnchorType)
+bool SwTransferable::Paste(SwWrtShell& rSh, TransferableDataHelper& rData, RndStdIds nAnchorType, bool bIgnoreComments)
 {
     SwPasteContext aPasteContext(rSh);
 
@@ -1321,7 +1321,7 @@ bool SwTransferable::Paste(SwWrtShell& rSh, TransferableDataHelper& rData, RndSt
                 nLevel++;
             } while (rSh.GetDoc()->IsIdxInTable(rSh.GetCursor()->GetNode()) != nullptr);
             if ( SwTransferable::PasteData( rData, rSh, EXCHG_OUT_ACTION_INSERT_STRING, nActionFlags, SotClipboardFormatId::HTML,
-                                        nDestination, false, false, nullptr, 0, false, nAnchorType, &aPasteContext ))
+                                        nDestination, false, false, nullptr, 0, false, nAnchorType, bIgnoreComments, &aPasteContext ))
             {
                 pDispatch->Execute(FN_CHAR_LEFT, SfxCallMode::SYNCHRON);
                 pDispatch->Execute(FN_TABLE_SELECT_ALL, SfxCallMode::SYNCHRON);
@@ -1354,7 +1354,7 @@ bool SwTransferable::Paste(SwWrtShell& rSh, TransferableDataHelper& rData, RndSt
 
     return EXCHG_INOUT_ACTION_NONE != nAction &&
             SwTransferable::PasteData( rData, rSh, nAction, nActionFlags, nFormat,
-                                        nDestination, false, false, nullptr, 0, false, nAnchorType, &aPasteContext );
+                                        nDestination, false, false, nullptr, 0, false, nAnchorType, bIgnoreComments, &aPasteContext );
 }
 
 bool SwTransferable::PasteData( TransferableDataHelper& rData,
@@ -1364,6 +1364,7 @@ bool SwTransferable::PasteData( TransferableDataHelper& rData,
                             bool bIsDefault,
                             const Point* pPt, sal_Int8 nDropAction,
                             bool bPasteSelection, RndStdIds nAnchorType,
+                            bool bIgnoreComments,
                             SwPasteContext* pContext )
 {
     SwWait aWait( *rSh.GetView().GetDocShell(), false );
@@ -1518,7 +1519,7 @@ bool SwTransferable::PasteData( TransferableDataHelper& rData,
             case SotClipboardFormatId::RICHTEXT:
             case SotClipboardFormatId::STRING:
                 bRet = SwTransferable::PasteFileContent( rData, rSh,
-                                                            nFormat, bMsg );
+                                                            nFormat, bMsg, bIgnoreComments );
                 break;
 
             case SotClipboardFormatId::NETSCAPE_BOOKMARK:
@@ -1798,7 +1799,7 @@ SotExchangeDest SwTransferable::GetSotDestination( const SwWrtShell& rSh )
 }
 
 bool SwTransferable::PasteFileContent( TransferableDataHelper& rData,
-                                    SwWrtShell& rSh, SotClipboardFormatId nFormat, bool bMsg )
+                                    SwWrtShell& rSh, SotClipboardFormatId nFormat, bool bMsg, bool bIgnoreComments )
 {
     const char* pResId = STR_CLPBRD_FORMAT_ERROR;
     bool bRet = false;
@@ -1870,6 +1871,10 @@ bool SwTransferable::PasteFileContent( TransferableDataHelper& rData,
         const SwPosition& rInsPos = *rSh.GetCursor()->Start();
         SwReader aReader(*pStream, OUString(), OUString(), *rSh.GetCursor());
         rSh.SaveTableBoxContent( &rInsPos );
+
+        if (bIgnoreComments)
+            pRead->SetIgnoreHTMLComments(true);
+
         if( aReader.Read( *pRead ).IsError() )
             pResId = STR_ERROR_CLPBRD_READ;
         else
diff --git a/sw/source/uibase/inc/swdtflvr.hxx b/sw/source/uibase/inc/swdtflvr.hxx
index c8015d1955c8..cf58d7e5bbed 100644
--- a/sw/source/uibase/inc/swdtflvr.hxx
+++ b/sw/source/uibase/inc/swdtflvr.hxx
@@ -97,7 +97,7 @@ class SW_DLLPUBLIC SwTransferable : public TransferableHelper
                                         SotClipboardFormatId nFormat, SotExchangeDest nDestination );
 
     static bool PasteFileContent( TransferableDataHelper&,
-                                    SwWrtShell& rSh, SotClipboardFormatId nFormat, bool bMsg );
+                                    SwWrtShell& rSh, SotClipboardFormatId nFormat, bool bMsg, bool bIgnoreComments = false );
     static bool PasteOLE( TransferableDataHelper& rData, SwWrtShell& rSh,
                             SotClipboardFormatId nFormat, SotExchangeActionFlags nActionFlags, bool bMsg );
     static bool PasteTargetURL( TransferableDataHelper& rData, SwWrtShell& rSh,
@@ -175,7 +175,7 @@ public:
 
     // paste - methods and helper methods for the paste
     static bool IsPaste( const SwWrtShell&, const TransferableDataHelper& );
-    static bool Paste( SwWrtShell&, TransferableDataHelper&, RndStdIds nAnchorType = RndStdIds::FLY_AT_PARA );
+    static bool Paste( SwWrtShell&, TransferableDataHelper&, RndStdIds nAnchorType = RndStdIds::FLY_AT_PARA, bool bIgnoreComments = false );
     static bool PasteData( TransferableDataHelper& rData,
                           SwWrtShell& rSh, sal_uInt8 nAction, SotExchangeActionFlags nActionFlags,
                           SotClipboardFormatId nFormat,
@@ -183,6 +183,7 @@ public:
                           bool bIsDefault,
                           const Point* pDDPos = nullptr, sal_Int8 nDropAction = 0,
                           bool bPasteSelection = false, RndStdIds nAnchorType = RndStdIds::FLY_AT_PARA,
+                          bool bIgnoreComments = false,
                           SwPasteContext* pContext = nullptr );
 
     static bool IsPasteSpecial( const SwWrtShell& rWrtShell,
diff --git a/sw/source/uibase/shells/basesh.cxx b/sw/source/uibase/shells/basesh.cxx
index b957769db3b7..55628c2ec0d2 100644
--- a/sw/source/uibase/shells/basesh.cxx
+++ b/sw/source/uibase/shells/basesh.cxx
@@ -286,11 +286,15 @@ void SwBaseShell::ExecClpbrd(SfxRequest &rReq)
                     // destroyed after the paste.
                     SwView* pView = &rView;
 
+                    RndStdIds nAnchorType = RndStdIds::FLY_AT_PARA;
                     const SfxUInt16Item* pAnchorType = rReq.GetArg<SfxUInt16Item>(FN_PARAM_1);
                     if (pAnchorType)
-                        SwTransferable::Paste(rSh, aDataHelper, static_cast<RndStdIds>(pAnchorType->GetValue()));
-                    else
-                        SwTransferable::Paste(rSh, aDataHelper);
+                        nAnchorType = static_cast<RndStdIds>(pAnchorType->GetValue());
+                    bool bIgnoreComments = false;
+                    const SfxBoolItem* pIgnoreComments = rReq.GetArg<SfxBoolItem>(FN_PARAM_2);
+                    if (pIgnoreComments)
+                        bIgnoreComments = pIgnoreComments->GetValue();
+                    SwTransferable::Paste(rSh, aDataHelper, nAnchorType, bIgnoreComments);
 
                     if( rSh.IsFrameSelected() || rSh.IsObjSelected() )
                         rSh.EnterSelFrameMode();


More information about the Libreoffice-commits mailing list