sw/source/uibase/inc/redlndlg.hxx  |    2 +
 sw/source/uibase/misc/redlndlg.cxx |   39 ++++++++++++++-----------------------
 2 files changed, 17 insertions(+), 24 deletions(-)

New commits:
commit baac4aadebf20fcd2b68a9e867534eab332b0976
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Thu Jun 19 12:22:02 2025 +0500
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Fri Jun 20 20:18:58 2025 +0200

    tdf#167128: SwRedlineAcceptDlg: move enabling controls after selection
    
    It was done in InitAuthors, which was called before lcl_reselect;
    and therefore, opening the dialog would not see the selection, and
    not activate buttons properly.
    
    Now the "Accept" and "Reject" are active upon dialog opening, when
    there is a selection.
    
    This required extracting the respective code to a separate function.
    
    Change-Id: I3a02384b402312613fef4b2d3932d19c9b1acc19
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186752
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186767

diff --git a/sw/source/uibase/inc/redlndlg.hxx 
b/sw/source/uibase/inc/redlndlg.hxx
index 68ee1774af99..07016a4b84f9 100644
--- a/sw/source/uibase/inc/redlndlg.hxx
+++ b/sw/source/uibase/inc/redlndlg.hxx
@@ -50,6 +50,7 @@ struct SwRedlineDataParent
 };
 
 class SwRedlineDataParentSortArr : public 
o3tl::sorted_vector<SwRedlineDataParent*, o3tl::less_ptr_to > {};
+class SwView;
 
 class SW_DLLPUBLIC SwRedlineAcceptDlg final : public SfxListener
 {
@@ -101,6 +102,7 @@ class SW_DLLPUBLIC SwRedlineAcceptDlg final : public 
SfxListener
     SAL_DLLPRIVATE void          InsertParents(SwRedlineTable::size_type 
nStart, SwRedlineTable::size_type nEnd = SwRedlineTable::npos);
     SAL_DLLPRIVATE void          RemoveParents(SwRedlineTable::size_type 
nStart, SwRedlineTable::size_type nEnd);
     SAL_DLLPRIVATE void          InitAuthors();
+    SAL_DLLPRIVATE void          EnableControls(const SwView* pView);
 
     SAL_DLLPRIVATE static const OUString & GetActionImage(const 
SwRangeRedline& rRedln, sal_uInt16 nStack = 0,
                                                   bool bTableChanges = false, 
bool bRowChanges = false);
diff --git a/sw/source/uibase/misc/redlndlg.cxx 
b/sw/source/uibase/misc/redlndlg.cxx
index 2ad441d1c5e7..dfe34011b081 100644
--- a/sw/source/uibase/misc/redlndlg.cxx
+++ b/sw/source/uibase/misc/redlndlg.cxx
@@ -309,6 +309,7 @@ void SwRedlineAcceptDlg::Init(SwRedlineTable::size_type 
nStart)
     InitAuthors();
 
     lcl_reselect(rTreeView, pSelectedEntryRedlineData);
+    EnableControls(pView);
 }
 
 void SwRedlineAcceptDlg::InitAuthors()
@@ -330,7 +331,6 @@ void SwRedlineAcceptDlg::InitAuthors()
     SwRedlineTable::size_type nCount = pSh ? pSh->GetRedlineCount() : 0;
 
     m_bOnlyFormatedRedlines = true;
-    bool bIsNotFormated = false;
 
     // determine authors
     for ( SwRedlineTable::size_type i = 0; i < nCount; i++)
@@ -356,6 +356,15 @@ void SwRedlineAcceptDlg::InitAuthors()
 
     if (pFilterPage->SelectAuthor(sOldAuthor) == -1 && !aStrings.empty())
         pFilterPage->SelectAuthor(aStrings[0]);
+}
+
+void SwRedlineAcceptDlg::EnableControls(const SwView* pView)
+{
+    if (!pView)
+        return;
+    SwWrtShell* pSh = pView->GetWrtShellPtr();
+    if (!pSh)
+        return;
 
     weld::TreeView& rTreeView = m_pTable->GetWidget();
     SwDocShell* pShell = pSh ? pSh->GetDoc()->GetDocShell() : nullptr;
@@ -364,6 +373,7 @@ void SwRedlineAcceptDlg::InitAuthors()
         && 
!pSh->getIDocumentRedlineAccess().GetRedlinePassword().hasElements();
     bool bSel = rTreeView.get_selected(nullptr);
 
+    bool bIsNotFormated = false;
     rTreeView.selected_foreach([this, pSh, &bIsNotFormated](weld::TreeIter& 
rEntry){
         // find the selected redline
         // (fdo#57874: ignore, if the redline is already gone)
@@ -464,7 +474,7 @@ void SwRedlineAcceptDlg::Activate()
         m_pTPView->EnableAcceptAll(false);
         m_pTPView->EnableRejectAll(false);
         m_pTPView->EnableClearFormatAll(false);
-        // note: enabling is done in InitAuthors below
+        // note: enabling is done in EnableControls below
     }
 
     m_aUsedSeqNo.clear();
@@ -576,6 +586,7 @@ void SwRedlineAcceptDlg::Activate()
     InitAuthors();
 
     lcl_reselect(rTreeView, pSelectedEntryRedlineData);
+    EnableControls(pView);
 }
 
 void SwRedlineAcceptDlg::Notify(SfxBroadcaster& /*rBC*/, const SfxHint& rHint)
@@ -1306,9 +1317,6 @@ IMPL_LINK_NOARG(SwRedlineAcceptDlg, GotoHdl, Timer *, 
void)
     if (!pSh)
         return;
 
-    bool bIsNotFormated = false;
-    bool bSel = false;
-
     //#98883# don't select redlines while the dialog is not focused
     //#107938# But not only ask pTable if it has the focus. To move
     //         the selection to the selected redline any child of pParentDlg
@@ -1323,7 +1331,7 @@ IMPL_LINK_NOARG(SwRedlineAcceptDlg, GotoHdl, Timer *, 
void)
             pSh->EnterStdMode();
             SwViewShell::SetCareDialog(m_xParentDlg);
 
-            rTreeView.selected_foreach([this, pSh, &rTreeView, &xActEntry, 
&bIsNotFormated, &bSel](weld::TreeIter& rEntry){
+            rTreeView.selected_foreach([this, pSh, &rTreeView, 
&xActEntry](weld::TreeIter& rEntry){
                 rTreeView.copy_iterator(rEntry, *xActEntry);
                 if (rTreeView.get_iter_depth(rEntry))
                 {
@@ -1331,17 +1339,11 @@ IMPL_LINK_NOARG(SwRedlineAcceptDlg, GotoHdl, Timer *, 
void)
                     if (rTreeView.is_selected(*xActEntry))
                         return false;   // don't select twice
                 }
-                else
-                    bSel = true;
 
                 // #98864# find the selected redline (ignore, if the redline 
is already gone)
                 SwRedlineTable::size_type nPos = GetRedlinePos(*xActEntry);
                 if (nPos != SwRedlineTable::npos)
                 {
-
-                    const SwRangeRedline& rRedln = pSh->GetRedline( nPos );
-                    bIsNotFormated |= RedlineType::Format != rRedln.GetType();
-
                     if (pSh->GotoRedline(nPos, true))
                     {
                         pSh->SetInSelect();
@@ -1362,9 +1364,6 @@ IMPL_LINK_NOARG(SwRedlineAcceptDlg, GotoHdl, Timer *, 
void)
                             nPos = GetRedlinePos(*xChild);
                             if (nPos != SwRedlineTable::npos)
                             {
-                                const SwRangeRedline& rRedln = 
pSh->GetRedline( nPos );
-                                bIsNotFormated |= RedlineType::Format != 
rRedln.GetType();
-
                                 if (pSh->GotoRedline(nPos, true))
                                 {
                                     pSh->SetInSelect();
@@ -1384,15 +1383,7 @@ IMPL_LINK_NOARG(SwRedlineAcceptDlg, GotoHdl, Timer *, 
void)
         }
     }
 
-    SwDocShell* pShell = pSh->GetDoc()->GetDocShell();
-    bool const bEnable = pShell && !pShell->IsReadOnly()
-        && 
!pSh->getIDocumentRedlineAccess().GetRedlinePassword().hasElements();
-    m_pTPView->EnableAccept( bEnable && bSel /*&& !bReadonlySel*/ );
-    m_pTPView->EnableReject( bEnable && bSel /*&& !bReadonlySel*/ );
-    m_pTPView->EnableClearFormat( bEnable && bSel && !bIsNotFormated /*&& 
!bReadonlySel*/ );
-    m_pTPView->EnableAcceptAll( bEnable );
-    m_pTPView->EnableRejectAll( bEnable );
-    m_pTPView->EnableClearFormatAll( bEnable && m_bOnlyFormatedRedlines );
+    EnableControls(pView);
 }
 
 IMPL_LINK(SwRedlineAcceptDlg, CommandHdl, const CommandEvent&, rCEvt, bool)

Reply via email to