summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorLászló Németh <nemeth@numbertext.org>2021-04-26 09:33:45 +0200
committerLászló Németh <nemeth@numbertext.org>2021-04-27 16:27:39 +0200
commitd6322bcedc197a654abc7d64bfea8cf570f123bf (patch)
tree5e37e019e0b8b823658fe222a1b1d0dc05378e00 /sw
parentf6b419b8946c5fc2dafa8f4201a4c7379148f306 (diff)
tdf#59463 track changes: record deletion of images
Instead of deleting the image object without recording the deletion, delete the anchor point in the text to record the deletion, if Record Changes is enabled. Note: only images anchored as characters can be recorded this way, so change the anchor before the deletion, if needed. This less problem, than hidden, i.e. non-tracked deletion of images. Change-Id: I7e4bee82b76b4a26e6482a678a2a1ce432980271 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114671 Tested-by: Jenkins Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/extras/uiwriter/uiwriter2.cxx27
-rw-r--r--sw/source/uibase/wrtsh/delete.cxx36
2 files changed, 58 insertions, 5 deletions
diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx
index 02811994e525..7945d6aa28a8 100644
--- a/sw/qa/extras/uiwriter/uiwriter2.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter2.cxx
@@ -3157,6 +3157,33 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testImageCommentAtChar)
CPPUNIT_ASSERT_EQUAL(*pImageAnchor, rAnnotationMarkStart);
}
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTrackImageDeletion)
+{
+ // load a document with an image anchored to paragraph in it
+ SwDoc* pDoc = createDoc("image.odt");
+ SwView* pView = pDoc->GetDocShell()->GetView();
+
+ // select the image
+ pView->GetViewFrame()->GetDispatcher()->Execute(FN_CNTNT_TO_NEXT_FRAME, SfxCallMode::SYNCHRON);
+
+ // 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()));
+
+ // now delete the image with track changes
+ pView->GetViewFrame()->GetDispatcher()->Execute(SID_DELETE, SfxCallMode::SYNCHRON);
+
+ const SwRedlineTable& rTable = rIDRA.GetRedlineTable();
+ // this was 0 (missing recording of deletion 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/uibase/wrtsh/delete.cxx b/sw/source/uibase/wrtsh/delete.cxx
index 7db55f76c627..455b421db158 100644
--- a/sw/source/uibase/wrtsh/delete.cxx
+++ b/sw/source/uibase/wrtsh/delete.cxx
@@ -17,6 +17,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <cmdid.h>
#include <wrtsh.hxx>
#include <swcrsr.hxx>
#include <editeng/lrspitem.hxx>
@@ -416,30 +417,55 @@ bool SwWrtShell::DelRight()
case SelectionType::DrawObjectEditMode:
case SelectionType::DbForm:
{
+ // Group deletion of the object and its comment together
+ // (also as-character anchor conversion at track changes)
+ mxDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::EMPTY, nullptr);
+
// #108205# Remember object's position.
Point aTmpPt = GetObjRect().TopLeft();
// Remember the anchor of the selected object before deletion.
std::unique_ptr<SwPosition> pAnchor;
+ RndStdIds eAnchorId = RndStdIds::FLY_AT_PARA;
SwFlyFrame* pFly = GetSelectedFlyFrame();
if (pFly)
{
SwFrameFormat* pFormat = pFly->GetFormat();
if (pFormat)
{
- RndStdIds eAnchorId = pFormat->GetAnchor().GetAnchorId();
+ eAnchorId = pFormat->GetAnchor().GetAnchorId();
+ // as-character anchor conversion at track changes
+ if ( IsRedlineOn() && eAnchorId != RndStdIds::FLY_AS_CHAR )
+ {
+ SfxItemSet aSet(GetAttrPool(), svl::Items<RES_ANCHOR, RES_ANCHOR>{});
+ GetFlyFrameAttr(aSet);
+ SwFormatAnchor aAnch(RndStdIds::FLY_AS_CHAR);
+ aSet.Put(aAnch);
+ SetFlyFrameAttr(aSet);
+ eAnchorId = pFormat->GetAnchor().GetAnchorId();
+ }
if ((eAnchorId == RndStdIds::FLY_AS_CHAR || eAnchorId == RndStdIds::FLY_AT_CHAR)
&& pFormat->GetAnchor().GetContentAnchor())
{
pAnchor.reset(new SwPosition(*pFormat->GetAnchor().GetContentAnchor()));
+ // set cursor before the anchor point
+ if ( IsRedlineOn() )
+ *GetCurrentShellCursor().GetPoint() = *pAnchor;
}
}
}
- // Group deletion of the object and its comment together.
- mxDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::EMPTY, nullptr);
-
- DelSelectedObj();
+ // track changes: delete the anchor point of the image to record the deletion
+ if ( IsRedlineOn() && pAnchor && SelectionType::Graphic & nSelection
+ && eAnchorId == RndStdIds::FLY_AS_CHAR )
+ {
+ OpenMark();
+ SwCursorShell::Right(1, CRSR_SKIP_CHARS);
+ bRet = Delete();
+ CloseMark( bRet );
+ }
+ else
+ DelSelectedObj();
if (pAnchor)
{