desktop/source/lib/init.cxx    |    6 ++----
 include/sfx2/lokhelper.hxx     |    4 ++++
 sfx2/source/view/lokhelper.cxx |   30 ++++++++++++++++++++++++++++++
 3 files changed, 36 insertions(+), 4 deletions(-)

New commits:
commit 4d8c4a60105488be84ea80775dc04a24582752fb
Author:     Gökay Şatır <gokaysa...@collabora.com>
AuthorDate: Tue Apr 23 14:40:14 2024 +0300
Commit:     Michael Meeks <michael.me...@collabora.com>
CommitDate: Fri Apr 26 16:08:38 2024 +0200

    Use a for loop for setting view properties.
    
    Since there may be no view with the given id, checking the list first is 
safer.
    
    Signed-off-by: Gökay Şatır <gokaysa...@collabora.com>
    Change-Id: I4c305e0a0f6ce7cccdfea9889c414a6054ed3a88
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166531
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Michael Meeks <michael.me...@collabora.com>

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index ba9b45230093..79e5af2fdedd 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -7292,8 +7292,7 @@ static void doc_setViewReadOnly(SAL_UNUSED_PARAMETER 
LibreOfficeKitDocument* pTh
     SolarMutexGuard aGuard;
     SetLastExceptionMsg();
 
-    doc_setView(pThis, nId);
-    SfxViewShell::Current()->SetLokReadOnlyView(readOnly);
+    SfxLokHelper::setViewReadOnly(nId, readOnly);
 }
 
 static void doc_setAllowChangeComments(SAL_UNUSED_PARAMETER 
LibreOfficeKitDocument* pThis, int nId, const bool allow)
@@ -7303,8 +7302,7 @@ static void 
doc_setAllowChangeComments(SAL_UNUSED_PARAMETER LibreOfficeKitDocume
     SolarMutexGuard aGuard;
     SetLastExceptionMsg();
 
-    doc_setView(pThis, nId);
-    SfxViewShell::Current()->SetAllowChangeComments(allow);
+    SfxLokHelper::setAllowChangeComments(nId, allow);
 }
 
 static void doc_setAccessibilityState(SAL_UNUSED_PARAMETER 
LibreOfficeKitDocument* pThis, int nId, bool nEnabled)
diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx
index 3cdc404a8e2a..96974417430e 100644
--- a/include/sfx2/lokhelper.hxx
+++ b/include/sfx2/lokhelper.hxx
@@ -119,6 +119,10 @@ public:
     static void setDefaultLanguage(const OUString& rBcp47LanguageTag);
     /// Enable/Disable AT support for the given view.
     static void setAccessibilityState(int nId, bool nEnabled);
+    // Set the readonly state of the view.
+    static void setViewReadOnly(int nId, bool readOnly);
+    // In readonly view, can user add / modify comments or not.
+    static void setAllowChangeComments(int nId, bool allow);
     /// Get the language used by the loading view (used for all save 
operations).
     static const LanguageTag & getLoadLanguage();
     /// Set the language used by the loading view (used for all save 
operations).
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index 80bdb38aa13a..8df19c359442 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -341,6 +341,36 @@ void SfxLokHelper::setViewLanguage(int nId, const 
OUString& rBcp47LanguageTag)
     }
 }
 
+void SfxLokHelper::setViewReadOnly(int nId, bool readOnly)
+{
+    std::vector<SfxViewShell*>& rViewArr = SfxGetpApp()->GetViewShells_Impl();
+
+    for (SfxViewShell* pViewShell : rViewArr)
+    {
+        if (pViewShell && pViewShell->GetViewShellId() == ViewShellId(nId))
+        {
+            LOK_INFO("lok.readonlyview", "SfxLokHelper::setViewReadOnly: view 
id: " << nId << ", readOnly: " << readOnly);
+            pViewShell->SetLokReadOnlyView(readOnly);
+            return;
+        }
+    }
+}
+
+void SfxLokHelper::setAllowChangeComments(int nId, bool allow)
+{
+    std::vector<SfxViewShell*>& rViewArr = SfxGetpApp()->GetViewShells_Impl();
+
+    for (SfxViewShell* pViewShell : rViewArr)
+    {
+        if (pViewShell && pViewShell->GetViewShellId() == ViewShellId(nId))
+        {
+            LOK_INFO("lok.readonlyview", 
"SfxLokHelper::setAllowChangeComments: view id: " << nId << ", allow: " << 
allow);
+            pViewShell->SetAllowChangeComments(allow);
+            return;
+        }
+    }
+}
+
 void SfxLokHelper::setAccessibilityState(int nId, bool nEnabled)
 {
     std::vector<SfxViewShell*>& rViewArr = SfxGetpApp()->GetViewShells_Impl();

Reply via email to