diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2014-04-28 18:03:49 +0200 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2014-04-30 14:57:04 +0200 |
commit | 44666ffdffc559efed0ce0822200aeb6b15059dd (patch) | |
tree | f6ef8a68f9d135f3e71a55cd4211228a38414ccc | |
parent | 069d771bf0ffd9693a29ccf33323b266d46c856a (diff) |
allow accepting/rejecting changes in a selection (bnc#874790)
More convenient than handling them one by one.
(cherry picked from commit 160e93607f6c2c3981823b30ee981ca23d4e1a0d)
(cherry picked from commit 4a60f9387ddd832f7c164102b76351e5e520d920)
(cherry picked from commit 94fc0b4752599601ddf9ff3c9b49da15cffb4882)
(cherry picked from commit d46e7dabd3090697c46e24a350cc75f35c28a8f7)
Change-Id: Iee02d12d595ee41cff7a31e2bda61425c9f53d6d
Reviewed-on: https://gerrit.libreoffice.org/9198
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | sw/inc/docary.hxx | 9 | ||||
-rw-r--r-- | sw/inc/editsh.hxx | 2 | ||||
-rw-r--r-- | sw/source/core/doc/docredln.cxx | 66 | ||||
-rw-r--r-- | sw/source/core/edit/edredln.cxx | 18 | ||||
-rw-r--r-- | sw/source/ui/uiview/view2.cxx | 31 | ||||
-rw-r--r-- | sw/source/ui/uiview/viewstat.cxx | 37 |
6 files changed, 115 insertions, 48 deletions
diff --git a/sw/inc/docary.hxx b/sw/inc/docary.hxx index 4525763749a3..0f6904848081 100644 --- a/sw/inc/docary.hxx +++ b/sw/inc/docary.hxx @@ -175,6 +175,15 @@ public: sal_uInt16 FindPrevSeqNo( sal_uInt16 nSeqNo, sal_uInt16 nSttPos, sal_uInt16 nLookahead = 20 ) const; + /** + Find the redline at the given position. + + @param tableIndex position in SwRedlineTbl to start searching at, will be updated with the index of the returned + redline (or the next redline after the given position if not found) + @param next true: redline starts at position and ends after, false: redline starts before position and ends at or after + */ + const SwRedline* FindAtPosition( const SwPosition& startPosition, sal_uInt16& tableIndex, bool next = true ) const; + using _SwRedlineTbl::size; using _SwRedlineTbl::operator[]; using _SwRedlineTbl::empty; diff --git a/sw/inc/editsh.hxx b/sw/inc/editsh.hxx index 9991fd014987..159a9daaeba0 100644 --- a/sw/inc/editsh.hxx +++ b/sw/inc/editsh.hxx @@ -894,6 +894,8 @@ public: const SwRedline& GetRedline( sal_uInt16 nPos ) const; sal_Bool AcceptRedline( sal_uInt16 nPos ); sal_Bool RejectRedline( sal_uInt16 nPos ); + bool AcceptRedlinesInSelection(); + bool RejectRedlinesInSelection(); /** Search Redline for this Data and @return position in array. diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx index ee4db2620a16..a6e6367e1ac6 100644 --- a/sw/source/core/doc/docredln.cxx +++ b/sw/source/core/doc/docredln.cxx @@ -1914,35 +1914,6 @@ static sal_Bool lcl_RejectRedline( SwRedlineTbl& rArr, sal_uInt16& rPos, return bRet; } -static const SwRedline* lcl_FindCurrRedline( const SwPosition& rSttPos, - sal_uInt16& rPos, - bool bNext = true ) -{ - const SwRedline* pFnd = 0; - const SwRedlineTbl& rArr = rSttPos.nNode.GetNode().GetDoc()->GetRedlineTbl(); - for( ; rPos < rArr.size() ; ++rPos ) - { - const SwRedline* pTmp = rArr[ rPos ]; - if( pTmp->HasMark() && pTmp->IsVisible() ) - { - const SwPosition* pRStt = pTmp->Start(), - * pREnd = pRStt == pTmp->GetPoint() ? pTmp->GetMark() - : pTmp->GetPoint(); - if( bNext ? *pRStt <= rSttPos : *pRStt < rSttPos ) - { - if( bNext ? *pREnd > rSttPos : *pREnd >= rSttPos ) - { - pFnd = pTmp; - break; - } - } - else - break; - } - } - return pFnd; -} - static int lcl_AcceptRejectRedl( Fn_AcceptReject fn_AcceptReject, SwRedlineTbl& rArr, sal_Bool bCallDelete, const SwPaM& rPam) @@ -1953,7 +1924,7 @@ static int lcl_AcceptRejectRedl( Fn_AcceptReject fn_AcceptReject, const SwPosition* pStt = rPam.Start(), * pEnd = pStt == rPam.GetPoint() ? rPam.GetMark() : rPam.GetPoint(); - const SwRedline* pFnd = lcl_FindCurrRedline( *pStt, n, true ); + const SwRedline* pFnd = rArr.FindAtPosition( *pStt, n, true ); if( pFnd && // Is new a part of it? ( *pFnd->Start() != *pStt || *pFnd->End() > *pEnd )) { @@ -2257,7 +2228,7 @@ const SwRedline* SwDoc::SelNextRedline( SwPaM& rPam ) const // If the starting positon points to the last valid ContentNode, // we take the next Redline in any case. sal_uInt16 n = 0; - const SwRedline* pFnd = lcl_FindCurrRedline( rSttPos, n, true ); + const SwRedline* pFnd = GetRedlineTbl().FindAtPosition( rSttPos, n, true ); if( pFnd ) { const SwPosition* pEnd = pFnd->End(); @@ -2374,7 +2345,7 @@ const SwRedline* SwDoc::SelPrevRedline( SwPaM& rPam ) const // If the starting positon points to the last valid ContentNode, // we take the previous Redline in any case. sal_uInt16 n = 0; - const SwRedline* pFnd = lcl_FindCurrRedline( rSttPos, n, false ); + const SwRedline* pFnd = GetRedlineTbl().FindAtPosition( rSttPos, n, false ); if( pFnd ) { const SwPosition* pStt = pFnd->Start(); @@ -2489,7 +2460,7 @@ bool SwDoc::SetRedlineComment( const SwPaM& rPaM, const OUString& rS ) * pEnd = pStt == rPaM.GetPoint() ? rPaM.GetMark() : rPaM.GetPoint(); sal_uInt16 n = 0; - if( lcl_FindCurrRedline( *pStt, n, true ) ) + if( GetRedlineTbl().FindAtPosition( *pStt, n, true ) ) { for( ; n < mpRedlineTbl->size(); ++n ) { @@ -2825,6 +2796,35 @@ sal_uInt16 SwRedlineTbl::FindPrevSeqNo( sal_uInt16 nSeqNo, sal_uInt16 nSttPos, return nRet; } +const SwRedline* SwRedlineTbl::FindAtPosition( const SwPosition& rSttPos, + sal_uInt16& rPos, + bool bNext ) const +{ + const SwRedline* pFnd = 0; + for( ; rPos < size() ; ++rPos ) + { + const SwRedline* pTmp = (*this)[ rPos ]; + if( pTmp->HasMark() && pTmp->IsVisible() ) + { + const SwPosition* pRStt = pTmp->Start(), + * pREnd = pRStt == pTmp->GetPoint() ? pTmp->GetMark() + : pTmp->GetPoint(); + if( bNext ? *pRStt <= rSttPos : *pRStt < rSttPos ) + { + if( bNext ? *pREnd > rSttPos : *pREnd >= rSttPos ) + { + pFnd = pTmp; + break; + } + } + else + break; + } + } + return pFnd; +} + + SwRedlineExtraData::~SwRedlineExtraData() { } diff --git a/sw/source/core/edit/edredln.cxx b/sw/source/core/edit/edredln.cxx index 5a553614bb19..5d5ff4a90dd4 100644 --- a/sw/source/core/edit/edredln.cxx +++ b/sw/source/core/edit/edredln.cxx @@ -91,6 +91,24 @@ sal_Bool SwEditShell::RejectRedline( sal_uInt16 nPos ) return bRet; } +bool SwEditShell::AcceptRedlinesInSelection() +{ + SET_CURR_SHELL( this ); + StartAllAction(); + sal_Bool bRet = GetDoc()->AcceptRedline( *GetCrsr(), true ); + EndAllAction(); + return bRet; +} + +bool SwEditShell::RejectRedlinesInSelection() +{ + SET_CURR_SHELL( this ); + StartAllAction(); + sal_Bool bRet = GetDoc()->RejectRedline( *GetCrsr(), true ); + EndAllAction(); + return bRet; +} + // Set the comment at the Redline sal_Bool SwEditShell::SetRedlineComment( const OUString& rS ) { diff --git a/sw/source/ui/uiview/view2.cxx b/sw/source/ui/uiview/view2.cxx index 83f74d9a8949..87df3b48e898 100644 --- a/sw/source/ui/uiview/view2.cxx +++ b/sw/source/ui/uiview/view2.cxx @@ -641,22 +641,31 @@ void SwView::Execute(SfxRequest &rReq) case FN_REDLINE_ACCEPT_DIRECT: case FN_REDLINE_REJECT_DIRECT: { - // We check for a redline at the start of the selection/cursor, not the point. - // 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) SwDoc *pDoc = m_pWrtShell->GetDoc(); SwPaM *pCursor = m_pWrtShell->GetCrsr(); - - sal_uInt16 nRedline = 0; - const SwRedline *pRedline = pDoc->GetRedline(*pCursor->Start(), &nRedline); - assert(pRedline != 0); - if (pRedline) + if( pCursor->HasMark()) { if (FN_REDLINE_ACCEPT_DIRECT == nSlot) - m_pWrtShell->AcceptRedline(nRedline); + m_pWrtShell->AcceptRedlinesInSelection(); else - m_pWrtShell->RejectRedline(nRedline); + m_pWrtShell->RejectRedlinesInSelection(); + } + else + { + // We check for a redline at the start of the selection/cursor, not the point. + // 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 SwRedline *pRedline = pDoc->GetRedline(*pCursor->Start(), &nRedline); + assert(pRedline != 0); + if (pRedline) + { + if (FN_REDLINE_ACCEPT_DIRECT == nSlot) + m_pWrtShell->AcceptRedline(nRedline); + else + m_pWrtShell->RejectRedline(nRedline); + } } } break; diff --git a/sw/source/ui/uiview/viewstat.cxx b/sw/source/ui/uiview/viewstat.cxx index bbc915c4e282..0fdf9bf5670c 100644 --- a/sw/source/ui/uiview/viewstat.cxx +++ b/sw/source/ui/uiview/viewstat.cxx @@ -52,6 +52,8 @@ #include <svl/stritem.hxx> #include <unotools/moduleoptions.hxx> #include <svl/visitem.hxx> +#include <redline.hxx> +#include <docary.hxx> #include <cmdid.h> @@ -286,14 +288,41 @@ void SwView::GetState(SfxItemSet &rSet) case FN_REDLINE_ACCEPT_DIRECT: case FN_REDLINE_REJECT_DIRECT: { - // If the selection/cursor start position isn't on a redline, disable - // accepting/rejecting changes. SwDoc *pDoc = m_pWrtShell->GetDoc(); SwPaM *pCursor = m_pWrtShell->GetCrsr(); - if (0 == pDoc->GetRedline(*pCursor->Start(), 0)) - rSet.DisableItem(nWhich); if (GetDocShell()->HasChangeRecordProtection()) rSet.DisableItem(nWhich); + else if (pCursor->HasMark()) + { // If the selection does not contain redlines, disable accepting/rejecting changes. + sal_uInt16 index = 0; + const SwRedlineTbl& table = pDoc->GetRedlineTbl(); + const SwRedline* redline = table.FindAtPosition( *pCursor->Start(), index ); + if( redline != NULL && *redline->Start() == *pCursor->End()) + redline = NULL; + if( redline == NULL ) + { + for(; index < table.size(); ++index ) + { + const SwRedline* tmp = table[ index ]; + if( *tmp->Start() >= *pCursor->End()) + break; + if( tmp->HasMark() && tmp->IsVisible()) + { + redline = tmp; + break; + } + } + } + if( redline == NULL ) + rSet.DisableItem(nWhich); + } + else + { + // If the cursor position isn't on a redline, disable + // accepting/rejecting changes. + if (0 == pDoc->GetRedline(*pCursor->Start(), 0)) + rSet.DisableItem(nWhich); + } } break; |