include/LibreOfficeKit/LibreOfficeKitEnums.h        |   23 +++++++++
 libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx |   19 -------
 libreofficekit/source/gtk/lokdocview.cxx            |    6 ++
 sw/inc/redline.hxx                                  |   14 +----
 sw/qa/extras/tiledrendering/tiledrendering.cxx      |   33 +++++++++++++
 sw/qa/extras/uiwriter/uiwriter.cxx                  |    9 +++
 sw/source/core/doc/DocumentRedlineManager.cxx       |    1 
 sw/source/core/doc/docredln.cxx                     |   48 +++++++++++++++++---
 sw/source/uibase/shells/textfld.cxx                 |    7 +-
 9 files changed, 122 insertions(+), 38 deletions(-)

New commits:
commit 632ee2f56a51531b7dc462dfb3d5c180918e4013
Author: Miklos Vajna <vmik...@collabora.co.uk>
Date:   Mon Aug 29 17:57:05 2016 +0200

    sw: use SwModule::GetRedlineAuthor() in SwTextShell::ExecField()
    
    This avoids some code duplication, and also means that the redline
    author set by SwDocShell::SetView() affects the inserted Writer comments
    as well, while those were 'Unknown Author' in the LOK case.
    
    Change-Id: Ib51183302ee6904fdf69fb16f27ecfe6df39e6cb
    (cherry picked from commit e2c240627c8a1a9cea1f9eedfb064214c8e93a39)

diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx 
b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index a1833d2..5ad2059 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -137,8 +137,6 @@ public:
     std::shared_ptr<TiledRowColumnBar> m_pRowBar;
     std::shared_ptr<TiledRowColumnBar> m_pColumnBar;
     std::shared_ptr<TiledCornerButton> m_pCornerButton;
-    /// Author string, used for comment insertion.
-    std::string m_aAuthor;
     /// Rendering arguments, which are the same for all views.
     boost::property_tree::ptree m_aRenderingArguments;
 
@@ -865,7 +863,6 @@ static void createView(GtkWidget* pButton, gpointer 
/*pItem*/)
     GtkWidget* pDocView = 
lok_doc_view_new_from_widget(LOK_DOC_VIEW(rWindow.m_pDocView), 
aArguments.c_str());
 
     TiledWindow& rNewWindow = setupWidgetAndCreateWindow(pDocView);
-    rNewWindow.m_aAuthor = aAuthor;
     // Hide the unused progress bar.
     gtk_widget_show_all(rNewWindow.m_pStatusBar);
     gtk_widget_hide(rNewWindow.m_pProgressBar);
@@ -917,9 +914,8 @@ static void createModelAndView(const char* pLOPath, const 
char* pDocPath, const
     // Save rendering arguments for views which are created later.
     rWindow.m_aRenderingArguments = aTree;
 
-    rWindow.m_aAuthor = getNextAuthor();
     aTree.put(boost::property_tree::ptree::path_type(".uno:Author/type", '/'), 
"string");
-    aTree.put(boost::property_tree::ptree::path_type(".uno:Author/value", 
'/'), rWindow.m_aAuthor);
+    aTree.put(boost::property_tree::ptree::path_type(".uno:Author/value", 
'/'), getNextAuthor());
 
     std::stringstream aStream;
     boost::property_tree::write_json(aStream, aTree);
@@ -1316,18 +1312,7 @@ static void toggleToolItem(GtkWidget* pWidget, gpointer 
/*pData*/)
         // notify about the finished Save
         gboolean bNotify = (rString == ".uno:Save");
 
-        std::string aArguments;
-        if (rString == ".uno:InsertAnnotation" && !rWindow.m_aAuthor.empty())
-        {
-            boost::property_tree::ptree aTree;
-            aTree.put(boost::property_tree::ptree::path_type("Author/type", 
'/'), "string");
-            aTree.put(boost::property_tree::ptree::path_type("Author/value", 
'/'), rWindow.m_aAuthor);
-            std::stringstream aStream;
-            boost::property_tree::write_json(aStream, aTree);
-            aArguments = aStream.str();
-        }
-
-        lok_doc_view_post_command(pLOKDocView, rString.c_str(), 
(aArguments.empty() ? nullptr : aArguments.c_str()), bNotify);
+        lok_doc_view_post_command(pLOKDocView, rString.c_str(), 
/*pArguments=*/nullptr, bNotify);
     }
 }
 
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx 
b/sw/qa/extras/uiwriter/uiwriter.cxx
index edc8e6b..656eb76 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -3322,6 +3322,15 @@ void SwUiWriterTest::testRedlineViewAuthor()
     SwRangeRedline* pRedline = rTable[0];
     // This was 'Unknown Author' instead of 'A U. Thor'.
     CPPUNIT_ASSERT_EQUAL(aAuthor, pRedline->GetAuthorString());
+
+    // Insert a comment and assert that SwView::SetRedlineAuthor() affects 
this as well.
+    lcl_dispatchCommand(mxComponent, ".uno:.uno:InsertAnnotation", {});
+    uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, 
uno::UNO_QUERY);
+    uno::Reference<container::XEnumerationAccess> 
xFieldsAccess(xTextFieldsSupplier->getTextFields());
+    uno::Reference<container::XEnumeration> 
xFields(xFieldsAccess->createEnumeration());
+    uno::Reference<beans::XPropertySet> xField(xFields->nextElement(), 
uno::UNO_QUERY);
+    // This was 'Unknown Author' instead of 'A U. Thor'.
+    CPPUNIT_ASSERT_EQUAL(aAuthor, 
xField->getPropertyValue("Author").get<OUString>());
 }
 
 CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest);
diff --git a/sw/source/uibase/shells/textfld.cxx 
b/sw/source/uibase/shells/textfld.cxx
index 652f607..67ef91d 100644
--- a/sw/source/uibase/shells/textfld.cxx
+++ b/sw/source/uibase/shells/textfld.cxx
@@ -71,6 +71,7 @@
 #include <PostItMgr.hxx>
 #include <calbck.hxx>
 #include <memory>
+#include <swmodule.hxx>
 
 using namespace nsSwDocInfoSubType;
 
@@ -382,10 +383,8 @@ void SwTextShell::ExecField(SfxRequest &rReq)
                         sAuthor = pAuthorItem->GetValue();
                     else
                     {
-                        SvtUserOptions aUserOpt;
-                        if( (sAuthor = aUserOpt.GetFullName()).isEmpty())
-                            if( (sAuthor = aUserOpt.GetID()).isEmpty() )
-                                sAuthor = SW_RES( STR_REDLINE_UNKNOWN_AUTHOR );
+                        sal_uInt16 nAuthor = SW_MOD()->GetRedlineAuthor();
+                        sAuthor = SW_MOD()->GetRedlineAuthor(nAuthor);
                     }
 
                     const SvxPostItTextItem* pTextItem = 
rReq.GetArg<SvxPostItTextItem>(SID_ATTR_POSTIT_TEXT);
commit 078831670df5ed26b4b7bab4461b0abb7b465b67
Author: Miklos Vajna <vmik...@collabora.co.uk>
Date:   Mon Aug 29 12:32:51 2016 +0200

    sw lok: emit REDLINE_TABLE_ENTRY_MODIFIED when deleting self-added 
characters
    
    This doesn't work out of the box via SwRangeRedline::SetStart/End,
    because the range of the redline is adjusted when redlining is disabled
    by sw::DocumentRedlineManager::AppendRedline() when it compresses the
    insert and delete redlines into a single reduced insert redline, and
    then the redline is updated implicitly via SwIndex.
    
    Change-Id: I4b652348b256df75e4c774ea5f3fdd78f59deb01
    Reviewed-on: https://gerrit.libreoffice.org/28454
    Reviewed-by: Miklos Vajna <vmik...@collabora.co.uk>
    Tested-by: Jenkins <c...@libreoffice.org>
    (cherry picked from commit d017362bc68fe40c4bd79db76614d84aa9be913d)

diff --git a/sw/inc/redline.hxx b/sw/inc/redline.hxx
index b30e631..e51f25f 100644
--- a/sw/inc/redline.hxx
+++ b/sw/inc/redline.hxx
@@ -192,7 +192,6 @@ 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 );
@@ -289,6 +288,7 @@ public:
     bool operator==( const SwRangeRedline& ) const;
     bool operator<( const SwRangeRedline& ) const;
     void dumpAsXml(struct _xmlTextWriter* pWriter) const;
+    void MaybeNotifyModification();
 };
 
 /// Base object for 'Redlines' that are not of 'Ranged' type (like table row 
insert\delete)
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx 
b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index e5d6f24..1eda2ad 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -70,6 +70,7 @@ public:
     void testShapeTextUndoGroupShells();
     void testTrackChanges();
     void testTrackChangesCallback();
+    void testRedlineUpdateCallback();
 
     CPPUNIT_TEST_SUITE(SwTiledRenderingTest);
     CPPUNIT_TEST(testRegisterCallback);
@@ -104,6 +105,7 @@ public:
     CPPUNIT_TEST(testShapeTextUndoGroupShells);
     CPPUNIT_TEST(testTrackChanges);
     CPPUNIT_TEST(testTrackChangesCallback);
+    CPPUNIT_TEST(testRedlineUpdateCallback);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -120,6 +122,7 @@ private:
     int m_nSelectionAfterSearchResult;
     int m_nInvalidations;
     int m_nRedlineTableSizeChanged;
+    int m_nRedlineTableEntryModified;
 };
 
 SwTiledRenderingTest::SwTiledRenderingTest()
@@ -127,7 +130,8 @@ SwTiledRenderingTest::SwTiledRenderingTest()
       m_nSelectionBeforeSearchResult(0),
       m_nSelectionAfterSearchResult(0),
       m_nInvalidations(0),
-      m_nRedlineTableSizeChanged(0)
+      m_nRedlineTableSizeChanged(0),
+      m_nRedlineTableEntryModified(0)
 {
 }
 
@@ -206,6 +210,11 @@ void SwTiledRenderingTest::callbackImpl(int nType, const 
char* pPayload)
         ++m_nRedlineTableSizeChanged;
     }
     break;
+    case LOK_CALLBACK_REDLINE_TABLE_ENTRY_MODIFIED:
+    {
+        ++m_nRedlineTableEntryModified;
+    }
+    break;
     }
 }
 
@@ -1200,6 +1209,28 @@ void SwTiledRenderingTest::testTrackChangesCallback()
     comphelper::LibreOfficeKit::setActive(false);
 }
 
+void SwTiledRenderingTest::testRedlineUpdateCallback()
+{
+    // Load a document.
+    comphelper::LibreOfficeKit::setActive();
+    SwXTextDocument* pXTextDocument = createDoc("dummy.fodt");
+    SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell();
+    
pWrtShell->GetSfxViewShell()->registerLibreOfficeKitViewCallback(&SwTiledRenderingTest::callback,
 this);
+
+    // Turn on track changes, type "xx" and delete the second one.
+    uno::Reference<beans::XPropertySet> xPropertySet(mxComponent, 
uno::UNO_QUERY);
+    xPropertySet->setPropertyValue("RecordChanges", uno::makeAny(true));
+    pWrtShell->Insert("xx");
+    m_nRedlineTableEntryModified = 0;
+    pWrtShell->DelLeft();
+
+    // Assert that we get exactly one notification about the redline update.
+    // This was 0, as LOK_CALLBACK_REDLINE_TABLE_ENTRY_MODIFIED wasn't sent.
+    CPPUNIT_ASSERT_EQUAL(1, m_nRedlineTableEntryModified);
+
+    comphelper::LibreOfficeKit::setActive(false);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SwTiledRenderingTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/core/doc/DocumentRedlineManager.cxx 
b/sw/source/core/doc/DocumentRedlineManager.cxx
index 34fe092..ed98e0c 100644
--- a/sw/source/core/doc/DocumentRedlineManager.cxx
+++ b/sw/source/core/doc/DocumentRedlineManager.cxx
@@ -1215,6 +1215,7 @@ bool DocumentRedlineManager::AppendRedline( 
SwRangeRedline* pNewRedl, bool bCall
                             }
                             delete pNewRedl;
                             pNewRedl = nullptr;
+                            pRedl->MaybeNotifyModification();
                             break;
 
                         case POS_OUTSIDE:
commit dea74fbbe14e04968a215ffcf2acb54ec24b708e
Author: Tor Lillqvist <t...@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.
    
    (cherry picked from commit 8f96ab602a9e7cad1215abb693f33824a7b37679)
    
    Conflicts:
        sw/source/core/doc/docredln.cxx
    
    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 3c8640f..2e5431c 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -419,6 +419,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;
@@ -1330,6 +1332,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 72d5909..b30e631 100644
--- a/sw/inc/redline.hxx
+++ b/sw/inc/redline.hxx
@@ -192,6 +192,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 );
@@ -213,16 +214,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 90c6875..99cd566 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);
     }
 }
@@ -334,7 +338,7 @@ bool SwRedlineTable::Insert( SwRangeRedline* p, bool bIns )
     {
         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(0, nP);
         return rv.second;
     }
@@ -502,7 +506,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();
@@ -529,7 +533,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;
     }
@@ -952,6 +956,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
 {
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to