summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorJustin Luth <justin.luth@collabora.com>2023-04-27 17:03:48 -0400
committerJustin Luth <jluth@mail.com>2023-05-18 17:56:39 +0200
commit4dfe107409f977b545f2ff5cda615ec12be2bf95 (patch)
tree007c21470709f171ff8d71a1c40d786ba8569eb0 /sw
parent33d984bb205d710a33303502884cda6d105a0d14 (diff)
tdf#86630 sw page number wizard: allow wizard to be re-run
This is a squashed commit including 47016a3374af6effb795ada4efa9fb682b566e25 Fix typo First delete what a previous run of the wizard inserted, then re-insert the page number. Change-Id: I1cbf1a7a40e71a13a06a174fd662eccfe8298e28 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151148 Tested-by: Jenkins Reviewed-by: Justin Luth <jluth@mail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151903 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/source/uibase/shells/textfld.cxx49
1 files changed, 48 insertions, 1 deletions
diff --git a/sw/source/uibase/shells/textfld.cxx b/sw/source/uibase/shells/textfld.cxx
index 5f1f1e821573..f50918838c33 100644
--- a/sw/source/uibase/shells/textfld.cxx
+++ b/sw/source/uibase/shells/textfld.cxx
@@ -1047,10 +1047,24 @@ FIELD_INSERT:
const size_t nPageDescIndex = rSh.GetCurPageDesc();
const SwPageDesc& rDesc = rSh.GetPageDesc(nPageDescIndex);
+ const bool bHeader = !pDlg->GetPageNumberPosition();
const bool bHeaderAlreadyOn = rDesc.GetMaster().GetHeader().IsActive();
const bool bFooterAlreadyOn = rDesc.GetMaster().GetFooter().IsActive();
const bool bIsSinglePage = rDesc.GetFollow() != &rDesc;
const size_t nMirrorPagesNeeded = rDesc.IsFirstShared() ? 2 : 3;
+ const OUString sBookmarkName = OUString::Concat("PageNumWizard_")
+ + (bHeader ? "HEADER" : "FOOTER") + "_" + rDesc.GetName();
+ IDocumentMarkAccess& rIDMA = *rSh.getIDocumentMarkAccess();
+
+ // Allow wizard to be re-run: delete previously wizard-inserted page number.
+ // Try before creating non-shared header: avoid copying ODD bookmark onto EVEN page.
+ IDocumentMarkAccess::const_iterator_t ppMark = rIDMA.findMark(
+ sBookmarkName + OUString::number(rSh.GetVirtPageNum()));
+ if (ppMark != rIDMA.getAllMarksEnd() && *ppMark)
+ {
+ SwPaM aDeleteOldPageNum((*ppMark)->GetMarkStart(), (*ppMark)->GetMarkEnd());
+ rDoc->getIDocumentContentOperations().DeleteAndJoin(aDeleteOldPageNum);
+ }
SvxPageItem aPageItem(SID_ATTR_PAGE);
aPageItem.SetNumType(pDlg->GetPageNumberType());
@@ -1065,7 +1079,6 @@ FIELD_INSERT:
{ &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)
@@ -1142,6 +1155,15 @@ FIELD_INSERT:
assert(bInHF && "shouldn't have a problem going to text when no mirroring");
}
+ // Allow wizard to be re-run: delete previously wizard-inserted page number.
+ // Now that the cursor may have moved to a different page, try delete again.
+ ppMark = rIDMA.findMark(sBookmarkName + OUString::number(rSh.GetVirtPageNum()));
+ if (ppMark != rIDMA.getAllMarksEnd() && *ppMark)
+ {
+ SwPaM aDeleteOldPageNum((*ppMark)->GetMarkStart(), (*ppMark)->GetMarkEnd());
+ rDoc->getIDocumentContentOperations().DeleteAndJoin(aDeleteOldPageNum);
+ }
+
SwTextNode* pTextNode = rSh.GetCursor()->GetPoint()->GetNode().GetTextNode();
// Insert new line if there is already text in header/footer
@@ -1185,11 +1207,27 @@ FIELD_INSERT:
OUString(), OUString(), SVX_NUM_PAGEDESC);
aMgr.InsertField(aData);
+ SwPaM aNewBookmarkPaM(*rSh.GetCursor()->Start());
+ aNewBookmarkPaM.SetMark();
+ rSh.GetCursor()->Left(1);
+ *aNewBookmarkPaM.Start() = *rSh.GetCursor()->Start();
+ rIDMA.makeMark(aNewBookmarkPaM,
+ sBookmarkName + OUString::number(rSh.GetVirtPageNum()),
+ IDocumentMarkAccess::MarkType::BOOKMARK,
+ sw::mark::InsertMode::New);
+
// Mirror on the even pages
if (!bSkipMirror && bCreateMirror
&& rSh.SetCursorInHdFt(nPageDescIndex, bHeader, /*Even=*/true))
{
assert(nEvenPage && "what? no even page and yet we got here?");
+ ppMark = rIDMA.findMark(sBookmarkName + OUString::number(rSh.GetVirtPageNum()));
+ if (ppMark != rIDMA.getAllMarksEnd() && *ppMark)
+ {
+ SwPaM aDeleteOldPageNum((*ppMark)->GetMarkStart(), (*ppMark)->GetMarkEnd());
+ rDoc->getIDocumentContentOperations().DeleteAndJoin(aDeleteOldPageNum);
+ }
+
pTextNode = rSh.GetCursor()->GetPoint()->GetNode().GetTextNode();
// Insert new line if there is already text in header/footer
@@ -1212,6 +1250,15 @@ FIELD_INSERT:
// Insert page number
SwFieldMgr aEvenMgr(pShell);
aEvenMgr.InsertField(aData);
+
+ SwPaM aNewEvenBookmarkPaM(*rSh.GetCursor()->Start());
+ aNewEvenBookmarkPaM.SetMark();
+ rSh.GetCursor()->Left(1);
+ *aNewEvenBookmarkPaM.Start() = *rSh.GetCursor()->Start();
+ rIDMA.makeMark(aNewEvenBookmarkPaM,
+ sBookmarkName + OUString::number(rSh.GetVirtPageNum()),
+ IDocumentMarkAccess::MarkType::BOOKMARK,
+ sw::mark::InsertMode::New);
}
rSh.SwCursorShell::Pop(SwCursorShell::PopMode::DeleteCurrent);