sw/qa/uibase/uiview/uiview.cxx          |   37 ++++++++++++++++++++++++++++++++
 sw/source/uibase/uiview/viewstat.cxx    |    1 
 sw/uiconfig/swriter/menubar/menubar.xml |    1 
 3 files changed, 39 insertions(+)

New commits:
commit 6257cae9e9845ea110b2b7abfad2b2672e966bbb
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Wed Mar 26 08:39:55 2025 +0100
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Wed Mar 26 09:37:01 2025 +0100

    cool#11357 sw redline reinstate: add command state
    
    Go outside a redline with your cursor, the accept and reject UNO
    commands report disabled state, but reinstate is enabled all the time.
    
    This happens because SwView::GetState() handles FN_REDLINE_ACCEPT_DIRECT
    / FN_REDLINE_REJECT_DIRECT explicitly.
    
    Fix the problem by handling FN_REDLINE_REINSTATE_DIRECT the same way: if
    reject is disabled, then reinstate ("reject with history") is also OK to
    be disabled.
    
    With this, reinstate is mostly usable, so add it to the Edit -> Track
    changes menu.
    
    Change-Id: Ic534bc314f0910b1a8376cabe944bfb6f0bc6953
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183325
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>

diff --git a/sw/qa/uibase/uiview/uiview.cxx b/sw/qa/uibase/uiview/uiview.cxx
index 5f41aa920c02..3dcd858c1e0f 100644
--- a/sw/qa/uibase/uiview/uiview.cxx
+++ b/sw/qa/uibase/uiview/uiview.cxx
@@ -32,6 +32,7 @@
 #include <wrtsh.hxx>
 #include <swmodule.hxx>
 #include <view.hxx>
+#include <IDocumentRedlineAccess.hxx>
 
 /// Covers sw/source/uibase/uiview/ fixes.
 class SwUibaseUiviewTest : public SwModelTestBase
@@ -354,6 +355,42 @@ CPPUNIT_TEST_FIXTURE(SwUibaseUiviewTest, 
testEditInReadonly)
     //status default in editable section
     CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT, eState);
 }
+
+CPPUNIT_TEST_FIXTURE(SwUibaseUiviewTest, testReinstateTrackedChangeState)
+{
+    // Given a document with a deletion:
+    createSwDoc();
+    SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
+    pWrtShell->Insert("abcd");
+    RedlineFlags nMode = pWrtShell->GetRedlineFlags();
+    pWrtShell->SetRedlineFlags(nMode | RedlineFlags::On);
+    pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, 
/*bBasicCall=*/false);
+    pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/true, 2, 
/*bBasicCall=*/false);
+    pWrtShell->DelRight();
+
+    // When the cursor is inside a redline:
+    pWrtShell->SttPara(/*bSelect=*/false);
+    pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/false, 2, 
/*bBasicCall=*/false);
+
+    // Then make sure that reinstate is enabled:
+    SwView* pView = getSwDocShell()->GetView();
+    std::unique_ptr<SfxPoolItem> pItem;
+    SfxItemState eState
+        = 
pView->GetViewFrame().GetBindings().QueryState(FN_REDLINE_REINSTATE_DIRECT, 
pItem);
+    CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT, eState);
+
+    // When the cursor is outside a redline:
+    pWrtShell->SttPara(/*bSelect=*/false);
+
+    // Then make sure that reinstate is disabled:
+    eState = 
pView->GetViewFrame().GetBindings().QueryState(FN_REDLINE_REINSTATE_DIRECT, 
pItem);
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: 1 (DISABLED)
+    // - Actual  : 32 (DEFAULT)
+    // i.e. reinstate was always enabled.
+    CPPUNIT_ASSERT_EQUAL(SfxItemState::DISABLED, eState);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/uiview/viewstat.cxx 
b/sw/source/uibase/uiview/viewstat.cxx
index 526c7f8e0fa6..a6f49ed91a04 100644
--- a/sw/source/uibase/uiview/viewstat.cxx
+++ b/sw/source/uibase/uiview/viewstat.cxx
@@ -391,6 +391,7 @@ void SwView::GetState(SfxItemSet &rSet)
             break;
             case FN_REDLINE_ACCEPT_DIRECT:
             case FN_REDLINE_REJECT_DIRECT:
+            case FN_REDLINE_REINSTATE_DIRECT:
             case FN_REDLINE_ACCEPT_TONEXT:
             case FN_REDLINE_REJECT_TONEXT:
             {
diff --git a/sw/uiconfig/swriter/menubar/menubar.xml 
b/sw/uiconfig/swriter/menubar/menubar.xml
index 55084344f59e..76ceac8bf705 100644
--- a/sw/uiconfig/swriter/menubar/menubar.xml
+++ b/sw/uiconfig/swriter/menubar/menubar.xml
@@ -138,6 +138,7 @@
           <menu:menuitem menu:id=".uno:RejectTrackedChange"/>
           <menu:menuitem menu:id=".uno:RejectTrackedChangeToNext"/>
           <menu:menuitem menu:id=".uno:RejectAllTrackedChanges"/>
+          <menu:menuitem menu:id=".uno:ReinstateTrackedChange"/>
           <menu:menuseparator/>
           <menu:menuitem menu:id=".uno:CommentChangeTracking"/>
           <menu:menuitem menu:id=".uno:ProtectTraceChangeMode"/>

Reply via email to