sw/source/uibase/shells/textfld.cxx | 38 +++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-)
New commits: commit a3a758350e92a3084d2cbef05ca6caef899746a4 Author: Justin Luth <justin.l...@collabora.com> AuthorDate: Wed Apr 26 12:05:15 2023 -0400 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Fri Apr 28 08:06:44 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 diff --git a/sw/source/uibase/shells/textfld.cxx b/sw/source/uibase/shells/textfld.cxx index 6e6cf9455724..bee499cd57f8 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> @@ -1047,24 +1048,27 @@ 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()); GetView().GetViewFrame().GetBindings().GetDispatcher()->ExecuteList( SID_ATTR_PAGE, SfxCallMode::RECORD, { &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(); @@ -1072,13 +1076,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())