sw/source/ui/fldui/flddb.cxx     |    2 +-
 sw/source/ui/fldui/flddinf.cxx   |    2 +-
 sw/source/ui/fldui/fldfunc.cxx   |    6 +++---
 sw/source/ui/fldui/fldpage.cxx   |   25 ++++++++++++++++---------
 sw/source/ui/fldui/fldpage.hxx   |    3 ++-
 sw/source/ui/fldui/fldref.cxx    |    2 +-
 sw/source/ui/fldui/fldtdlg.cxx   |    7 +++++++
 sw/source/ui/fldui/fldvar.cxx    |    6 +++---
 sw/source/uibase/inc/fldtdlg.hxx |    1 +
 9 files changed, 35 insertions(+), 19 deletions(-)

New commits:
commit 157d71689ce1878a142118cdc7fd09b499cb07e3
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Mon Jul 8 10:39:51 2024 +0100
Commit:     Adolfo Jayme Barrientos <fit...@ubuntu.com>
CommitDate: Sat Jul 13 20:22:05 2024 +0200

    Resolves: tdf#161478 Insert button not updated on switch tabs
    
    regression since:
    
    commit fbd79c6125fd302dde9af2d76171dd5ca794af4d
    Author: Caolán McNamara <caol...@redhat.com>
    Date:   Wed Mar 20 11:56:03 2019 +0000
    
        weld SwFieldDlg
    
    Change-Id: Ifb4f107bb8d4d53ae81b8ce38a87c9774112b617
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170150
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    (cherry picked from commit 7a5d0c413f37e02356d0bd1e1da7a9445ee25fe8)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170236
    Reviewed-by: Adolfo Jayme Barrientos <fit...@ubuntu.com>

diff --git a/sw/source/ui/fldui/flddb.cxx b/sw/source/ui/fldui/flddb.cxx
index 0e6374e2b45e..99af2899746b 100644
--- a/sw/source/ui/fldui/flddb.cxx
+++ b/sw/source/ui/fldui/flddb.cxx
@@ -441,7 +441,7 @@ void SwFieldDBPage::CheckInsert()
         bInsert &= bHasValue;
     }
 
-    EnableInsert(bInsert);
+    EnableInsert(bInsert, IsCurrentPage());
 }
 
 IMPL_LINK(SwFieldDBPage, TreeSelectHdl, weld::TreeView&, rBox, void)
diff --git a/sw/source/ui/fldui/flddinf.cxx b/sw/source/ui/fldui/flddinf.cxx
index 24c81eb10edb..36743339ab56 100644
--- a/sw/source/ui/fldui/flddinf.cxx
+++ b/sw/source/ui/fldui/flddinf.cxx
@@ -401,7 +401,7 @@ sal_Int32 SwFieldDokInfPage::FillSelectionLB(sal_uInt16 
nSubType)
     // fill Format-Listbox
     SwFieldTypesEnum nTypeId = SwFieldTypesEnum::DocumentInfo;
 
-    EnableInsert(nSubType != USHRT_MAX);
+    EnableInsert(nSubType != USHRT_MAX, IsCurrentPage());
 
     if (nSubType == USHRT_MAX)  // Info-Text
         nSubType = DI_SUBTYPE_BEGIN;
diff --git a/sw/source/ui/fldui/fldfunc.cxx b/sw/source/ui/fldui/fldfunc.cxx
index 0a553522985c..98fac8e93515 100644
--- a/sw/source/ui/fldui/fldfunc.cxx
+++ b/sw/source/ui/fldui/fldfunc.cxx
@@ -377,7 +377,7 @@ IMPL_LINK_NOARG(SwFieldFuncPage, TypeHdl, weld::TreeView&, 
void)
     m_xValueGroup->set_sensitive(bValue);
     m_xMacroBT->set_sensitive(bMacro);
 
-    EnableInsert( bInsert );
+    EnableInsert(bInsert, IsCurrentPage());
 }
 
 IMPL_LINK_NOARG(SwFieldFuncPage, SelectHdl, weld::TreeView&, void)
@@ -500,7 +500,7 @@ void SwFieldFuncPage::UpdateSubType()
             m_xNameED->set_text(GetFieldMgr().GetMacroName());
             m_xValueGroup->set_sensitive(true);
         }
-        EnableInsert(bHasMacro);
+        EnableInsert(bHasMacro, IsCurrentPage());
     }
 }
 
@@ -605,7 +605,7 @@ IMPL_LINK_NOARG(SwFieldFuncPage, ModifyHdl, weld::Entry&, 
void)
         (!nLen || nLen > MAX_COMBINED_CHARACTERS ))
         bEnable = false;
 
-    EnableInsert( bEnable );
+    EnableInsert(bEnable, IsCurrentPage());
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/ui/fldui/fldpage.cxx b/sw/source/ui/fldui/fldpage.cxx
index 11923d34ee93..0bf3fa640dc0 100644
--- a/sw/source/ui/fldui/fldpage.cxx
+++ b/sw/source/ui/fldui/fldpage.cxx
@@ -98,7 +98,7 @@ void SwFieldPage::Init()
 // newly initialise page
 void SwFieldPage::Activate()
 {
-    EnableInsert(m_bInsert);
+    EnableInsert(m_bInsert, true);
 }
 
 // complete reset; edit new field
@@ -318,18 +318,25 @@ void SwFieldPage::InsertHdl(weld::Widget* pBtn)
     }
 }
 
+bool SwFieldPage::IsCurrentPage() const
+{
+    if (const SwFieldDlg *pDlg = dynamic_cast<const 
SwFieldDlg*>(GetDialogController()))
+        return pDlg->GetCurTabPage() == this;
+    return true;
+}
+
 // enable/disable "Insert"-Button
-void SwFieldPage::EnableInsert(bool bEnable)
+void SwFieldPage::EnableInsert(bool bEnable, bool bIsCurrentPage)
 {
-    if (SwFieldDlg *pDlg = dynamic_cast<SwFieldDlg*>(GetDialogController()))
+    if (bIsCurrentPage)
     {
-        if (pDlg->GetCurTabPage() == this)
+        if (SwFieldDlg *pDlg = 
dynamic_cast<SwFieldDlg*>(GetDialogController()))
             pDlg->EnableInsert(bEnable);
-    }
-    else
-    {
-        SwFieldEditDlg *pEditDlg = 
static_cast<SwFieldEditDlg*>(GetDialogController());
-        pEditDlg->EnableInsert(bEnable);
+        else
+        {
+            SwFieldEditDlg *pEditDlg = 
static_cast<SwFieldEditDlg*>(GetDialogController());
+            pEditDlg->EnableInsert(bEnable);
+        }
     }
 
     m_bInsert = bEnable;
diff --git a/sw/source/ui/fldui/fldpage.hxx b/sw/source/ui/fldui/fldpage.hxx
index fbfa8cf2ba53..aad057822b6b 100644
--- a/sw/source/ui/fldui/fldpage.hxx
+++ b/sw/source/ui/fldui/fldpage.hxx
@@ -58,7 +58,8 @@ protected:
     void                Init();
     void                SavePos( const weld::TreeView& rLst1);
     void                RestorePos( weld::TreeView& rLst1 );
-    void                EnableInsert(bool bEnable);
+    bool                IsCurrentPage() const;
+    void                EnableInsert(bool bEnable, bool bIsCurrentPage);
     bool                IsFieldEdit() const   { return m_bFieldEdit; }
 
     // insert field
diff --git a/sw/source/ui/fldui/fldref.cxx b/sw/source/ui/fldui/fldref.cxx
index 672465d713d9..334f392f476f 100644
--- a/sw/source/ui/fldui/fldref.cxx
+++ b/sw/source/ui/fldui/fldref.cxx
@@ -1003,7 +1003,7 @@ IMPL_LINK_NOARG(SwFieldRefPage, ModifyHdl, weld::Entry&, 
void)
                        nTypeId == REFFLDFLAG_BOOKMARK)))
         bEnable = false;
 
-    EnableInsert(bEnable);
+    EnableInsert(bEnable, IsCurrentPage());
 
     m_xSelectionLB->select_text(aName);
 }
diff --git a/sw/source/ui/fldui/fldtdlg.cxx b/sw/source/ui/fldui/fldtdlg.cxx
index f649a24416b1..8b0d334f19fd 100644
--- a/sw/source/ui/fldui/fldtdlg.cxx
+++ b/sw/source/ui/fldui/fldtdlg.cxx
@@ -240,6 +240,13 @@ void SwFieldDlg::Activate()
     }
 }
 
+void SwFieldDlg::ActivatePage(const OUString& rPage)
+{
+    SfxTabDialogController::ActivatePage(rPage);
+    if (SfxTabPage* pPage = GetTabPage(rPage))
+        pPage->Activate();
+}
+
 void SwFieldDlg::EnableInsert(bool bEnable)
 {
     if( bEnable )
diff --git a/sw/source/ui/fldui/fldvar.cxx b/sw/source/ui/fldui/fldvar.cxx
index a950a5054529..01be468828f1 100644
--- a/sw/source/ui/fldui/fldvar.cxx
+++ b/sw/source/ui/fldui/fldvar.cxx
@@ -408,7 +408,7 @@ void SwFieldVarPage::SubTypeHdl(const weld::TreeView* pBox)
                 else
                     bFormat = false;
 
-                EnableInsert(bFormat || bNumFormat);
+                EnableInsert(bFormat || bNumFormat, IsCurrentPage());
             }
             break;
 
@@ -953,7 +953,7 @@ IMPL_LINK_NOARG(SwFieldVarPage, ModifyHdl, weld::Entry&, 
void)
 
     m_xNewPB->set_sensitive(bApply);
     m_xDelPB->set_sensitive(bDelete);
-    EnableInsert(bInsert);
+    EnableInsert(bInsert, IsCurrentPage());
 }
 
 IMPL_LINK(SwFieldVarPage, TBClickHdl, weld::Button&, rBox, void)
@@ -1123,7 +1123,7 @@ IMPL_LINK_NOARG(SwFieldVarPage, SeparatorHdl, 
weld::Entry&, void)
 {
     bool bEnable = !m_xSeparatorED->get_text().isEmpty() ||
                     m_xChapterLevelLB->get_active() == 0;
-    EnableInsert(bEnable);
+    EnableInsert(bEnable, IsCurrentPage());
 }
 
 bool SwFieldVarPage::FillItemSet(SfxItemSet* )
diff --git a/sw/source/uibase/inc/fldtdlg.hxx b/sw/source/uibase/inc/fldtdlg.hxx
index 0db155b3d54b..55de4a5db20c 100644
--- a/sw/source/uibase/inc/fldtdlg.hxx
+++ b/sw/source/uibase/inc/fldtdlg.hxx
@@ -61,6 +61,7 @@ public:
     virtual void        Close() override;
     virtual void        EndDialog(int nResponse) override;
     virtual void        Activate() override;
+    virtual void        ActivatePage(const OUString& rPage) override;
 };
 
 #endif

Reply via email to