[Libreoffice-commits] core.git: 2 commits - sw/inc sw/sdi sw/source

Luboš Luňák l.lunak at collabora.com
Mon Apr 28 10:21:29 PDT 2014


 sw/inc/cmdid.h                             |    2 
 sw/inc/docary.hxx                          |    9 +++
 sw/inc/editsh.hxx                          |    2 
 sw/inc/swcommands.h                        |    2 
 sw/sdi/_viewsh.sdi                         |   12 +++++
 sw/sdi/swriter.sdi                         |   50 +++++++++++++++++++++
 sw/source/core/doc/docredln.cxx            |   66 ++++++++++++++---------------
 sw/source/core/edit/edredln.cxx            |   18 +++++++
 sw/source/core/uibase/inc/redline_tmpl.hrc |   12 +++++
 sw/source/core/uibase/lingu/olmenu.cxx     |   10 +++-
 sw/source/core/uibase/uiview/view2.cxx     |   10 ++++
 sw/source/core/uibase/uiview/viewstat.cxx  |   39 +++++++++++++++++
 12 files changed, 196 insertions(+), 36 deletions(-)

New commits:
commit 4a60f9387ddd832f7c164102b76351e5e520d920
Author: Luboš Luňák <l.lunak at collabora.com>
Date:   Mon Apr 28 19:16:20 2014 +0200

    allow accepting/rejecting changes in a selection (bnc#874790)
    
    Adds 'Accept Changes'/'Reject Changes' to the RMB popup if appropriate,
    more convenient than handling them one by one.
    
    Change-Id: I4e2670aa9fdacaaaa1b7ecca36b9c150c82e2e72

diff --git a/sw/inc/cmdid.h b/sw/inc/cmdid.h
index 8f49675..721b3f4b 100644
--- a/sw/inc/cmdid.h
+++ b/sw/inc/cmdid.h
@@ -163,6 +163,8 @@
 #define FN_COPY_HYPERLINK_LOCATION   (FN_EDIT2 + 40)    /* copy hyperlink URL to clipboard */
 #define FN_REDLINE_NEXT_CHANGE       (FN_EDIT2 + 41)    /* Go to the next change */
 #define FN_REDLINE_PREV_CHANGE       (FN_EDIT2 + 42)    /* Go to the previous change */
+#define FN_REDLINE_ACCEPT_DIRECT_SELECTION (FN_EDIT2 + 43)    /* accept redlines in the selection */
+#define FN_REDLINE_REJECT_DIRECT_SELECTION (FN_EDIT2 + 44)    /* reject redlines in the selection */
 
 /*--------------------------------------------------------------------
     Region: Edit
diff --git a/sw/inc/editsh.hxx b/sw/inc/editsh.hxx
index 70c18cb..31a1b0e 100644
--- a/sw/inc/editsh.hxx
+++ b/sw/inc/editsh.hxx
@@ -890,6 +890,8 @@ public:
     const SwRangeRedline& 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.
      If not found, return USHRT_MAX. */
diff --git a/sw/inc/swcommands.h b/sw/inc/swcommands.h
index cc9bc07..aa580e3 100644
--- a/sw/inc/swcommands.h
+++ b/sw/inc/swcommands.h
@@ -122,6 +122,8 @@
 #define CMD_FN_HIDE_ALL_NOTES                       ".uno:HideAllNotes"
 #define CMD_FN_REDLINE_ACCEPT_DIRECT                ".uno:AcceptTracedChange"
 #define CMD_FN_REDLINE_REJECT_DIRECT                ".uno:RejectTracedChange"
+#define CMD_FN_REDLINE_ACCEPT_DIRECT_SELECTION      ".uno:AcceptTracedChangesInSelection"
+#define CMD_FN_REDLINE_REJECT_DIRECT_SELECTION      ".uno:RejectTracedChangesInSelection"
 #define CMD_FN_REDLINE_NEXT_CHANGE                  ".uno:NextTrackedChange"
 #define CMD_FN_REDLINE_PREV_CHANGE                  ".uno:PreviousTrackedChange"
 #define CMD_FN_REMOVE_HYPERLINK                     ".uno:RemoveHyperlink"
diff --git a/sw/sdi/_viewsh.sdi b/sw/sdi/_viewsh.sdi
index 40ec958..7c8f2ad 100644
--- a/sw/sdi/_viewsh.sdi
+++ b/sw/sdi/_viewsh.sdi
@@ -142,6 +142,18 @@ interface BaseTextEditView
         StateMethod = GetState ;
         DisableFlags="SW_DISABLE_ON_MAILBOX_EDITOR";
     ]
+    FN_REDLINE_ACCEPT_DIRECT_SELECTION
+    [
+        ExecMethod = Execute ;
+        StateMethod = GetState ;
+        DisableFlags="SW_DISABLE_ON_MAILBOX_EDITOR";
+    ]
+    FN_REDLINE_REJECT_DIRECT_SELECTION
+    [
+        ExecMethod = Execute ;
+        StateMethod = GetState ;
+        DisableFlags="SW_DISABLE_ON_MAILBOX_EDITOR";
+    ]
     FN_REDLINE_NEXT_CHANGE
     [
         ExecMethod = Execute ;
diff --git a/sw/sdi/swriter.sdi b/sw/sdi/swriter.sdi
index 9bde88a..1ddeba3 100644
--- a/sw/sdi/swriter.sdi
+++ b/sw/sdi/swriter.sdi
@@ -9823,6 +9823,56 @@ SfxVoidItem RejectTracedChange FN_REDLINE_REJECT_DIRECT
     GroupId = GID_EDIT;
 ]
 
+SfxVoidItem AcceptTracedChangeInSelection FN_REDLINE_ACCEPT_DIRECT_SELECTION
+[
+    /* flags: */
+    AutoUpdate = FALSE,
+    Cachable = Cachable,
+    FastCall = FALSE,
+    HasCoreId = FALSE,
+    HasDialog = FALSE,
+    ReadOnlyDoc = FALSE,
+    Toggle = FALSE,
+    Container = FALSE,
+    RecordAbsolute = FALSE,
+    RecordPerSet;
+    Asynchron;
+
+    Readonly = FALSE,
+
+    /* config: */
+    AccelConfig = TRUE,
+    MenuConfig = TRUE,
+    StatusBarConfig = FALSE,
+    ToolBoxConfig = TRUE,
+    GroupId = GID_EDIT;
+]
+
+SfxVoidItem RejectTracedChangeInSelection FN_REDLINE_REJECT_DIRECT_SELECTION
+[
+    /* flags: */
+    AutoUpdate = FALSE,
+    Cachable = Cachable,
+    FastCall = FALSE,
+    HasCoreId = FALSE,
+    HasDialog = FALSE,
+    ReadOnlyDoc = FALSE,
+    Toggle = FALSE,
+    Container = FALSE,
+    RecordAbsolute = FALSE,
+    RecordPerSet;
+    Asynchron;
+
+    Readonly = FALSE,
+
+    /* config: */
+    AccelConfig = TRUE,
+    MenuConfig = TRUE,
+    StatusBarConfig = FALSE,
+    ToolBoxConfig = TRUE,
+    GroupId = GID_EDIT;
+]
+
 SfxVoidItem NextTrackedChange FN_REDLINE_NEXT_CHANGE
 [
     /* flags: */
diff --git a/sw/source/core/edit/edredln.cxx b/sw/source/core/edit/edredln.cxx
index eaf4394..e0fad19 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/core/uibase/inc/redline_tmpl.hrc b/sw/source/core/uibase/inc/redline_tmpl.hrc
index 4271708..8212465 100644
--- a/sw/source/core/uibase/inc/redline_tmpl.hrc
+++ b/sw/source/core/uibase/inc/redline_tmpl.hrc
@@ -25,6 +25,18 @@
         };                                                           \
         MenuItem                                                     \
         {                                                            \
+            Identifier = FN_REDLINE_ACCEPT_DIRECT_SELECTION;         \
+            HelpId = CMD_FN_REDLINE_ACCEPT_DIRECT_SELECTION ;        \
+            Text [ en-US ] = "Accept Changes" ;                      \
+        };                                                           \
+        MenuItem                                                     \
+        {                                                            \
+            Identifier = FN_REDLINE_REJECT_DIRECT_SELECTION ;        \
+            HelpId = CMD_FN_REDLINE_REJECT_DIRECT_SELECTION ;        \
+            Text [ en-US ] = "Reject Changes" ;                      \
+        };                                                           \
+        MenuItem                                                     \
+        {                                                            \
             Identifier = FN_REDLINE_NEXT_CHANGE;                     \
             HelpId = CMD_FN_REDLINE_NEXT_CHANGE ;                    \
             Text [ en-US ] = "Next Change" ;                         \
diff --git a/sw/source/core/uibase/lingu/olmenu.cxx b/sw/source/core/uibase/lingu/olmenu.cxx
index 682df9a..8694eab 100644
--- a/sw/source/core/uibase/lingu/olmenu.cxx
+++ b/sw/source/core/uibase/lingu/olmenu.cxx
@@ -610,10 +610,12 @@ void SwSpellPopup::checkRedline()
         FN_REDLINE_ACCEPT_DIRECT,
         FN_REDLINE_REJECT_DIRECT,
         FN_REDLINE_NEXT_CHANGE,
-        FN_REDLINE_PREV_CHANGE
+        FN_REDLINE_PREV_CHANGE,
+        FN_REDLINE_ACCEPT_DIRECT_SELECTION,
+        FN_REDLINE_REJECT_DIRECT_SELECTION
     };
     SwDoc *pDoc = m_pSh->GetDoc();
-    SfxItemSet aSet(pDoc->GetAttrPool(), FN_REDLINE_ACCEPT_DIRECT, FN_REDLINE_PREV_CHANGE);
+    SfxItemSet aSet(pDoc->GetAttrPool(), FN_REDLINE_ACCEPT_DIRECT, FN_REDLINE_REJECT_DIRECT_SELECTION);
     for (size_t i = 0; i < SAL_N_ELEMENTS(pRedlineIds); ++i)
     {
         const sal_uInt16 nWhich = pRedlineIds[i];
@@ -808,7 +810,9 @@ void SwSpellPopup::Execute( sal_uInt16 nId )
         }
     }
     else if (nId == FN_REDLINE_ACCEPT_DIRECT || nId == FN_REDLINE_REJECT_DIRECT
-            || nId == FN_REDLINE_NEXT_CHANGE || nId == FN_REDLINE_PREV_CHANGE)
+            || nId == FN_REDLINE_NEXT_CHANGE || nId == FN_REDLINE_PREV_CHANGE
+            || nId == FN_REDLINE_ACCEPT_DIRECT_SELECTION
+            || nId == FN_REDLINE_REJECT_DIRECT_SELECTION)
     {
         // Let SwView::Execute() handle the redline actions.
         SfxRequest aReq(m_pSh->GetView().GetViewFrame(), nId);
diff --git a/sw/source/core/uibase/uiview/view2.cxx b/sw/source/core/uibase/uiview/view2.cxx
index 2b398ad..cf2d68a 100644
--- a/sw/source/core/uibase/uiview/view2.cxx
+++ b/sw/source/core/uibase/uiview/view2.cxx
@@ -684,6 +684,16 @@ void SwView::Execute(SfxRequest &rReq)
         }
         break;
 
+        case FN_REDLINE_ACCEPT_DIRECT_SELECTION:
+        case FN_REDLINE_REJECT_DIRECT_SELECTION:
+        {
+            if (FN_REDLINE_ACCEPT_DIRECT_SELECTION == nSlot)
+                m_pWrtShell->AcceptRedlinesInSelection();
+            else
+                m_pWrtShell->RejectRedlinesInSelection();
+        }
+        break;
+
         case FN_REDLINE_NEXT_CHANGE:
         {
             const SwRangeRedline *pCurrent = m_pWrtShell->GetCurrRedline();
diff --git a/sw/source/core/uibase/uiview/viewstat.cxx b/sw/source/core/uibase/uiview/viewstat.cxx
index aded9e1..195889b 100644
--- a/sw/source/core/uibase/uiview/viewstat.cxx
+++ b/sw/source/core/uibase/uiview/viewstat.cxx
@@ -53,6 +53,8 @@
 #include <svl/stritem.hxx>
 #include <unotools/moduleoptions.hxx>
 #include <svl/visitem.hxx>
+#include <redline.hxx>
+#include <docary.hxx>
 
 #include <cmdid.h>
 
@@ -297,6 +299,43 @@ void SwView::GetState(SfxItemSet &rSet)
                     rSet.DisableItem(nWhich);
             }
             break;
+            case FN_REDLINE_ACCEPT_DIRECT_SELECTION:
+            case FN_REDLINE_REJECT_DIRECT_SELECTION:
+            {
+                // If the selection does not contain a redline, disable
+                // accepting/rejecting changes.
+                SwDoc *pDoc = m_pWrtShell->GetDoc();
+                SwPaM *pCursor = m_pWrtShell->GetCrsr();
+                if (GetDocShell()->HasChangeRecordProtection())
+                    rSet.DisableItem(nWhich);
+                else if (!pCursor->HasMark())
+                    rSet.DisableItem(nWhich);
+                else
+                {
+                    sal_uInt16 index = 0;
+                    const SwRedlineTbl& table = pDoc->GetRedlineTbl();
+                    const SwRangeRedline* redline = table.FindAtPosition( *pCursor->Start(), index );
+                    if( redline != NULL && *redline->Start() == *pCursor->End())
+                        redline = NULL;
+                    if( redline == NULL )
+                    {
+                        for(; index < table.size(); ++index )
+                        {
+                            const SwRangeRedline* tmp = table[ index ];
+                            if( *tmp->Start() >= *pCursor->End())
+                                break;
+                            if( tmp->HasMark() && tmp->IsVisible())
+                            {
+                                redline = tmp;
+                                break;
+                            }
+                        }
+                    }
+                    if( redline == NULL )
+                        rSet.DisableItem(nWhich);
+                }
+            }
+            break;
 
             case FN_REDLINE_NEXT_CHANGE:
             case FN_REDLINE_PREV_CHANGE:
commit 160e93607f6c2c3981823b30ee981ca23d4e1a0d
Author: Luboš Luňák <l.lunak at collabora.com>
Date:   Mon Apr 28 18:03:49 2014 +0200

    move function searching for a readline directly to SwRedlineTbl
    
    It's more fun to roll one's own lcl_ function hidden somewhere, huh?
    
    Change-Id: I8cad6ff7e829a58c68098bff23bd48343c3e5b6a

diff --git a/sw/inc/docary.hxx b/sw/inc/docary.hxx
index 3269eb0..120606a 100644
--- a/sw/inc/docary.hxx
+++ b/sw/inc/docary.hxx
@@ -182,6 +182,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 SwRangeRedline* FindAtPosition( const SwPosition& startPosition, sal_uInt16& tableIndex, bool next = true ) const;
+
     using _SwRedlineTbl::size;
     using _SwRedlineTbl::operator[];
     using _SwRedlineTbl::empty;
diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx
index 8dcf9ee..5b45838 100644
--- a/sw/source/core/doc/docredln.cxx
+++ b/sw/source/core/doc/docredln.cxx
@@ -2115,35 +2115,6 @@ static sal_Bool lcl_RejectRedline( SwRedlineTbl& rArr, sal_uInt16& rPos,
     return bRet;
 }
 
-static const SwRangeRedline* lcl_FindCurrRedline( const SwPosition& rSttPos,
-                                        sal_uInt16& rPos,
-                                        bool bNext = true )
-{
-    const SwRangeRedline* pFnd = 0;
-    const SwRedlineTbl& rArr = rSttPos.nNode.GetNode().GetDoc()->GetRedlineTbl();
-    for( ; rPos < rArr.size() ; ++rPos )
-    {
-        const SwRangeRedline* 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)
@@ -2154,7 +2125,7 @@ static int lcl_AcceptRejectRedl( Fn_AcceptReject fn_AcceptReject,
     const SwPosition* pStt = rPam.Start(),
                     * pEnd = pStt == rPam.GetPoint() ? rPam.GetMark()
                                                      : rPam.GetPoint();
-    const SwRangeRedline* pFnd = lcl_FindCurrRedline( *pStt, n, true );
+    const SwRangeRedline* pFnd = rArr.FindAtPosition( *pStt, n, true );
     if( pFnd &&     // Is new a part of it?
         ( *pFnd->Start() != *pStt || *pFnd->End() > *pEnd ))
     {
@@ -2466,7 +2437,7 @@ const SwRangeRedline* SwDoc::SelNextRedline( SwPaM& rPam ) const
     // If the starting position points to the last valid ContentNode,
     // we take the next Redline in any case.
     sal_uInt16 n = 0;
-    const SwRangeRedline* pFnd = lcl_FindCurrRedline( rSttPos, n, true );
+    const SwRangeRedline* pFnd = GetRedlineTbl().FindAtPosition( rSttPos, n, true );
     if( pFnd )
     {
         const SwPosition* pEnd = pFnd->End();
@@ -2585,7 +2556,7 @@ const SwRangeRedline* SwDoc::SelPrevRedline( SwPaM& rPam ) const
     // If the starting position points to the last valid ContentNode,
     // we take the previous Redline in any case.
     sal_uInt16 n = 0;
-    const SwRangeRedline* pFnd = lcl_FindCurrRedline( rSttPos, n, false );
+    const SwRangeRedline* pFnd = GetRedlineTbl().FindAtPosition( rSttPos, n, false );
     if( pFnd )
     {
         const SwPosition* pStt = pFnd->Start();
@@ -2702,7 +2673,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 )
         {
@@ -3042,6 +3013,35 @@ sal_uInt16 SwRedlineTbl::FindPrevSeqNo( sal_uInt16 nSeqNo, sal_uInt16 nSttPos,
     return nRet;
 }
 
+const SwRangeRedline* SwRedlineTbl::FindAtPosition( const SwPosition& rSttPos,
+                                        sal_uInt16& rPos,
+                                        bool bNext ) const
+{
+    const SwRangeRedline* pFnd = 0;
+    for( ; rPos < size() ; ++rPos )
+    {
+        const SwRangeRedline* 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()
 {
 }


More information about the Libreoffice-commits mailing list