summaryrefslogtreecommitdiff
path: root/sd
diff options
context:
space:
mode:
authorPranav Kant <pranavk@collabora.co.uk>2017-02-20 16:12:11 +0530
committerPranav Kant <pranavk@collabora.co.uk>2017-02-20 20:46:34 +0530
commitb02416ea4742873153227b6eaca00a15e7335987 (patch)
treee15cb1f4296025c3d1076820c517c32b9a5fa853 /sd
parent35bb22c1a834b306c910cb065bc006818c9fa9b3 (diff)
sd lok: Don't rely on model notify events
Place comment notification triggers at the end of the annotation insertion/modification function to accomplish the desired behavior. See inline comment for details. Change-Id: I0cbd51feb455d497826d6a4534a8bbd817be7b31
Diffstat (limited to 'sd')
-rw-r--r--sd/source/ui/annotations/annotationmanager.cxx47
1 files changed, 37 insertions, 10 deletions
diff --git a/sd/source/ui/annotations/annotationmanager.cxx b/sd/source/ui/annotations/annotationmanager.cxx
index 8d318854ed31..5b7b3246faaf 100644
--- a/sd/source/ui/annotations/annotationmanager.cxx
+++ b/sd/source/ui/annotations/annotationmanager.cxx
@@ -109,18 +109,20 @@ using namespace ::com::sun::star::office;
namespace {
- void lcl_CommentNotification(const OUString& rEventName, const sd::ViewShellBase& rViewShell, Reference<XAnnotation>& rxAnnotation)
+ enum class CommentNotificationType { Add, Modify, Remove };
+
+ void lcl_CommentNotification(CommentNotificationType nType, const SfxViewShell* pViewShell, Reference<XAnnotation>& rxAnnotation)
{
// callbacks only if tiled annotations are explicltly turned off by LOK client
if (!comphelper::LibreOfficeKit::isActive() || comphelper::LibreOfficeKit::isTiledAnnotations())
return;
boost::property_tree::ptree aAnnotation;
- aAnnotation.put("action", (rEventName == "OnAnnotationInserted" ? "Add" :
- (rEventName == "OnAnnotationRemoved" ? "Remove" :
- (rEventName == "OnAnnotationChanged" ? "Modify" : "???"))));
+ aAnnotation.put("action", (nType == CommentNotificationType::Add ? "Add" :
+ (nType == CommentNotificationType::Remove ? "Remove" :
+ (nType == CommentNotificationType::Modify ? "Modify" : "???"))));
aAnnotation.put("id", sd::getAnnotationId(rxAnnotation));
- if (rEventName != "OnAnnotationRemoved")
+ if (nType != CommentNotificationType::Remove)
{
aAnnotation.put("id", sd::getAnnotationId(rxAnnotation));
aAnnotation.put("author", rxAnnotation->getAuthor());
@@ -135,7 +137,7 @@ namespace {
boost::property_tree::write_json(aStream, aTree);
std::string aPayload = aStream.str();
- rViewShell.libreOfficeKitViewCallback(LOK_CALLBACK_COMMENT, aPayload.c_str());
+ pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_COMMENT, aPayload.c_str());
}
} // anonymous ns
@@ -276,12 +278,21 @@ void SAL_CALL AnnotationManagerImpl::notifyEvent( const css::document::EventObje
{
if( aEvent.EventName == "OnAnnotationInserted" || aEvent.EventName == "OnAnnotationRemoved" || aEvent.EventName == "OnAnnotationChanged" )
{
- Reference<XAnnotation> xAnnotation(aEvent.Source, uno::UNO_QUERY);
- if (xAnnotation.is())
+ // AnnotationInsertion and modification is not handled here because when
+ // a new annotation is inserted, it consists of OnAnnotationInserted
+ // followed by a chain of OnAnnotationChanged (called for setting each
+ // of the annotation attributes - author, text etc.). This is not what a
+ // LOK client wants. So only handle removal here as annotation removal
+ // consists of only one event - 'OnAnnotationRemoved'
+ if ( aEvent.EventName == "OnAnnotationRemoved" )
{
- // Inform our LOK clients
- lcl_CommentNotification(aEvent.EventName, mrBase, xAnnotation);
+ Reference< XAnnotation > xAnnotation( aEvent.Source, uno::UNO_QUERY );
+ if ( xAnnotation.is() )
+ {
+ lcl_CommentNotification(CommentNotificationType::Remove, &mrBase, xAnnotation);
+ }
}
+
UpdateTags();
}
}
@@ -507,6 +518,14 @@ void AnnotationManagerImpl::InsertAnnotation(const OUString& rText)
if( mpDoc->IsUndoEnabled() )
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);
+ }
+
UpdateTags(true);
SelectAnnotation( xAnnotation, true );
}
@@ -585,6 +604,14 @@ void AnnotationManagerImpl::ExecuteReplyToAnnotation( SfxRequest& rReq )
// set current time to reply
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);
+ }
+
UpdateTags(true);
SelectAnnotation( xAnnotation, true );
}