sw/inc/IDocumentRedlineAccess.hxx             |    2 -
 sw/source/core/doc/DocumentRedlineManager.cxx |   32 ++++++++++++++++++--------
 sw/source/core/edit/edredln.cxx               |   11 --------
 sw/source/uibase/uiview/view.cxx              |    4 +++
 4 files changed, 28 insertions(+), 21 deletions(-)

New commits:
commit ab5560d443247722a55936cb31baa4e6c6b81371
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Thu Feb 27 13:19:10 2025 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Thu Feb 27 15:47:48 2025 +0100

    cool#11226 sw per-view redline on: move the setter to the model
    
    Open e.g. an RTF file with  evisions in it (enable track changes
    recording), notice that track changes is not enabled, when the UI would
    take the "redline on" setting from the view.
    
    Commit 025a1e4612fecf59f38910fbf52fc63db054ae5f (cool#11226 sw per-view
    redline on: add new flag in SwViewOption, 2025-02-26) added the per-view
    "is record" setter to SwEditShell, but I missed that this setting can be
    also set by an import filter, which works on an SwDoc with no view.
    
    Fix this problem by:
    
    - remove the setter from SwEditShell::SetRedlineFlags(), we'll do this
      in the model instead
    - use sw::DocumentRedlineManager::SetRedlineFlags_intern() everywhere,
      so we have a central point where the current view (if there is any)
      can be updated together with the model
    - implement the model -> current view synchronization in
      sw::DocumentRedlineManager::SetRedlineFlags_intern()
    - extend the the SwView ctor, so the setting of the view is not the
      default, but it's based on the model
    
    Also make it explicit that RedlineFlags::Ignore is not something a user
    may set. With this rearrangement, implementing a getter (that takes the
    view into account) looks possible, but is not yet done in this commit.
    
    Change-Id: Ifc0c3bbb95539cc1a26582ee7d27653899fbc236
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182304
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins

diff --git a/sw/inc/IDocumentRedlineAccess.hxx 
b/sw/inc/IDocumentRedlineAccess.hxx
index 264c23e29895..eeb793530337 100644
--- a/sw/inc/IDocumentRedlineAccess.hxx
+++ b/sw/inc/IDocumentRedlineAccess.hxx
@@ -43,7 +43,7 @@ enum class RedlineFlags
 {
     NONE                 = 0x000, ///< no RedlineFlags
     On                   = 0x001, ///< RedlineFlags on
-    Ignore               = 0x002, ///< ignore Redlines
+    Ignore               = 0x002, ///< ignore Redlines (only set from code, 
temporarily)
     ShowInsert           = 0x010, ///< show all inserts
     ShowDelete           = 0x020, ///< show all deletes
     ShowMask             = ShowInsert | ShowDelete,
diff --git a/sw/source/core/doc/DocumentRedlineManager.cxx 
b/sw/source/core/doc/DocumentRedlineManager.cxx
index 01d02a704e97..f1b639ca3895 100644
--- a/sw/source/core/doc/DocumentRedlineManager.cxx
+++ b/sw/source/core/doc/DocumentRedlineManager.cxx
@@ -1224,7 +1224,7 @@ void DocumentRedlineManager::SetRedlineFlags( 
RedlineFlags eMode )
 
         m_rDoc.SetInXMLImport( bSaveInXMLImportFlag );
     }
-    meRedlineFlags = eMode;
+    SetRedlineFlags_intern(eMode);
     m_rDoc.getIDocumentState().SetModified();
 
     // #TODO - add 'SwExtraRedlineTable' also ?
@@ -1242,6 +1242,20 @@ bool DocumentRedlineManager::IsIgnoreRedline() const
 
 void DocumentRedlineManager::SetRedlineFlags_intern(RedlineFlags eMode)
 {
+    SwDocShell* pDocShell = m_rDoc.GetDocShell();
+    SwWrtShell* pWrtShell = pDocShell ? pDocShell->GetWrtShell() : nullptr;
+    if (pWrtShell)
+    {
+        // Recording can be per-view, the rest is per-document.
+        auto bRedlineRecordingOn = bool(eMode & RedlineFlags::On);
+        SwViewOption aOpt(*pWrtShell->GetViewOptions());
+        if (aOpt.IsRedlineRecordingOn() != bRedlineRecordingOn)
+        {
+            aOpt.SetRedlineRecordingOn(bRedlineRecordingOn);
+            pWrtShell->ApplyViewOptions(aOpt);
+        }
+    }
+
     meRedlineFlags = eMode;
 }
 
@@ -1325,9 +1339,9 @@ DocumentRedlineManager::AppendRedline(SwRangeRedline* 
pNewRedl, bool const bCall
             RedlineFlags eOld = meRedlineFlags;
             // Set to NONE, so that the Delete::Redo merges the Redline data 
correctly!
             // The ShowMode needs to be retained!
-            meRedlineFlags = eOld & ~RedlineFlags(RedlineFlags::On | 
RedlineFlags::Ignore);
+            SetRedlineFlags_intern(eOld & ~RedlineFlags(RedlineFlags::On | 
RedlineFlags::Ignore));
             m_rDoc.getIDocumentContentOperations().DeleteAndJoin( *pNewRedl );
-            meRedlineFlags = eOld;
+            SetRedlineFlags_intern(eOld);
         }
         delete pNewRedl;
         pNewRedl = nullptr;
@@ -1827,7 +1841,7 @@ DocumentRedlineManager::AppendRedline(SwRangeRedline* 
pNewRedl, bool const bCall
 
                     // Set to NONE, so that the Delete::Redo merges the 
Redline data correctly!
                     // The ShowMode needs to be retained!
-                    meRedlineFlags = eOld & ~RedlineFlags(RedlineFlags::On | 
RedlineFlags::Ignore);
+                    SetRedlineFlags_intern(eOld & 
~RedlineFlags(RedlineFlags::On | RedlineFlags::Ignore));
                     switch( eCmpPos )
                     {
                     case SwComparePosition::Equal:
@@ -1926,7 +1940,7 @@ DocumentRedlineManager::AppendRedline(SwRangeRedline* 
pNewRedl, bool const bCall
                         break;
                     }
 
-                    meRedlineFlags = eOld;
+                    SetRedlineFlags_intern(eOld);
                 }
                 else
                 {
@@ -2490,9 +2504,9 @@ bool DocumentRedlineManager::AppendTableRowRedline( 
SwTableRowRedline* pNewRedl
             RedlineFlags eOld = meRedlineFlags;
             // Set to NONE, so that the Delete::Redo merges the Redline data 
correctly!
             // The ShowMode needs to be retained!
-            meRedlineFlags = eOld & ~(RedlineFlags::On | RedlineFlags::Ignore);
+            SetRedlineFlags_intern(eOld & ~(RedlineFlags::On | 
RedlineFlags::Ignore));
             DeleteAndJoin( *pNewRedl );
-            meRedlineFlags = eOld;
+            SetRedlineFlags_intern(eOld);
         }
         delete pNewRedl, pNewRedl = 0;
         */
@@ -2532,9 +2546,9 @@ bool DocumentRedlineManager::AppendTableCellRedline( 
SwTableCellRedline* pNewRed
             RedlineFlags eOld = meRedlineFlags;
             // Set to NONE, so that the Delete::Redo merges the Redline data 
correctly!
             // The ShowMode needs to be retained!
-            meRedlineFlags = eOld & ~(RedlineFlags::On | RedlineFlags::Ignore);
+            SetRedlineFlags_intern(eOld & ~(RedlineFlags::On | 
RedlineFlags::Ignore));
             DeleteAndJoin( *pNewRedl );
-            meRedlineFlags = eOld;
+            SetRedlineFlags_intern(eOld);
         }
         delete pNewRedl, pNewRedl = 0;
         */
diff --git a/sw/source/core/edit/edredln.cxx b/sw/source/core/edit/edredln.cxx
index 9eff073c09b6..1778745f57e4 100644
--- a/sw/source/core/edit/edredln.cxx
+++ b/sw/source/core/edit/edredln.cxx
@@ -22,7 +22,6 @@
 #include <redline.hxx>
 #include <doc.hxx>
 #include <editsh.hxx>
-#include <viewopt.hxx>
 #include <frmtool.hxx>
 
 RedlineFlags SwEditShell::GetRedlineFlags() const
@@ -36,16 +35,6 @@ void SwEditShell::SetRedlineFlags( RedlineFlags eMode )
     {
         CurrShell aCurr( this );
         StartAllAction();
-
-        // Recording is per-view, the rest if per-document.
-        auto bRedlineRecordingOn = bool(eMode & RedlineFlags::On);
-        SwViewOption aOpt(*GetViewOptions());
-        if (aOpt.IsRedlineRecordingOn() != bRedlineRecordingOn)
-        {
-            aOpt.SetRedlineRecordingOn(bRedlineRecordingOn);
-            ApplyViewOptions(aOpt);
-        }
-
         GetDoc()->getIDocumentRedlineAccess().SetRedlineFlags( eMode );
         EndAllAction();
     }
diff --git a/sw/source/uibase/uiview/view.cxx b/sw/source/uibase/uiview/view.cxx
index 342f889183c7..ee7a7de88918 100644
--- a/sw/source/uibase/uiview/view.cxx
+++ b/sw/source/uibase/uiview/view.cxx
@@ -121,6 +121,7 @@
 #include <svx/svdview.hxx>
 #include <node2lay.hxx>
 #include <cntfrm.hxx>
+#include <IDocumentRedlineAccess.hxx>
 
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::uno;
@@ -862,6 +863,9 @@ SwView::SwView(SfxViewFrame& _rFrame, SfxViewShell* pOldSh)
     SvtLinguConfig().GetOptions( aLinguOpt );
     aUsrPref.SetOnlineSpell( aLinguOpt.bIsSpellAuto );
 
+    // Inherit the per-view setting from the per-document one.
+    
aUsrPref.SetRedlineRecordingOn(rDocSh.GetDoc()->getIDocumentRedlineAccess().IsRedlineOn());
+
     bool bOldShellWasSrcView = false;
 
     // determine if there is an existing view for

Reply via email to