[Libreoffice-commits] core.git: include/LibreOfficeKit libreofficekit/source sw/inc sw/source

Tor Lillqvist tml at collabora.com
Mon Aug 29 08:06:16 UTC 2016


 include/LibreOfficeKit/LibreOfficeKitEnums.h |   23 ++++++++++++
 libreofficekit/source/gtk/lokdocview.cxx     |    6 +++
 sw/inc/redline.hxx                           |   14 ++-----
 sw/source/core/doc/docredln.cxx              |   48 +++++++++++++++++++++++----
 4 files changed, 75 insertions(+), 16 deletions(-)

New commits:
commit 8f96ab602a9e7cad1215abb693f33824a7b37679
Author: Tor Lillqvist <tml at collabora.com>
Date:   Thu Aug 25 13:58:06 2016 +0300

    Emit notification to a LibreOfficeKit client also when a redline is modified
    
    Work in progress, not all modifications to a redline record cause
    notifications yet.
    
    Change-Id: I01614cd6ede9576e9cc329889fef86342567325f

diff --git a/include/LibreOfficeKit/LibreOfficeKitEnums.h b/include/LibreOfficeKit/LibreOfficeKitEnums.h
index 0805e62..324318c 100644
--- a/include/LibreOfficeKit/LibreOfficeKitEnums.h
+++ b/include/LibreOfficeKit/LibreOfficeKitEnums.h
@@ -431,6 +431,29 @@ typedef enum
      */
     LOK_CALLBACK_REDLINE_TABLE_SIZE_CHANGED,
 
+    /**
+     * An entry in the change tracking table has been modified.
+     *
+     * The payload example:
+     * {
+     *     "redline": {
+     *         "action": "Modify",
+     *         "index": "1",
+     *         "author": "Unknown Author",
+     *         "type": "Insert",
+     *         "comment": "",
+     *         "description": "Insert 'abcd'",
+     *         "dateTime": "2016-08-18T13:13:00"
+     *     }
+     * }
+     *
+     * The format is the same as an entry of
+     * lok::Document::getCommandValues('.uno:AcceptTrackedChanges'), extra
+     * fields:
+     *
+     * - 'action' is 'Modify'.
+     */
+    LOK_CALLBACK_REDLINE_TABLE_ENTRY_MODIFIED,
 }
 LibreOfficeKitCallbackType;
 
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 694ea62..fc8d3637 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -424,6 +424,8 @@ callbackTypeToString (int nType)
         return "LOK_CALLBACK_VIEW_LOCK";
     case LOK_CALLBACK_REDLINE_TABLE_SIZE_CHANGED:
         return "LOK_CALLBACK_REDLINE_TABLE_SIZE_CHANGED";
+    case LOK_CALLBACK_REDLINE_TABLE_ENTRY_MODIFIED:
+        return "LOK_CALLBACK_REDLINE_TABLE_ENTRY_MODIFIED";
     }
     g_assert(false);
     return nullptr;
@@ -1346,6 +1348,10 @@ callback (gpointer pData)
     {
         break;
     }
+    case LOK_CALLBACK_REDLINE_TABLE_ENTRY_MODIFIED:
+    {
+        break;
+    }
     default:
         g_assert(false);
         break;
diff --git a/sw/inc/redline.hxx b/sw/inc/redline.hxx
index 0adc5c9..55d4076 100644
--- a/sw/inc/redline.hxx
+++ b/sw/inc/redline.hxx
@@ -190,6 +190,7 @@ class SW_DLLPUBLIC SwRangeRedline : public SwPaM
     void CopyToSection();
     void DelCopyOfSection(size_t nMyPos);
     void MoveFromSection(size_t nMyPos);
+    void MaybeNotifyModification();
 
 public:
     SwRangeRedline( RedlineType_t eType, const SwPaM& rPam );
@@ -211,16 +212,9 @@ public:
     bool IsVisible() const { return bIsVisible; }
     bool IsDelLastPara() const { return bDelLastPara; }
 
-    void SetStart( const SwPosition& rPos, SwPosition* pSttPtr = nullptr )
-    {
-        if( !pSttPtr ) pSttPtr = Start();
-        *pSttPtr = rPos;
-    }
-    void SetEnd( const SwPosition& rPos, SwPosition* pEndPtr = nullptr )
-    {
-        if( !pEndPtr ) pEndPtr = End();
-        *pEndPtr = rPos;
-    }
+    void SetStart( const SwPosition& rPos, SwPosition* pSttPtr = nullptr );
+    void SetEnd( const SwPosition& rPos, SwPosition* pEndPtr = nullptr );
+
     /// Do we have a valid selection?
     bool HasValidRange() const;
 
diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx
index 602b736..8a2e2be 100644
--- a/sw/source/core/doc/docredln.cxx
+++ b/sw/source/core/doc/docredln.cxx
@@ -57,6 +57,8 @@
 
 using namespace com::sun::star;
 
+enum class RedlineNotification { Add, Remove, Modify };
+
 #ifdef DBG_UTIL
 
     void sw_DebugRedline( const SwDoc* pDoc )
@@ -299,13 +301,15 @@ bool SwExtraRedlineTable::DeleteTableCellRedline( SwDoc* pDoc, const SwTableBox&
 }
 
 /// Emits LOK notification about one addition / removal of a redline item.
-static void lcl_RedlineNotification(bool bAdd, size_t nPos, SwRangeRedline* pRedline)
+static void lcl_RedlineNotification(RedlineNotification nType, size_t nPos, SwRangeRedline* pRedline)
 {
     if (!comphelper::LibreOfficeKit::isActive())
         return;
 
     boost::property_tree::ptree aRedline;
-    aRedline.put("action", (bAdd ? "Add" : "Remove"));
+    aRedline.put("action", (nType == RedlineNotification::Add ? "Add" :
+                            (nType == RedlineNotification::Remove ? "Remove" :
+                             (nType == RedlineNotification::Modify ? "Modify" : "???"))));
     aRedline.put("index", nPos);
     aRedline.put("author", pRedline->GetAuthorString(1).toUtf8().getStr());
     aRedline.put("type", SwRedlineTypeToOUString(pRedline->GetRedlineData().GetType()).toUtf8().getStr());
@@ -322,7 +326,7 @@ static void lcl_RedlineNotification(bool bAdd, size_t nPos, SwRangeRedline* pRed
     SfxViewShell* pViewShell = SfxViewShell::GetFirst();
     while (pViewShell)
     {
-        pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_REDLINE_TABLE_SIZE_CHANGED, aPayload.c_str());
+        pViewShell->libreOfficeKitViewCallback(nType == RedlineNotification::Modify ? LOK_CALLBACK_REDLINE_TABLE_ENTRY_MODIFIED : LOK_CALLBACK_REDLINE_TABLE_SIZE_CHANGED, aPayload.c_str());
         pViewShell = SfxViewShell::GetNext(*pViewShell);
     }
 }
@@ -333,7 +337,7 @@ bool SwRedlineTable::Insert( SwRangeRedline* p )
     {
         std::pair<vector_type::const_iterator, bool> rv = maVector.insert( p );
         size_t nP = rv.first - begin();
-        lcl_RedlineNotification(/*bAdd=*/true, nP, p);
+        lcl_RedlineNotification(RedlineNotification::Add, nP, p);
         p->CallDisplayFunc(nP);
         return rv.second;
     }
@@ -493,7 +497,7 @@ bool SwRedlineTable::Remove( const SwRangeRedline* p )
 
 void SwRedlineTable::Remove( sal_uInt16 nP )
 {
-    lcl_RedlineNotification(/*bAdd=*/false, nP, maVector[nP]);
+    lcl_RedlineNotification(RedlineNotification::Remove, nP, maVector[nP]);
     SwDoc* pDoc = nullptr;
     if( !nP && 1 == size() )
         pDoc = maVector.front()->GetDoc();
@@ -520,7 +524,7 @@ void SwRedlineTable::DeleteAndDestroy( sal_uInt16 nP, sal_uInt16 nL )
     size_t nCount = 0;
     for( vector_type::const_iterator it = maVector.begin() + nP; it != maVector.begin() + nP + nL; ++it )
     {
-        lcl_RedlineNotification(/*bAdd=*/false, nP + nCount, *it);
+        lcl_RedlineNotification(RedlineNotification::Remove, nP + nCount, *it);
         delete *it;
         ++nCount;
     }
@@ -940,6 +944,38 @@ SwRangeRedline::~SwRangeRedline()
     delete pRedlineData;
 }
 
+void SwRangeRedline::MaybeNotifyModification()
+{
+    if (!comphelper::LibreOfficeKit::isActive())
+        return;
+
+    const SwRedlineTable& rRedTable = GetDoc()->getIDocumentRedlineAccess().GetRedlineTable();
+    for (SwRedlineTable::size_type i = 0; i < rRedTable.size(); ++i)
+    {
+        if (rRedTable[i] == this)
+        {
+            lcl_RedlineNotification(RedlineNotification::Modify, i, this);
+            break;
+        }
+    }
+}
+
+void SwRangeRedline::SetStart( const SwPosition& rPos, SwPosition* pSttPtr )
+{
+    if( !pSttPtr ) pSttPtr = Start();
+    *pSttPtr = rPos;
+
+    MaybeNotifyModification();
+}
+
+void SwRangeRedline::SetEnd( const SwPosition& rPos, SwPosition* pEndPtr )
+{
+    if( !pEndPtr ) pEndPtr = End();
+    *pEndPtr = rPos;
+
+    MaybeNotifyModification();
+}
+
 /// Do we have a valid Selection?
 bool SwRangeRedline::HasValidRange() const
 {


More information about the Libreoffice-commits mailing list