[Libreoffice-commits] core.git: sd/inc sd/source

Marco Cecchetti marco.cecchetti at collabora.com
Wed May 31 10:09:42 UTC 2017


 sd/inc/Annotation.hxx                          |    9 +++
 sd/source/core/annotations/Annotation.cxx      |   69 +++++++++++++++++++++++++
 sd/source/ui/annotations/annotationmanager.cxx |   62 +---------------------
 3 files changed, 82 insertions(+), 58 deletions(-)

New commits:
commit b29363a2ec4509b79fca57842a529b4ce460516e
Author: Marco Cecchetti <marco.cecchetti at collabora.com>
Date:   Fri May 19 13:01:25 2017 +0200

    lok: impress: undoing comment deletion doesn't work
    
    Change-Id: I3399ea4131acde42bdd307a8438a9129a83817f2
    Reviewed-on: https://gerrit.libreoffice.org/37815
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Marco Cecchetti <mrcekets at gmail.com>

diff --git a/sd/inc/Annotation.hxx b/sd/inc/Annotation.hxx
index 27f1d51c969d..a4203575a732 100644
--- a/sd/inc/Annotation.hxx
+++ b/sd/inc/Annotation.hxx
@@ -29,8 +29,12 @@ namespace com { namespace sun { namespace star { namespace office {
     class XAnnotation;
 } } } }
 
+class SfxViewShell;
+
 namespace sd {
 
+enum class CommentNotificationType { Add, Modify, Remove };
+
 void createAnnotation( css::uno::Reference< css::office::XAnnotation >& xAnnotation, SdPage* pPage );
 
 SdrUndoAction* CreateUndoInsertOrRemoveAnnotation( const css::uno::Reference< css::office::XAnnotation >& xAnnotation, bool bInsert );
@@ -39,6 +43,11 @@ sal_uInt32 getAnnotationId(const css::uno::Reference <css::office::XAnnotation>&
 
 const SdPage* getAnnotationPage(const css::uno::Reference<css::office::XAnnotation>& xAnnotation);
 
+void LOKCommentNotify(CommentNotificationType nType, const SfxViewShell* pViewShell,
+        css::uno::Reference<css::office::XAnnotation>& rxAnnotation);
+
+void LOKCommentNotifyAll(CommentNotificationType nType,
+        css::uno::Reference<css::office::XAnnotation>& rxAnnotation);
 }
 
 #endif
diff --git a/sd/source/core/annotations/Annotation.cxx b/sd/source/core/annotations/Annotation.cxx
index cf1eeb41e703..be6ecf1b44fe 100644
--- a/sd/source/core/annotations/Annotation.cxx
+++ b/sd/source/core/annotations/Annotation.cxx
@@ -21,15 +21,26 @@
 
 #include "osl/time.h"
 
+#include <boost/property_tree/json_parser.hpp>
+
 #include <com/sun/star/uno/XComponentContext.hpp>
 #include <com/sun/star/office/XAnnotation.hpp>
 #include <com/sun/star/drawing/XDrawPage.hpp>
 
 #include <comphelper/processfactory.hxx>
+#include <comphelper/lok.hxx>
+#include <comphelper/string.hxx>
 #include <cppuhelper/propertysetmixin.hxx>
 #include <cppuhelper/compbase.hxx>
 #include <cppuhelper/basemutex.hxx>
 
+#include <unotools/datetime.hxx>
+#include <tools/datetime.hxx>
+
+#include <sfx2/viewsh.hxx>
+
+#include <LibreOfficeKit/LibreOfficeKitEnums.h>
+
 #include "Annotation.hxx"
 #include "drawdoc.hxx"
 #include "notifydocumentevent.hxx"
@@ -387,6 +398,62 @@ const SdPage* getAnnotationPage(const Reference<XAnnotation>& xAnnotation)
     return nullptr;
 }
 
+
+namespace
+{
+std::string lcl_LOKGetCommentPayload(CommentNotificationType nType, Reference<XAnnotation>& rxAnnotation)
+{
+    boost::property_tree::ptree aAnnotation;
+    aAnnotation.put("action", (nType == CommentNotificationType::Add ? "Add" :
+                               (nType == CommentNotificationType::Remove ? "Remove" :
+                                (nType == CommentNotificationType::Modify ? "Modify" : "???"))));
+    aAnnotation.put("id", sd::getAnnotationId(rxAnnotation));
+    if (nType != CommentNotificationType::Remove && rxAnnotation.is())
+    {
+        aAnnotation.put("id", sd::getAnnotationId(rxAnnotation));
+        aAnnotation.put("author", rxAnnotation->getAuthor());
+        aAnnotation.put("dateTime", utl::toISO8601(rxAnnotation->getDateTime()));
+        uno::Reference<text::XText> xText(rxAnnotation->getTextRange());
+        aAnnotation.put("text", xText->getString());
+        const SdPage* pPage = sd::getAnnotationPage(rxAnnotation);
+        aAnnotation.put("parthash", pPage ? OString::number(pPage->GetHashCode()) : OString());
+    }
+
+    boost::property_tree::ptree aTree;
+    aTree.add_child("comment", aAnnotation);
+    std::stringstream aStream;
+    boost::property_tree::write_json(aStream, aTree);
+
+    return aStream.str();
+}
+} // unonymous ns
+
+void LOKCommentNotify(CommentNotificationType nType, const SfxViewShell* pViewShell, Reference<XAnnotation>& rxAnnotation)
+{
+    // callbacks only if tiled annotations are explicitly turned off by LOK client
+    if (!comphelper::LibreOfficeKit::isActive() || comphelper::LibreOfficeKit::isTiledAnnotations())
+        return ;
+
+    std::string aPayload = lcl_LOKGetCommentPayload(nType, rxAnnotation);
+    pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_COMMENT, aPayload.c_str());
+}
+
+void LOKCommentNotifyAll(CommentNotificationType nType, Reference<XAnnotation>& rxAnnotation)
+{
+    // callbacks only if tiled annotations are explicitly turned off by LOK client
+    if (!comphelper::LibreOfficeKit::isActive() || comphelper::LibreOfficeKit::isTiledAnnotations())
+        return ;
+
+    std::string aPayload = lcl_LOKGetCommentPayload(nType, rxAnnotation);
+
+    const SfxViewShell* pViewShell = SfxViewShell::GetFirst();
+    while (pViewShell)
+    {
+        pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_COMMENT, aPayload.c_str());
+        pViewShell = SfxViewShell::GetNext(*pViewShell);
+    }
+}
+
 UndoInsertOrRemoveAnnotation::UndoInsertOrRemoveAnnotation( Annotation& rAnnotation, bool bInsert )
 : SdrUndoAction( *rAnnotation.GetModel() )
 , mxAnnotation( &rAnnotation )
@@ -423,6 +490,7 @@ void UndoInsertOrRemoveAnnotation::Undo()
         else
         {
             pPage->addAnnotation( xAnnotation, mnIndex );
+            LOKCommentNotifyAll( CommentNotificationType::Add, xAnnotation );
         }
     }
 }
@@ -438,6 +506,7 @@ void UndoInsertOrRemoveAnnotation::Redo()
         if( mbInsert )
         {
             pPage->addAnnotation( xAnnotation, mnIndex );
+            LOKCommentNotifyAll( CommentNotificationType::Add, xAnnotation );
         }
         else
         {
diff --git a/sd/source/ui/annotations/annotationmanager.cxx b/sd/source/ui/annotations/annotationmanager.cxx
index f51373cca0a4..6e61ee2dd5f7 100644
--- a/sd/source/ui/annotations/annotationmanager.cxx
+++ b/sd/source/ui/annotations/annotationmanager.cxx
@@ -64,8 +64,6 @@
 #include <editeng/udlnitem.hxx>
 #include <editeng/crossedoutitem.hxx>
 
-#include <LibreOfficeKit/LibreOfficeKitEnums.h>
-
 #include <svx/postattr.hxx>
 #include <svx/svdetc.hxx>
 
@@ -107,43 +105,6 @@ using namespace ::com::sun::star::ui;
 using namespace ::com::sun::star::task;
 using namespace ::com::sun::star::office;
 
-namespace {
-
-    enum class CommentNotificationType { Add, Modify, Remove };
-
-    void lcl_CommentNotification(CommentNotificationType nType, const SfxViewShell* pViewShell, Reference<XAnnotation>& rxAnnotation)
-    {
-        // callbacks only if tiled annotations are explicitly turned off by LOK client
-        if (!comphelper::LibreOfficeKit::isActive() || comphelper::LibreOfficeKit::isTiledAnnotations())
-            return;
-
-        boost::property_tree::ptree aAnnotation;
-        aAnnotation.put("action", (nType == CommentNotificationType::Add ? "Add" :
-                                   (nType == CommentNotificationType::Remove ? "Remove" :
-                                    (nType == CommentNotificationType::Modify ? "Modify" : "???"))));
-        aAnnotation.put("id", sd::getAnnotationId(rxAnnotation));
-        if (nType != CommentNotificationType::Remove && rxAnnotation.is())
-        {
-            aAnnotation.put("id", sd::getAnnotationId(rxAnnotation));
-            aAnnotation.put("author", rxAnnotation->getAuthor());
-            aAnnotation.put("dateTime", utl::toISO8601(rxAnnotation->getDateTime()));
-            uno::Reference<text::XText> xText(rxAnnotation->getTextRange());
-            aAnnotation.put("text", xText->getString());
-            const SdPage* pPage = sd::getAnnotationPage(rxAnnotation);
-            aAnnotation.put("parthash", pPage ? OString::number(pPage->GetHashCode()) : OString());
-        }
-
-        boost::property_tree::ptree aTree;
-        aTree.add_child("comment", aAnnotation);
-        std::stringstream aStream;
-        boost::property_tree::write_json(aStream, aTree);
-        std::string aPayload = aStream.str();
-
-        pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_COMMENT, aPayload.c_str());
-    }
-
-} // anonymous ns
-
 namespace sd {
 
 SfxItemPool* GetAnnotationPool()
@@ -291,7 +252,7 @@ void SAL_CALL AnnotationManagerImpl::notifyEvent( const css::document::EventObje
             Reference< XAnnotation > xAnnotation( aEvent.Source, uno::UNO_QUERY );
             if ( xAnnotation.is() )
             {
-                lcl_CommentNotification(CommentNotificationType::Remove, &mrBase, xAnnotation);
+                LOKCommentNotify(CommentNotificationType::Remove, &mrBase, xAnnotation);
             }
         }
 
@@ -460,12 +421,7 @@ void AnnotationManagerImpl::ExecuteEditAnnotation(SfxRequest& rReq)
             Reference<XText> xText(xAnnotation->getTextRange());
             xText->setString(sText);
 
-            const SfxViewShell* pViewShell = SfxViewShell::GetFirst();
-            while (pViewShell)
-            {
-                lcl_CommentNotification(CommentNotificationType::Modify, pViewShell, xAnnotation);
-                pViewShell = SfxViewShell::GetNext(*pViewShell);
-            }
+            LOKCommentNotifyAll(CommentNotificationType::Modify, xAnnotation);
         }
     }
 
@@ -559,12 +515,7 @@ void AnnotationManagerImpl::InsertAnnotation(const OUString& rText)
             mpDoc->EndUndo();
 
         // Tell our LOK clients about new comment added
-        const SfxViewShell* pViewShell = SfxViewShell::GetFirst();
-        while (pViewShell)
-        {
-            lcl_CommentNotification(CommentNotificationType::Add, pViewShell, xAnnotation);
-            pViewShell = SfxViewShell::GetNext(*pViewShell);
-        }
+        LOKCommentNotifyAll(CommentNotificationType::Add, xAnnotation);
 
         UpdateTags(true);
         SelectAnnotation( xAnnotation, true );
@@ -652,12 +603,7 @@ void AnnotationManagerImpl::ExecuteReplyToAnnotation( SfxRequest& rReq )
         xAnnotation->setDateTime( getCurrentDateTime() );
 
         // Tell our LOK clients about this (comment modification)
-        const SfxViewShell* pViewShell = SfxViewShell::GetFirst();
-        while (pViewShell)
-        {
-            lcl_CommentNotification(CommentNotificationType::Modify, pViewShell, xAnnotation);
-            pViewShell = SfxViewShell::GetNext(*pViewShell);
-        }
+        LOKCommentNotifyAll(CommentNotificationType::Modify, xAnnotation);
 
         UpdateTags(true);
         SelectAnnotation( xAnnotation, true );


More information about the Libreoffice-commits mailing list