Kaydet (Commit) dd5c9897 authored tarafından Miklos Vajna's avatar Miklos Vajna

sw: add IgnoreComments parameter to .uno:Paste

Which allows not hardcoding true for LOK.

Change-Id: I644763ba052b148fc34283e361aa02f9bba2c5ee
Reviewed-on: https://gerrit.libreoffice.org/72832Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.com>
Tested-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
üst ebbcb090
......@@ -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()
......
......@@ -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))
{
......
......@@ -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,
......
......@@ -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
......
......@@ -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,
......
......@@ -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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment