diff options
author | Pranav Kant <pranavk@collabora.co.uk> | 2017-03-16 19:33:48 +0530 |
---|---|---|
committer | Pranav Kant <pranavk@collabora.co.uk> | 2017-03-23 20:35:13 +0530 |
commit | f20bb20f8e1147d8ea1b93ee6dc216722461d456 (patch) | |
tree | e7cca67540fe12bceb099bae63bd9f5bd6edbb46 /sw | |
parent | d33b3b16ec076deab72d9b5802d0a874cc23cfb6 (diff) |
sw lok: Use unique redline identifier, instead of array indices
Use a static integer counter as identifier to each redline
Change few unit-tets that was testing redlines by using a hardcoded array
index. Instead use these unique redline identifiers now.
(cherry picked from commit fe3007b013ac74760a6377387bebd15dbd23420f)
Conflicts:
sw/inc/docary.hxx
sw/source/core/doc/docredln.cxx
sw/source/uibase/uiview/view2.cxx
Change-Id: I63aec3fc8ab10d0dad0c936600d16e96999a2bcd
Diffstat (limited to 'sw')
-rw-r--r-- | sw/inc/docary.hxx | 2 | ||||
-rw-r--r-- | sw/inc/redline.hxx | 6 | ||||
-rw-r--r-- | sw/qa/extras/tiledrendering/tiledrendering.cxx | 33 | ||||
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter.cxx | 9 | ||||
-rw-r--r-- | sw/sdi/swriter.sdi | 8 | ||||
-rw-r--r-- | sw/source/core/doc/docredln.cxx | 28 | ||||
-rw-r--r-- | sw/source/core/txtnode/ndtxt.cxx | 4 | ||||
-rw-r--r-- | sw/source/uibase/shells/textfld.cxx | 15 | ||||
-rw-r--r-- | sw/source/uibase/uiview/view2.cxx | 32 | ||||
-rw-r--r-- | sw/source/uibase/uno/unotxdoc.cxx | 2 |
10 files changed, 95 insertions, 44 deletions
diff --git a/sw/inc/docary.hxx b/sw/inc/docary.hxx index 8efe46f59ce5..a3e727435213 100644 --- a/sw/inc/docary.hxx +++ b/sw/inc/docary.hxx @@ -365,7 +365,7 @@ public: void Resort() { maVector.Resort(); } // Notifies all LOK clients when redliens are added/modified/removed - static void LOKRedlineNotification(RedlineNotification eType, SwRedlineTable::size_type nPos, SwRangeRedline* pRedline); + static void LOKRedlineNotification(RedlineNotification eType, SwRangeRedline* pRedline); }; /// Table that holds 'extra' redlines, such as 'table row insert\delete', 'paragraph moves' etc... diff --git a/sw/inc/redline.hxx b/sw/inc/redline.hxx index fe55dd657452..f31be5704738 100644 --- a/sw/inc/redline.hxx +++ b/sw/inc/redline.hxx @@ -171,6 +171,7 @@ class SW_DLLPUBLIC SwRangeRedline : public SwPaM SwNodeIndex* pContentSect; bool bDelLastPara : 1; bool bIsVisible : 1; + sal_uInt32 m_nId; void MoveToSection(); void CopyToSection(); @@ -178,6 +179,8 @@ class SW_DLLPUBLIC SwRangeRedline : public SwPaM void MoveFromSection(size_t nMyPos); public: + static sal_uInt32 m_nLastId; + SwRangeRedline( RedlineType_t eType, const SwPaM& rPam ); SwRangeRedline( const SwRedlineData& rData, const SwPaM& rPam ); SwRangeRedline( const SwRedlineData& rData, const SwPosition& rPos ); @@ -185,11 +188,12 @@ public: SwRangeRedline(SwRedlineData* pData, const SwPosition& rPos, bool bDelLP) : SwPaM( rPos ), pRedlineData( pData ), pContentSect( nullptr ), - bDelLastPara( bDelLP ), bIsVisible( true ) + bDelLastPara( bDelLP ), bIsVisible( true ), m_nId( m_nLastId++ ) {} SwRangeRedline( const SwRangeRedline& ); virtual ~SwRangeRedline() override; + sal_uInt32 GetId() const { return m_nId; } SwNodeIndex* GetContentIdx() const { return pContentSect; } // For Undo. void SetContentIdx( const SwNodeIndex* ); diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index 25e7bef09105..f12d53f26fee 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -31,6 +31,8 @@ #include <cmdid.h> #include <sfx2/viewsh.hxx> #include <sfx2/lokhelper.hxx> +#include <redline.hxx> +#include <IDocumentRedlineAccess.hxx> static const char* DATA_DIRECTORY = "/sw/qa/extras/tiledrendering/data/"; @@ -651,6 +653,10 @@ public: bool m_bViewLock; /// Set if any callback was invoked. bool m_bCalled; + /// Redline table size changed payload + boost::property_tree::ptree m_aRedlineTableChanged; + /// Redline table modified payload + boost::property_tree::ptree m_aRedlineTableModified; ViewCallback() : m_bOwnCursorInvalidated(false), @@ -757,6 +763,22 @@ public: m_bViewLock = aTree.get_child("rectangle").get_value<std::string>() != "EMPTY"; } break; + case LOK_CALLBACK_REDLINE_TABLE_SIZE_CHANGED: + { + m_aRedlineTableChanged.clear(); + std::stringstream aStream(pPayload); + boost::property_tree::read_json(aStream, m_aRedlineTableChanged); + m_aRedlineTableChanged = m_aRedlineTableChanged.get_child("redline"); + } + break; + case LOK_CALLBACK_REDLINE_TABLE_ENTRY_MODIFIED: + { + m_aRedlineTableModified.clear(); + std::stringstream aStream(pPayload); + boost::property_tree::read_json(aStream, m_aRedlineTableModified); + m_aRedlineTableModified = m_aRedlineTableModified.get_child("redline"); + } + break; } } }; @@ -1307,15 +1329,22 @@ void SwTiledRenderingTest::testTrackChanges() // Turn on trak changes, type "zzz" at the end, and move to the start. uno::Reference<beans::XPropertySet> xPropertySet(mxComponent, uno::UNO_QUERY); xPropertySet->setPropertyValue("RecordChanges", uno::makeAny(true)); + ViewCallback aView; SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell(); + pWrtShell->GetSfxViewShell()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView); pWrtShell->EndDoc(); pWrtShell->Insert("zzz"); pWrtShell->SttDoc(); - // Reject the change by index, while the cursor does not cover the tracked change. + // Get the redline just created + const SwRedlineTable& rTable = pWrtShell->GetDoc()->getIDocumentRedlineAccess().GetRedlineTable(); + CPPUNIT_ASSERT_EQUAL(static_cast<SwRedlineTable::size_type>(1), rTable.size()); + SwRangeRedline* pRedline = rTable[0]; + + // Reject the change by id, while the cursor does not cover the tracked change. uno::Sequence<beans::PropertyValue> aPropertyValues(comphelper::InitPropertySequence( { - {"RejectTrackedChange", uno::makeAny(static_cast<sal_uInt16>(0))} + {"RejectTrackedChange", uno::makeAny(static_cast<sal_uInt16>(pRedline->GetId()))} })); comphelper::dispatchCommand(".uno:RejectTrackedChange", aPropertyValues); Scheduler::ProcessEventsToIdle(); diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx index aec74fa044c5..b345380cf44d 100644 --- a/sw/qa/extras/uiwriter/uiwriter.cxx +++ b/sw/qa/extras/uiwriter/uiwriter.cxx @@ -3896,11 +3896,14 @@ void SwUiWriterTest::testRedlineParam() pWrtShell->EndDoc(); pWrtShell->Insert("zzz"); + const SwRedlineTable& rTable = pDoc->getIDocumentRedlineAccess().GetRedlineTable(); + CPPUNIT_ASSERT_EQUAL(static_cast<SwRedlineTable::size_type>(2), rTable.size()); + // Select the first redline. pWrtShell->SttDoc(); uno::Sequence<beans::PropertyValue> aPropertyValues(comphelper::InitPropertySequence( { - {"NextTrackedChange", uno::makeAny(static_cast<sal_uInt16>(0))} + {"NextTrackedChange", uno::makeAny(static_cast<sal_uInt16>(rTable[0]->GetId()))} })); lcl_dispatchCommand(mxComponent, ".uno:NextTrackedChange", aPropertyValues); Scheduler::ProcessEventsToIdle(); @@ -3913,7 +3916,7 @@ void SwUiWriterTest::testRedlineParam() pWrtShell->SttDoc(); aPropertyValues = comphelper::InitPropertySequence( { - {"NextTrackedChange", uno::makeAny(static_cast<sal_uInt16>(1))} + {"NextTrackedChange", uno::makeAny(static_cast<sal_uInt16>(rTable[1]->GetId()))} }); lcl_dispatchCommand(mxComponent, ".uno:NextTrackedChange", aPropertyValues); Scheduler::ProcessEventsToIdle(); @@ -3924,7 +3927,7 @@ void SwUiWriterTest::testRedlineParam() pWrtShell->SttDoc(); aPropertyValues = comphelper::InitPropertySequence( { - {"RejectTrackedChange", uno::makeAny(static_cast<sal_uInt16>(1))} + {"RejectTrackedChange", uno::makeAny(static_cast<sal_uInt16>(rTable[1]->GetId()))} }); lcl_dispatchCommand(mxComponent, ".uno:RejectTrackedChange", aPropertyValues); Scheduler::ProcessEventsToIdle(); diff --git a/sw/sdi/swriter.sdi b/sw/sdi/swriter.sdi index aef5641d26c0..3226f27b24b3 100644 --- a/sw/sdi/swriter.sdi +++ b/sw/sdi/swriter.sdi @@ -663,7 +663,7 @@ SfxVoidItem ClosePreview FN_CLOSE_PAGEPREVIEW ] SfxVoidItem CommentChangeTracking FN_REDLINE_COMMENT -(SfxUInt16Item ChangeTrackingId FN_REDLINE_COMMENT,SvxPostItTextItem Text SID_ATTR_POSTIT_TEXT) +(SfxUInt32Item ChangeTrackingId FN_REDLINE_COMMENT,SvxPostItTextItem Text SID_ATTR_POSTIT_TEXT) [ AutoUpdate = FALSE, FastCall = FALSE, @@ -7252,7 +7252,7 @@ SfxBoolItem SpellingAndGrammarDialog FN_SPELL_GRAMMAR_DIALOG ] SfxVoidItem AcceptTrackedChange FN_REDLINE_ACCEPT_DIRECT -( SfxUInt16Item AcceptTrackedChange FN_REDLINE_ACCEPT_DIRECT ) +( SfxUInt32Item AcceptTrackedChange FN_REDLINE_ACCEPT_DIRECT ) [ AutoUpdate = FALSE, FastCall = FALSE, @@ -7271,7 +7271,7 @@ SfxVoidItem AcceptTrackedChange FN_REDLINE_ACCEPT_DIRECT ] SfxVoidItem RejectTrackedChange FN_REDLINE_REJECT_DIRECT -( SfxUInt16Item RejectTrackedChange FN_REDLINE_REJECT_DIRECT ) +( SfxUInt32Item RejectTrackedChange FN_REDLINE_REJECT_DIRECT ) [ AutoUpdate = FALSE, FastCall = FALSE, @@ -7290,7 +7290,7 @@ SfxVoidItem RejectTrackedChange FN_REDLINE_REJECT_DIRECT ] SfxVoidItem NextTrackedChange FN_REDLINE_NEXT_CHANGE -( SfxUInt16Item NextTrackedChange FN_REDLINE_NEXT_CHANGE ) +( SfxUInt32Item NextTrackedChange FN_REDLINE_NEXT_CHANGE ) [ AutoUpdate = FALSE, FastCall = FALSE, diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx index 1a80bccab96a..2f18017842e6 100644 --- a/sw/source/core/doc/docredln.cxx +++ b/sw/source/core/doc/docredln.cxx @@ -302,7 +302,7 @@ bool SwExtraRedlineTable::DeleteTableCellRedline( SwDoc* pDoc, const SwTableBox& } /// Emits LOK notification about one addition / removal of a redline item. -void SwRedlineTable::LOKRedlineNotification(RedlineNotification nType, size_t nPos, SwRangeRedline* pRedline) +void SwRedlineTable::LOKRedlineNotification(RedlineNotification nType, SwRangeRedline* pRedline) { if (!comphelper::LibreOfficeKit::isActive()) return; @@ -311,7 +311,7 @@ void SwRedlineTable::LOKRedlineNotification(RedlineNotification nType, size_t nP aRedline.put("action", (nType == RedlineNotification::Add ? "Add" : (nType == RedlineNotification::Remove ? "Remove" : (nType == RedlineNotification::Modify ? "Modify" : "???")))); - aRedline.put("index", nPos); + aRedline.put("index", pRedline->GetId()); aRedline.put("author", pRedline->GetAuthorString(1).toUtf8().getStr()); aRedline.put("type", nsRedlineType_t::SwRedlineTypeToOUString(pRedline->GetRedlineData().GetType()).toUtf8().getStr()); aRedline.put("comment", pRedline->GetRedlineData().GetComment().toUtf8().getStr()); @@ -361,7 +361,7 @@ bool SwRedlineTable::Insert( SwRangeRedline* p ) { std::pair<vector_type::const_iterator, bool> rv = maVector.insert( p ); size_type nP = rv.first - begin(); - LOKRedlineNotification(RedlineNotification::Add, nP, p); + LOKRedlineNotification(RedlineNotification::Add, p); p->CallDisplayFunc(nP); return rv.second; } @@ -521,7 +521,7 @@ bool SwRedlineTable::Remove( const SwRangeRedline* p ) void SwRedlineTable::Remove( sal_uInt16 nP ) { - LOKRedlineNotification(RedlineNotification::Remove, nP, maVector[nP]); + LOKRedlineNotification(RedlineNotification::Remove, maVector[nP]); SwDoc* pDoc = nullptr; if( !nP && 1 == size() ) pDoc = maVector.front()->GetDoc(); @@ -545,12 +545,10 @@ void SwRedlineTable::DeleteAndDestroy( sal_uInt16 nP, sal_uInt16 nL ) if( !nP && nL && nL == size() ) pDoc = maVector.front()->GetDoc(); - size_t nCount = 0; for( vector_type::const_iterator it = maVector.begin() + nP; it != maVector.begin() + nP + nL; ++it ) { - LOKRedlineNotification(RedlineNotification::Remove, nP + nCount, *it); + LOKRedlineNotification(RedlineNotification::Remove, *it); delete *it; - ++nCount; } maVector.erase( maVector.begin() + nP, maVector.begin() + nP + nL ); @@ -931,10 +929,13 @@ OUString SwRedlineData::GetDescr() const return SW_RES(STR_REDLINE_INSERT + GetType()); } +sal_uInt32 SwRangeRedline::m_nLastId = 1; + SwRangeRedline::SwRangeRedline(RedlineType_t eTyp, const SwPaM& rPam ) : SwPaM( *rPam.GetMark(), *rPam.GetPoint() ), pRedlineData( new SwRedlineData( eTyp, GetDoc()->getIDocumentRedlineAccess().GetRedlineAuthor() ) ), - pContentSect( nullptr ) + pContentSect( nullptr ), + m_nId( m_nLastId++ ) { bDelLastPara = false; bIsVisible = true; @@ -945,7 +946,8 @@ SwRangeRedline::SwRangeRedline(RedlineType_t eTyp, const SwPaM& rPam ) SwRangeRedline::SwRangeRedline( const SwRedlineData& rData, const SwPaM& rPam ) : SwPaM( *rPam.GetMark(), *rPam.GetPoint() ), pRedlineData( new SwRedlineData( rData )), - pContentSect( nullptr ) + pContentSect( nullptr ), + m_nId( m_nLastId++ ) { bDelLastPara = false; bIsVisible = true; @@ -956,7 +958,8 @@ SwRangeRedline::SwRangeRedline( const SwRedlineData& rData, const SwPaM& rPam ) SwRangeRedline::SwRangeRedline( const SwRedlineData& rData, const SwPosition& rPos ) : SwPaM( rPos ), pRedlineData( new SwRedlineData( rData )), - pContentSect( nullptr ) + pContentSect( nullptr ), + m_nId( m_nLastId++ ) { bDelLastPara = false; bIsVisible = true; @@ -965,7 +968,8 @@ SwRangeRedline::SwRangeRedline( const SwRedlineData& rData, const SwPosition& rP SwRangeRedline::SwRangeRedline( const SwRangeRedline& rCpy ) : SwPaM( *rCpy.GetMark(), *rCpy.GetPoint() ), pRedlineData( new SwRedlineData( *rCpy.pRedlineData )), - pContentSect( nullptr ) + pContentSect( nullptr ), + m_nId( rCpy.m_nId ) { bDelLastPara = false; bIsVisible = true; @@ -995,7 +999,7 @@ void SwRangeRedline::MaybeNotifyModification() { if (rRedTable[i] == this) { - SwRedlineTable::LOKRedlineNotification(RedlineNotification::Modify, i, this); + SwRedlineTable::LOKRedlineNotification(RedlineNotification::Modify, this); break; } } diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx index aaffc3c57a88..97198e980e56 100644 --- a/sw/source/core/txtnode/ndtxt.cxx +++ b/sw/source/core/txtnode/ndtxt.cxx @@ -1225,12 +1225,12 @@ void SwTextNode::Update( // Redline is changed only when some change occurs before it if (nChangePos <= pRedln->Start()->nContent.GetIndex()) { - SwRedlineTable::LOKRedlineNotification(RedlineNotification::Modify, nRedlnPos, pRedln); + SwRedlineTable::LOKRedlineNotification(RedlineNotification::Modify, pRedln); } } } else if (this == &pRedln->GetPoint()->nNode.GetNode()) - SwRedlineTable::LOKRedlineNotification(RedlineNotification::Modify, nRedlnPos, pRedln); + SwRedlineTable::LOKRedlineNotification(RedlineNotification::Modify, pRedln); } } } diff --git a/sw/source/uibase/shells/textfld.cxx b/sw/source/uibase/shells/textfld.cxx index ed4224c4b7bb..3ef89aa6cd21 100644 --- a/sw/source/uibase/shells/textfld.cxx +++ b/sw/source/uibase/shells/textfld.cxx @@ -512,19 +512,14 @@ void SwTextShell::ExecField(SfxRequest &rReq) const SwRangeRedline *pRedline = rSh.GetCurrRedline(); SwDoc *pDoc = rSh.GetDoc(); - SwRedlineTable::size_type nRedline = SwRedlineTable::npos; + // If index is specified, goto and select the appropriate redline if (pArgs && pArgs->GetItemState(nSlot, false, &pItem) == SfxItemState::SET) { - //TODO: SfxUInt16Item vs. SwRedlineTable::size_type mismatch: - nRedline = static_cast<const SfxUInt16Item*>(pItem)->GetValue(); - if (nRedline == USHRT_MAX) - nRedline = SwRedlineTable::npos; - - if (nRedline != SwRedlineTable::npos) + const sal_uInt32 nChangeId = static_cast<const SfxUInt32Item*>(pItem)->GetValue(); + const SwRedlineTable& rRedlineTable = pDoc->getIDocumentRedlineAccess().GetRedlineTable(); + for (SwRedlineTable::size_type nRedline = 0; nRedline < rRedlineTable.size(); ++nRedline) { - // If index is specified, goto and select the appropriate redline - const SwRedlineTable& rTable = pDoc->getIDocumentRedlineAccess().GetRedlineTable(); - if (nRedline < rTable.size()) + if (nChangeId == rRedlineTable[nRedline]->GetId()) pRedline = rSh.GotoRedline(nRedline, true); } } diff --git a/sw/source/uibase/uiview/view2.cxx b/sw/source/uibase/uiview/view2.cxx index 8865d294597a..a9744b0b48b6 100644 --- a/sw/source/uibase/uiview/view2.cxx +++ b/sw/source/uibase/uiview/view2.cxx @@ -665,9 +665,18 @@ void SwView::Execute(SfxRequest &rReq) { SwDoc *pDoc = m_pWrtShell->GetDoc(); SwPaM *pCursor = m_pWrtShell->GetCursor(); + const SwRedlineTable& rRedlineTable = pDoc->getIDocumentRedlineAccess().GetRedlineTable(); + SwRedlineTable::size_type nRedline = SwRedlineTable::npos; sal_uInt16 nRedline = USHRT_MAX; if (pArgs && pArgs->GetItemState(nSlot, false, &pItem) == SfxItemState::SET) - nRedline = static_cast<const SfxUInt16Item*>(pItem)->GetValue(); + { + const sal_uInt32 nChangeId = static_cast<const SfxUInt32Item*>(pItem)->GetValue(); + for (SwRedlineTable::size_type i = 0; i < rRedlineTable.size(); ++i) + { + if (nChangeId == rRedlineTable[i]->GetId()) + nRedline = i; + } + } if( pCursor->HasMark() && nRedline == USHRT_MAX) { @@ -687,9 +696,9 @@ void SwView::Execute(SfxRequest &rReq) { // 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]; + + if (nRedline < rRedlineTable.size()) + pRedline = rRedlineTable[nRedline]; } else pRedline = pDoc->getIDocumentRedlineAccess().GetRedline(*pCursor->Start(), &nRedline); @@ -710,15 +719,22 @@ void SwView::Execute(SfxRequest &rReq) { // If a parameter is provided, try going to the nth change, not to // the next one. + SwDoc* pDoc = m_pWrtShell->GetDoc(); + const SwRedlineTable& rRedlineTable = pDoc->getIDocumentRedlineAccess().GetRedlineTable(); sal_uInt16 nRedline = USHRT_MAX; if (pArgs && pArgs->GetItemState(nSlot, false, &pItem) == SfxItemState::SET) - nRedline = static_cast<const SfxUInt16Item*>(pItem)->GetValue(); + { + const sal_uInt32 nChangeId = static_cast<const SfxUInt32Item*>(pItem)->GetValue(); + for (SwRedlineTable::size_type i = 0; i < rRedlineTable.size(); ++i) + { + if (nChangeId == rRedlineTable[i]->GetId()) + nRedline = i; + } + } const SwRangeRedline *pCurrent = m_pWrtShell->GetCurrRedline(); - SwDoc* pDoc = m_pWrtShell->GetDoc(); - const SwRedlineTable& rTable = pDoc->getIDocumentRedlineAccess().GetRedlineTable(); const SwRangeRedline *pNext = nullptr; - if (nRedline < rTable.size()) + if (nRedline < rRedlineTable.size()) pNext = m_pWrtShell->GotoRedline(nRedline, true); else pNext = m_pWrtShell->SelNextRedline(); diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx index bd01697d2522..7ef82e34934d 100644 --- a/sw/source/uibase/uno/unotxdoc.cxx +++ b/sw/source/uibase/uno/unotxdoc.cxx @@ -3240,7 +3240,7 @@ OUString SwXTextDocument::getTrackedChanges() for (SwRedlineTable::size_type i = 0; i < rRedlineTable.size(); ++i) { boost::property_tree::ptree aTrackedChange; - aTrackedChange.put("index", i); + aTrackedChange.put("index", rRedlineTable[i]->GetId()); aTrackedChange.put("author", rRedlineTable[i]->GetAuthorString(1).toUtf8().getStr()); aTrackedChange.put("type", nsRedlineType_t::SwRedlineTypeToOUString(rRedlineTable[i]->GetRedlineData().GetType()).toUtf8().getStr()); aTrackedChange.put("comment", rRedlineTable[i]->GetRedlineData().GetComment().toUtf8().getStr()); |