diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index 945be7009d0a..11db3d75398b 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -192,6 +192,7 @@ public: void testCommentsImpress(); void testCommentsCallbacksWriter(); void testCommentsAddEditDeleteDraw(); + void testCommentsInReadOnlyMode(); void testRunMacro(); void testExtractParameter(); void testGetSignatureState_NonSigned(); @@ -262,6 +263,7 @@ public: CPPUNIT_TEST(testCommentsImpress); CPPUNIT_TEST(testCommentsCallbacksWriter); CPPUNIT_TEST(testCommentsAddEditDeleteDraw); + CPPUNIT_TEST(testCommentsInReadOnlyMode); CPPUNIT_TEST(testRunMacro); CPPUNIT_TEST(testExtractParameter); CPPUNIT_TEST(testGetSignatureState_Signed); @@ -2665,6 +2667,72 @@ void DesktopLOKTest::testCommentsAddEditDeleteDraw() CPPUNIT_ASSERT_EQUAL(nCommentId1, aView1.m_aCommentCallbackResult.get("id")); } +void DesktopLOKTest::testCommentsInReadOnlyMode() +{ + // Comments callback are emitted only if tiled annotations are off + comphelper::LibreOfficeKit::setTiledAnnotations(false); + LibLODocument_Impl* pDocument = loadDoc("blank_text.odt"); + + int viewId = pDocument->m_pDocumentClass->createView(pDocument); + pDocument->m_pDocumentClass->setView(pDocument, viewId); + + pDocument->m_pDocumentClass->initializeForRendering(pDocument, "{\".uno:Author\":{\"type\":\"string\",\"value\":\"LOK User1\"}}"); + + SfxLokHelper::setViewReadOnly(viewId, true); + SfxLokHelper::setAllowChangeComments(viewId, true); + + Scheduler::ProcessEventsToIdle(); + + ViewCallback aView(pDocument); + + // Add a new comment + OString aCommandArgs; + { + tools::JsonWriter aJson; + addParameter(aJson, "Text", "string", "Comment"); + addParameter(aJson, "Author", "string", "LOK User1"); + aCommandArgs = aJson.finishAndGetAsOString(); + } + + pDocument->pClass->postUnoCommand(pDocument, ".uno:InsertAnnotation", aCommandArgs.getStr(), false); + Scheduler::ProcessEventsToIdle(); + + // We received a LOK_CALLBACK_COMMENT callback with comment 'Add' action + CPPUNIT_ASSERT_EQUAL(std::string("Add"), aView.m_aCommentCallbackResult.get("action")); + int nCommentId = aView.m_aCommentCallbackResult.get("id"); + + // Edit the previously added comment + { + tools::JsonWriter aJson; + addParameter(aJson, "Id", "string", OString::number(nCommentId)); + addParameter(aJson, "Text", "string", "Edited comment"); + aCommandArgs = aJson.finishAndGetAsOString(); + } + + pDocument->pClass->postUnoCommand(pDocument, ".uno:EditAnnotation", aCommandArgs.getStr(), false); + Scheduler::ProcessEventsToIdle(); + + // We received a LOK_CALLBACK_COMMENT callback with comment 'Modify' action + CPPUNIT_ASSERT_EQUAL(std::string("Modify"), aView.m_aCommentCallbackResult.get("action")); + CPPUNIT_ASSERT_EQUAL(nCommentId, aView.m_aCommentCallbackResult.get("id")); + + // Delete Comment + { + tools::JsonWriter aJson; + addParameter(aJson, "Id", "string", OString::number(nCommentId)); + aCommandArgs = aJson.finishAndGetAsOString(); + } + pDocument->pClass->postUnoCommand(pDocument, ".uno:DeleteAnnotation", aCommandArgs.getStr(), false); + Scheduler::ProcessEventsToIdle(); + + // Result is not sent for delete operation for some reason. But it is sent when debugging with online. + // TODO: Enable below 2 checks. + + // We received a LOK_CALLBACK_COMMENT callback with comment 'Remove' action + //CPPUNIT_ASSERT_EQUAL(std::string("Remove"), aView.m_aCommentCallbackResult.get("action")); + //CPPUNIT_ASSERT_EQUAL(nCommentId, aView.m_aCommentCallbackResult.get("id")); +} + void DesktopLOKTest::testRunMacro() { LibLibreOffice_Impl aOffice; diff --git a/sfx2/source/control/dispatch.cxx b/sfx2/source/control/dispatch.cxx index d8a24baebcc0..87dc47d8c976 100644 --- a/sfx2/source/control/dispatch.cxx +++ b/sfx2/source/control/dispatch.cxx @@ -1635,7 +1635,7 @@ bool SfxDispatcher::FindServer_(sal_uInt16 nSlot, SfxSlotServer& rServer) // This check can be true only if Lokit is active and view is readonly. if (pSlot && bCheckForCommentCommands) - bReadOnly = IsCommandAllowedInLokReadOnlyViewMode(pSlot->GetCommand()); + bReadOnly = !IsCommandAllowedInLokReadOnlyViewMode(pSlot->GetCommand()); if ( pSlot && pSlot->nDisableFlags != SfxDisableFlags::NONE && ( static_cast(pSlot->nDisableFlags) & static_cast(pObjShell->GetDisableFlags()) ) != 0 )