sw/source/uibase/shells/textfld.cxx |   38 +++++++++++++++++++-----------------
 1 file changed, 21 insertions(+), 17 deletions(-)

New commits:
commit 9f446595a3237351d934687938284eea8cd9dec1
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Wed Apr 26 12:05:15 2023 -0400
Commit:     Justin Luth <jl...@mail.com>
CommitDate: Thu May 18 17:55:07 2023 +0200

    tdf#86630 sw page number wizard: only turn on current page footer
    
    Without specifying the name of the page style,
    all in-use page styles were having the header or footer enabled.
    That was not the intent.
    
    Change-Id: I5eadd73cb2d7e11b6a003826b5698e22df3f13c1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151133
    Reviewed-by: Justin Luth <jl...@mail.com>
    Tested-by: Jenkins
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151900
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>

diff --git a/sw/source/uibase/shells/textfld.cxx 
b/sw/source/uibase/shells/textfld.cxx
index f9d091cce3cf..93f19ca4e0dd 100644
--- a/sw/source/uibase/shells/textfld.cxx
+++ b/sw/source/uibase/shells/textfld.cxx
@@ -37,6 +37,7 @@
 #include <svx/hlnkitem.hxx>
 #include <svx/svxdlg.hxx>
 #include <osl/diagnose.h>
+#include <fmthdft.hxx>
 #include <fmtinfmt.hxx>
 #include <fldwrap.hxx>
 #include <redline.hxx>
@@ -1044,11 +1045,10 @@ FIELD_INSERT:
                 rSh.SwCursorShell::Push();
                 
rDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::INSERT_PAGE_NUMBER, nullptr);
 
-                // Insert header/footer
-                bool bFooter = (pDlg->GetPageNumberPosition() == 1);
-                sal_uInt16 nPageNumberPosition = bFooter ?
-                    FN_INSERT_PAGEFOOTER : FN_INSERT_PAGEHEADER;
-                SfxBoolItem aItem(FN_PARAM_1, true);
+                const size_t nPageDescIndex = rSh.GetCurPageDesc();
+                const SwPageDesc& rDesc = rSh.GetPageDesc(nPageDescIndex);
+                const bool bHeaderAlreadyOn = 
rDesc.GetMaster().GetHeader().IsActive();
+                const bool bFooterAlreadyOn = 
rDesc.GetMaster().GetFooter().IsActive();
 
                 SvxPageItem aPageItem(SID_ATTR_PAGE);
                 aPageItem.SetNumType(pDlg->GetPageNumberType());
@@ -1056,13 +1056,17 @@ FIELD_INSERT:
                                                           SfxCallMode::API | 
SfxCallMode::SYNCHRON,
                                                           { &aPageItem });
 
+                // Insert header/footer
+                const bool bHeader = !pDlg->GetPageNumberPosition();
+                if (bHeader && !bHeaderAlreadyOn)
+                    rSh.ChangeHeaderOrFooter(rDesc.GetName(), bHeader, 
/*On=*/true, /*Warn=*/false);
+                else if (!bHeader && !bFooterAlreadyOn)
+                    rSh.ChangeHeaderOrFooter(rDesc.GetName(), false, 
/*On=*/true, /*Warn=*/false);
 
-
-                rSh.GetView().GetDispatcher().ExecuteList(
-                    nPageNumberPosition,
-                    SfxCallMode::API | SfxCallMode::SYNCHRON,
-                    {&aItem}
-                );
+                if (bHeader)
+                    rSh.GotoHeaderText();
+                else
+                    rSh.GotoFooterText();
 
                 SwTextNode* pTextNode = 
rSh.GetCursor()->GetPoint()->GetNode().GetTextNode();
 
@@ -1070,13 +1074,13 @@ FIELD_INSERT:
                 if (pTextNode && !pTextNode->GetText().isEmpty())
                 {
                     
rDoc->getIDocumentContentOperations().SplitNode(*rSh.GetCursor()->GetPoint(), 
false);
-                }
 
-                // Go back to start of header/footer
-                if (bFooter)
-                    rSh.GotoFooterText();
-                else
-                    rSh.GotoHeaderText();
+                    // Go back to start of header/footer
+                    if (bHeader)
+                        rSh.GotoHeaderText();
+                    else
+                        rSh.GotoFooterText();
+                }
 
                 // Set alignment for the new line
                 switch (pDlg->GetPageNumberAlignment())

Reply via email to