desktop/source/lib/init.cxx |   36 +++++++++++++++---------------------
 1 file changed, 15 insertions(+), 21 deletions(-)

New commits:
commit ce81b1046986c06dcb3ef98c7340890894811654
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Fri Jun 13 10:16:21 2025 +0200
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Fri Jun 13 11:56:32 2025 +0200

    Simplify isCommandAllowed
    
    There is no need to call SfxViewShell::Current twice (one time in
    SfxViewShell::IsCurrentLokViewReadOnly). There is no need to check
    pViewShell, when it's already known to exist ("read-only" implies
    that). There is no need to compare command to specially handled
    commands twice (once in special handler, once in deny list search).
    And that makes the deny list a bit shorter, too.
    
    Change-Id: I81d7f3dfce7cfb4571428788486ef90f292aefdf
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186443
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 4ad92a153888..b4fd24cfbcd8 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -5349,32 +5349,26 @@ void LibLibreOffice_Impl::dumpState(rtl::OStringBuffer 
&rState)
 }
 
 // We have special handling for some uno commands and it seems we need to 
check for readonly state.
-static bool isCommandAllowed(std::u16string_view command) {
-    static constexpr OUString nonAllowedList[] = { u".uno:Save"_ustr, 
u".uno:TransformDialog"_ustr, u".uno:SidebarShow"_ustr, 
u".uno:SidebarHide"_ustr };
+static bool isCommandAllowed(std::u16string_view command)
+{
+    static constexpr std::u16string_view denyList[] = { u".uno:SidebarShow", 
u".uno:SidebarHide" };
 
-    if (!SfxViewShell::IsCurrentLokViewReadOnly())
+    SfxViewShell* pViewShell = SfxViewShell::Current();
+    if (!pViewShell || !pViewShell->IsLokReadOnlyView())
         return true;
-    else
+
+    if (command == u".uno:Save")
     {
-        SfxViewShell* pViewShell = SfxViewShell::Current();
-        if (command == u".uno:Save" && pViewShell && 
pViewShell->IsAllowChangeComments())
-            return true;
+        return pViewShell->IsAllowChangeComments();
+    }
 
-        for (size_t i = 0; i < std::size(nonAllowedList); i++)
-        {
-            if (nonAllowedList[i] == command)
-            {
-                bool bRet = false;
-                if (pViewShell && command == u".uno:TransformDialog")
-                {
-                    // If the just added signature line shape is selected, 
allow moving it.
-                    bRet = pViewShell->GetSignPDFCertificate().Is();
-                }
-                return bRet;
-            }
-        }
-        return true;
+    if (command == u".uno:TransformDialog")
+    {
+        // If the just added signature line shape is selected, allow moving it.
+        return pViewShell->GetSignPDFCertificate().Is();
     }
+
+    return std::find(std::begin(denyList), std::end(denyList), command) == 
std::end(denyList);
 }
 
 static void doc_postUnoCommand(LibreOfficeKitDocument* pThis, const char* 
pCommand, const char* pArguments, bool bNotifyWhenFinished)

Reply via email to