include/sfx2/dispatch.hxx | 1 + sfx2/source/control/dispatch.cxx | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-)
New commits: commit 226e2263468da403d1f9db504115830f5a030229 Author: Gökay Şatır <gokaysa...@gmail.com> AuthorDate: Tue Mar 26 18:41:34 2024 +0300 Commit: Gökay ŞATIR <gokaysa...@collabora.com> CommitDate: Wed Mar 27 10:39:09 2024 +0100 Enable allowing comment editing in readOnly view mode. Signed-off-by: Gökay Şatır <gokaysa...@gmail.com> Change-Id: I536448da395568cd43af6f4d1d36ef09f3c6a6b3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165349 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Gökay ŞATIR <gokaysa...@collabora.com> diff --git a/include/sfx2/dispatch.hxx b/include/sfx2/dispatch.hxx index 7216fc92badc..fee0082fb36b 100644 --- a/include/sfx2/dispatch.hxx +++ b/include/sfx2/dispatch.hxx @@ -89,6 +89,7 @@ friend class SfxHelp; bool FindServer_( sal_uInt16 nId, SfxSlotServer &rServer ); + static bool IsCommandAllowedInLokReadOnlyViewMode (OUString commandName); bool FillState_( const SfxSlotServer &rServer, SfxItemSet &rState, const SfxSlot *pRealSlot ); void Execute_( SfxShell &rShell, const SfxSlot &rSlot, diff --git a/sfx2/source/control/dispatch.cxx b/sfx2/source/control/dispatch.cxx index 67f78885a033..81317dab4153 100644 --- a/sfx2/source/control/dispatch.cxx +++ b/sfx2/source/control/dispatch.cxx @@ -1521,6 +1521,23 @@ SfxSlotFilterState SfxDispatcher::IsSlotEnabledByFilter_Impl( sal_uInt16 nSID ) return bFound ? SfxSlotFilterState::DISABLED : SfxSlotFilterState::ENABLED; } +bool SfxDispatcher::IsCommandAllowedInLokReadOnlyViewMode (OUString commandName) { + constexpr OUString allowedList[] = { + u".uno:InsertAnnotation"_ustr, + u".uno:ReplyComment"_ustr, + u".uno:ResolveComment"_ustr, + u".uno:ResolveCommentThread"_ustr, + u".uno:DeleteComment"_ustr, + u".uno:DeleteAnnotation"_ustr, + u".uno:EditAnnotation"_ustr, + }; + + if (std::find(std::begin(allowedList), std::end(allowedList), commandName) != std::end(allowedList)) + return true; + else + return false; +} + /** This helper method searches for the <Slot-Server> which currently serves the nSlot. As the result, rServe is filled accordingly. @@ -1590,9 +1607,16 @@ bool SfxDispatcher::FindServer_(sal_uInt16 nSlot, SfxSlotServer& rServer) } bool bReadOnly = ( SfxSlotFilterState::ENABLED_READONLY != nSlotEnableMode && xImp->bReadOnly ); + bool bCheckForCommentCommands = false; - if (!bReadOnly && comphelper::LibreOfficeKit::isActive()) - bReadOnly = xImp->pFrame && xImp->pFrame->GetViewShell() && xImp->pFrame->GetViewShell()->IsLokReadOnlyView(); + if (!bReadOnly && comphelper::LibreOfficeKit::isActive() && xImp->pFrame && xImp->pFrame->GetViewShell()) + { + SfxViewShell *pViewSh = xImp->pFrame->GetViewShell(); + bReadOnly = pViewSh->IsLokReadOnlyView(); + + if (bReadOnly && pViewSh->IsAllowChangeComments()) + bCheckForCommentCommands = true; + } // search through all the shells of the chained dispatchers // from top to bottom @@ -1606,6 +1630,10 @@ bool SfxDispatcher::FindServer_(sal_uInt16 nSlot, SfxSlotServer& rServer) SfxInterface *pIFace = pObjShell->GetInterface(); const SfxSlot *pSlot = pIFace->GetSlot(nSlot); + // This check can be true only if Lokit is active and view is readonly. + if (pSlot && bCheckForCommentCommands) + bReadOnly = IsCommandAllowedInLokReadOnlyViewMode(pSlot->GetCommand()); + if ( pSlot && pSlot->nDisableFlags != SfxDisableFlags::NONE && ( static_cast<int>(pSlot->nDisableFlags) & static_cast<int>(pObjShell->GetDisableFlags()) ) != 0 ) return false;