diff options
author | László Németh <nemeth@numbertext.org> | 2021-06-09 15:56:09 +0200 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2021-06-10 09:07:03 +0200 |
commit | 68b6004fe9df184bcbaf46dd53abfec228219df6 (patch) | |
tree | fd2cc53899adc395d0d5385f3c4d710abbdf2f6c /sw | |
parent | 2693ef720d9aaabe4fca0183f0c91ab34cf47fb4 (diff) |
tdf#141994 track changes: record insertion of images
by adding a SwRangeRedline to the anchoring point of
the image inserted with Insert->Image... or
"Insert Image" of the Standard toolbar.
Note: Only images anchored as characters can be
recorded this way, so change the default to-character
anchoring at enabled change tracking. (In other office
suites, as-character insertion is the default anchoring
for inserted images with disabled change tracking, too.)
Follow-up to commit d6322bcedc197a654abc7d64bfea8cf570f123bf
"tdf#59463 track changes: record deletion of images".
Change-Id: I593abbdb6f9f2b1a5265f112103479c1833166af
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116924
Tested-by: László Németh <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/uiwriter/data/ole2.png | bin | 0 -> 766 bytes | |||
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter2.cxx | 29 | ||||
-rw-r--r-- | sw/source/core/frmedt/fefly1.cxx | 12 | ||||
-rw-r--r-- | sw/source/uibase/wrtsh/wrtsh1.cxx | 5 |
4 files changed, 46 insertions, 0 deletions
diff --git a/sw/qa/extras/uiwriter/data/ole2.png b/sw/qa/extras/uiwriter/data/ole2.png Binary files differnew file mode 100644 index 000000000000..fdad35484e7c --- /dev/null +++ b/sw/qa/extras/uiwriter/data/ole2.png diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx index 736704b45d04..5e6cfb1fc0f4 100644 --- a/sw/qa/extras/uiwriter/uiwriter2.cxx +++ b/sw/qa/extras/uiwriter/uiwriter2.cxx @@ -26,6 +26,7 @@ #include <com/sun/star/text/XTextViewCursorSupplier.hpp> #include <com/sun/star/table/XTableRows.hpp> #include <comphelper/propertysequence.hxx> +#include <comphelper/propertyvalue.hxx> #include <comphelper/configuration.hxx> #include <LibreOfficeKit/LibreOfficeKitEnums.h> #include <i18nlangtag/languagetag.hxx> @@ -3533,6 +3534,34 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTrackImageDeletion) CPPUNIT_ASSERT_EQUAL(static_cast<SwRedlineTable::size_type>(1), rTable.size()); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTrackImageInsertion) +{ + loadURL("private:factory/swriter", nullptr); + SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get()); + SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc(); + + // turn on red-lining and show changes + IDocumentRedlineAccess& rIDRA(pDoc->getIDocumentRedlineAccess()); + + rIDRA.SetRedlineFlags(RedlineFlags::On | RedlineFlags::ShowDelete | RedlineFlags::ShowInsert); + CPPUNIT_ASSERT_MESSAGE("redlining should be on", + pDoc->getIDocumentRedlineAccess().IsRedlineOn()); + CPPUNIT_ASSERT_MESSAGE( + "redlines should be visible", + IDocumentRedlineAccess::IsShowChanges(pDoc->getIDocumentRedlineAccess().GetRedlineFlags())); + + // Insert an image with change tracking + OUString aImageURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "ole2.png"; + uno::Sequence<beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("FileName", aImageURL), + }; + dispatchCommand(mxComponent, ".uno:InsertGraphic", aArgs); + + const SwRedlineTable& rTable = rIDRA.GetRedlineTable(); + // this was 0 (missing recording of insertion of images) + CPPUNIT_ASSERT_EQUAL(static_cast<SwRedlineTable::size_type>(1), rTable.size()); +} + CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf120338) { load(DATA_DIRECTORY, "tdf120338.docx"); diff --git a/sw/source/core/frmedt/fefly1.cxx b/sw/source/core/frmedt/fefly1.cxx index 6ecb3c2c2a20..18e46f9bce47 100644 --- a/sw/source/core/frmedt/fefly1.cxx +++ b/sw/source/core/frmedt/fefly1.cxx @@ -48,6 +48,8 @@ #include <IDocumentUndoRedo.hxx> #include <IDocumentState.hxx> #include <IDocumentLayoutAccess.hxx> +#include <IDocumentRedlineAccess.hxx> +#include <redline.hxx> #include <dview.hxx> #include <dflyobj.hxx> #include <dcontact.hxx> @@ -890,6 +892,16 @@ void SwFEShell::Insert( const OUString& rGrfName, const OUString& rFltName, if( pFrame ) { + // add a redline to the anchor point at tracked insertion of picture + if ( IsRedlineOn() ) + { + SwPosition aPos(*pFormat->GetAnchor().GetContentAnchor()); + SwPaM aPaM(aPos.nNode.GetNode(), aPos.nContent.GetIndex(), + aPos.nNode.GetNode(), aPos.nContent.GetIndex() + 1); + GetDoc()->getIDocumentRedlineAccess().AppendRedline( + new SwRangeRedline( RedlineType::Insert, aPaM ), true); + } + // fdo#36681: Invalidate the content and layout to refresh // the picture anchoring properly SwPageFrame* pPageFrame = pFrame->FindPageFrameOfAnchor(); diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx b/sw/source/uibase/wrtsh/wrtsh1.cxx index b26af831754d..d32a6154146d 100644 --- a/sw/source/uibase/wrtsh/wrtsh1.cxx +++ b/sw/source/uibase/wrtsh/wrtsh1.cxx @@ -336,6 +336,11 @@ void SwWrtShell::Insert( const OUString &rPath, const OUString &rFilter, pFrameMgr->SetHeightSizeType(SwFrameSize::Fixed); } + // during change tracking, insert the image anchored as character + // (to create an SwRangeRedline on its anchor point) + if ( IsRedlineOn() && nAnchorType != RndStdIds::FLY_AS_CHAR ) + pFrameMgr->SetAnchor( RndStdIds::FLY_AS_CHAR ); + // Insert the graphic SwFEShell::Insert(rPath, rFilter, &rGrf, &pFrameMgr->GetAttrSet()); if ( bOwnMgr ) |