Kaydet (Commit) b29363a2 authored tarafından Marco Cecchetti's avatar Marco Cecchetti Kaydeden (comit) Marco Cecchetti

lok: impress: undoing comment deletion doesn't work

Change-Id: I3399ea4131acde42bdd307a8438a9129a83817f2
Reviewed-on: https://gerrit.libreoffice.org/37815Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMarco Cecchetti <mrcekets@gmail.com>
üst 22a69119
......@@ -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
......
......@@ -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
{
......
......@@ -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 );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment