include/sfx2/dispatch.hxx        |    1 
 include/sfx2/viewsh.hxx          |    2 -
 sfx2/source/control/dispatch.cxx |   75 ++++++++++++++++++++-------------------
 3 files changed, 40 insertions(+), 38 deletions(-)

New commits:
commit f07f1d4c3acbd08dbfad5250a6327a21e8a769a6
Author:     Mike Kaganski <[email protected]>
AuthorDate: Wed Jun 18 13:20:10 2025 +0500
Commit:     Miklos Vajna <[email protected]>
CommitDate: Fri Jun 20 08:55:01 2025 +0200

    Restructure SfxDispatcher::FindServer_ more
    
    A follow-up to commit 51c6879137325c66dd447ff82c35292953d15ae7
    (Restructure SfxDispatcher::FindServer_, 2025-06-17).
    
    Split the code that checks exceptions for global read-only mode
    (defined by xImp->bReadOnly), and LOK view read-only mode (defined
    by GetViewShell()->IsLokReadOnlyView()).
    
    IsCommandAllowedInLokReadOnlyViewMode is removed from SfxDispatcher
    (there is no need to access this static function from outside).
    
    Change-Id: Ib5e3cfec116112ade23b351367ccece289c1f2d8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186650
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186685
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Miklos Vajna <[email protected]>

diff --git a/include/sfx2/dispatch.hxx b/include/sfx2/dispatch.hxx
index 6963484b3b0e..15d96f2a531d 100644
--- a/include/sfx2/dispatch.hxx
+++ b/include/sfx2/dispatch.hxx
@@ -90,7 +90,6 @@ friend class SfxHintPoster;
 
 
     bool                FindServer_( sal_uInt16 nId, SfxSlotServer &rServer );
-    static bool         IsCommandAllowedInLokReadOnlyViewMode(const OUString & 
commandName);
     bool                FillState_( const SfxSlotServer &rServer,
                                     SfxItemSet &rState, const SfxSlot 
*pRealSlot );
     void                Execute_( SfxShell &rShell, const SfxSlot &rSlot,
diff --git a/include/sfx2/viewsh.hxx b/include/sfx2/viewsh.hxx
index 2a9af514b956..dcd6619d4e0f 100644
--- a/include/sfx2/viewsh.hxx
+++ b/include/sfx2/viewsh.hxx
@@ -253,7 +253,7 @@ public:
     void                        SetLokReadOnlyView(bool readOnlyView) { 
lokReadOnlyView = readOnlyView; };
     bool                        IsLokReadOnlyView() const { return 
lokReadOnlyView; };
     void                        SetAllowChangeComments(bool allow) { 
allowChangeComments = allow; }
-    bool                        IsAllowChangeComments() { return 
allowChangeComments; }
+    bool                        IsAllowChangeComments() const { return 
allowChangeComments; }
 
     // Misc
 
diff --git a/sfx2/source/control/dispatch.cxx b/sfx2/source/control/dispatch.cxx
index adf72165bd92..40910ff6e949 100644
--- a/sfx2/source/control/dispatch.cxx
+++ b/sfx2/source/control/dispatch.cxx
@@ -1534,23 +1534,27 @@ SfxSlotFilterState 
SfxDispatcher::IsSlotEnabledByFilter_Impl( sal_uInt16 nSID )
         return bFound ? SfxSlotFilterState::DISABLED : 
SfxSlotFilterState::ENABLED;
 }
 
-bool SfxDispatcher::IsCommandAllowedInLokReadOnlyViewMode (const OUString & 
commandName) {
-    static 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,
-        u".uno:PromoteComment"_ustr,
-        u".uno:Save"_ustr,
-    };
-
-    if (std::find(std::begin(allowedList), std::end(allowedList), commandName) 
!= std::end(allowedList))
-        return true;
-    else
-        return false;
+static bool IsCommandAllowedInLokReadOnlyViewMode(std::u16string_view 
commandName,
+                                                  const SfxViewShell& 
viewShell)
+{
+    if (viewShell.IsAllowChangeComments())
+    {
+        static constexpr std::u16string_view allowed[] = {
+            u".uno:InsertAnnotation",
+            u".uno:ReplyComment",
+            u".uno:ResolveComment",
+            u".uno:ResolveCommentThread",
+            u".uno:DeleteComment",
+            u".uno:DeleteAnnotation",
+            u".uno:EditAnnotation",
+            u".uno:PromoteComment",
+            u".uno:Save",
+        };
+
+        if (std::find(std::begin(allowed), std::end(allowed), commandName) != 
std::end(allowed))
+            return true;
+    }
+    return false;
 }
 
 /** This helper method searches for the <Slot-Server> which currently serves
@@ -1622,17 +1626,10 @@ bool SfxDispatcher::FindServer_(sal_uInt16 nSlot, 
SfxSlotServer& rServer)
     }
 
     const bool isViewerAppMode = 
officecfg::Office::Common::Misc::ViewerAppMode::get();
-    bool bReadOnly = ( SfxSlotFilterState::ENABLED_READONLY != nSlotEnableMode 
&& xImp->bReadOnly );
-    bool bCheckForCommentCommands = false;
-
-    if (!bReadOnly && comphelper::LibreOfficeKit::isActive() && xImp->pFrame 
&& xImp->pFrame->GetViewShell())
-    {
-        SfxViewShell *pViewSh = xImp->pFrame->GetViewShell();
-        bReadOnly = pViewSh->IsLokReadOnlyView();
-
-        if (bReadOnly && pViewSh->IsAllowChangeComments())
-            bCheckForCommentCommands = true;
-    }
+    const bool bReadOnlyGlobal = SfxSlotFilterState::ENABLED_READONLY != 
nSlotEnableMode && xImp->bReadOnly;
+    const bool bReadOnlyLokView = !bReadOnlyGlobal && 
comphelper::LibreOfficeKit::isActive()
+                                  && xImp->pFrame && 
xImp->pFrame->GetViewShell()
+                                  && 
xImp->pFrame->GetViewShell()->IsLokReadOnlyView();
 
     const bool bIsInPlace = xImp->pFrame && 
xImp->pFrame->GetObjectShell()->IsInPlaceActive();
     // Shell belongs to Server?
@@ -1678,16 +1675,22 @@ bool SfxDispatcher::FindServer_(sal_uInt16 nSlot, 
SfxSlotServer& rServer)
         if (!(pSlot->nFlags & SfxSlotMode::VIEWERAPP) && isViewerAppMode)
             return false;
 
-        if (!(pSlot->nFlags & SfxSlotMode::READONLYDOC) && bReadOnly)
+        // The slot is not read-only
+        if (!(pSlot->nFlags & SfxSlotMode::READONLYDOC))
         {
-            bool bAllowThis = false;
-
-            // This check can be true only if Lokit is active and view is 
readonly.
-            if (bCheckForCommentCommands)
-                bAllowThis = 
IsCommandAllowedInLokReadOnlyViewMode(pSlot->GetCommand());
-
-            if (!bAllowThis)
+            // 1. The global context is read-only
+            if (bReadOnlyGlobal)
+            {
                 return false;
+            }
+
+            // 2. LOK view context is read-only
+            if (bReadOnlyLokView)
+            {
+                if (!IsCommandAllowedInLokReadOnlyViewMode(pSlot->GetCommand(),
+                                                           
*xImp->pFrame->GetViewShell()))
+                    return false;
+            }
         }
 
         rServer.SetSlot(pSlot);

Reply via email to