summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2016-08-17 15:40:14 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2016-08-17 14:59:37 +0000
commit087b71f423cf6c047137fb1316527132bb47fc05 (patch)
tree5737058d8db999eb20fa2b9c4674fe627954925d /sw
parentf2033c28f4ddb5984fc9b2374486f229f296d5f6 (diff)
sw: allow accept/reject of redline by index
Previously .uno:AcceptTrackedChange / .uno:RejectTrackedChange always worked by cursor position, but redlines are stored in the redline table, so they have a unique index. Allow specifying that index when invoking the command, and in that case ignore the cursor position. The index is not stable after an insertion / deletion. Change-Id: I493a22e84800ded224fb6b9c61261744dc0fb64f Reviewed-on: https://gerrit.libreoffice.org/28192 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk> Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/extras/uiwriter/uiwriter.cxx33
-rw-r--r--sw/sdi/swriter.sdi2
-rw-r--r--sw/source/uibase/uiview/view2.cxx20
3 files changed, 52 insertions, 3 deletions
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index a835533a0032..c0fa9e23e8f5 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -202,6 +202,7 @@ public:
void testTdf84695();
void testTdf84695NormalChar();
void testTableStyleUndo();
+ void testRedlineParam();
CPPUNIT_TEST_SUITE(SwUiWriterTest);
CPPUNIT_TEST(testReplaceForward);
@@ -305,6 +306,7 @@ public:
CPPUNIT_TEST(testTdf84695);
CPPUNIT_TEST(testTdf84695NormalChar);
CPPUNIT_TEST(testTableStyleUndo);
+ CPPUNIT_TEST(testRedlineParam);
CPPUNIT_TEST_SUITE_END();
private:
@@ -3824,6 +3826,37 @@ void SwUiWriterTest::testTableStyleUndo()
CPPUNIT_ASSERT(pStyle->GetBoxFormat(0).GetBackground() == aBackground2);
}
+void SwUiWriterTest::testRedlineParam()
+{
+ // Create a document with minimal content.
+ SwDoc* pDoc = createDoc();
+ SwDocShell* pDocShell = pDoc->GetDocShell();
+ SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
+ pWrtShell->Insert("middle");
+
+ // Turn on track changes, and add changes to the start and end of the document.
+ uno::Reference<beans::XPropertySet> xPropertySet(mxComponent, uno::UNO_QUERY);
+ xPropertySet->setPropertyValue("RecordChanges", uno::makeAny(true));
+ pWrtShell->SttDoc();
+ pWrtShell->Insert("aaa");
+ pWrtShell->EndDoc();
+ pWrtShell->Insert("zzz");
+
+ // Move the cursor to the start again, and reject the second change.
+ pWrtShell->SttDoc();
+ uno::Sequence<beans::PropertyValue> aPropertyValues(comphelper::InitPropertySequence(
+ {
+ {"RejectTrackedChange", uno::makeAny(static_cast<sal_uInt16>(1))}
+ }));
+ lcl_dispatchCommand(mxComponent, ".uno:RejectTrackedChange", aPropertyValues);
+ Scheduler::ProcessEventsToIdle();
+ SwShellCursor* pShellCursor = pWrtShell->getShellCursor(false);
+
+ // This was 'middlezzz', the uno command rejected the redline under the
+ // cursor, instead of the requested one.
+ CPPUNIT_ASSERT_EQUAL(OUString("aaamiddle"), pShellCursor->GetPoint()->nNode.GetNode().GetTextNode()->GetText());
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/sdi/swriter.sdi b/sw/sdi/swriter.sdi
index 6c7aa8812ace..94a6e0f00eae 100644
--- a/sw/sdi/swriter.sdi
+++ b/sw/sdi/swriter.sdi
@@ -7273,6 +7273,7 @@ SfxBoolItem SpellingAndGrammarDialog FN_SPELL_GRAMMAR_DIALOG
]
SfxVoidItem AcceptTrackedChange FN_REDLINE_ACCEPT_DIRECT
+( SfxUInt16Item AcceptTrackedChange FN_REDLINE_ACCEPT_DIRECT )
[
AutoUpdate = FALSE,
FastCall = FALSE,
@@ -7291,6 +7292,7 @@ SfxVoidItem AcceptTrackedChange FN_REDLINE_ACCEPT_DIRECT
]
SfxVoidItem RejectTrackedChange FN_REDLINE_REJECT_DIRECT
+( SfxUInt16Item RejectTrackedChange FN_REDLINE_REJECT_DIRECT )
[
AutoUpdate = FALSE,
FastCall = FALSE,
diff --git a/sw/source/uibase/uiview/view2.cxx b/sw/source/uibase/uiview/view2.cxx
index 060bf5a7b3b5..2f6b28f56b46 100644
--- a/sw/source/uibase/uiview/view2.cxx
+++ b/sw/source/uibase/uiview/view2.cxx
@@ -664,7 +664,11 @@ void SwView::Execute(SfxRequest &rReq)
{
SwDoc *pDoc = m_pWrtShell->GetDoc();
SwPaM *pCursor = m_pWrtShell->GetCursor();
- if( pCursor->HasMark())
+ sal_uInt16 nRedline = USHRT_MAX;
+ if (pArgs && pArgs->GetItemState(nSlot, false, &pItem) == SfxItemState::SET)
+ nRedline = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
+
+ if( pCursor->HasMark() && nRedline == USHRT_MAX)
{
if (FN_REDLINE_ACCEPT_DIRECT == nSlot)
m_pWrtShell->AcceptRedlinesInSelection();
@@ -677,8 +681,18 @@ void SwView::Execute(SfxRequest &rReq)
// This ensures we work properly with FN_REDLINE_NEXT_CHANGE, which leaves the
// point at the *end* of the redline and the mark at the start (so GetRedline
// would return NULL if called on the point)
- sal_uInt16 nRedline = 0;
- const SwRangeRedline *pRedline = pDoc->getIDocumentRedlineAccess().GetRedline(*pCursor->Start(), &nRedline);
+ const SwRangeRedline* pRedline = nullptr;
+ if (nRedline < USHRT_MAX)
+ {
+ // A redline was explicitly requested by specifying an
+ // index, don't guess based on the cursor position.
+ const SwRedlineTable& rTable = pDoc->getIDocumentRedlineAccess().GetRedlineTable();
+ if (nRedline < rTable.size())
+ pRedline = rTable[nRedline];
+ }
+ else
+ pRedline = pDoc->getIDocumentRedlineAccess().GetRedline(*pCursor->Start(), &nRedline);
+
assert(pRedline != nullptr);
if (pRedline)
{