sw/inc/strings.hrc | 3 sw/inc/swundo.hxx | 2 sw/source/core/undo/undobj.cxx | 6 + sw/source/uibase/utlui/content.cxx | 103 ++++++++++++++++--------- sw/uiconfig/swriter/ui/navigatorcontextmenu.ui | 16 +++ 5 files changed, 96 insertions(+), 34 deletions(-)
New commits: commit 1b49aa0bad6d1fce29f27112991ddd839600cd0d Author: Jim Raykowski <rayk...@gmail.com> AuthorDate: Mon Nov 11 22:34:48 2024 -0900 Commit: Jim Raykowski <rayk...@gmail.com> CommitDate: Tue Nov 12 20:01:47 2024 +0100 tdf#89352 Allow user to change all Footnotes to Endnotes and vice versa through use of context menu entries in the Writer Navigator Footnotes and Endnotes content types Change-Id: I2c7b6d01013023702f9272e222b76a83710ca6f1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176495 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> Reviewed-by: Jim Raykowski <rayk...@gmail.com> diff --git a/sw/inc/strings.hrc b/sw/inc/strings.hrc index 88fa5c9ec865..7542f716e8b4 100644 --- a/sw/inc/strings.hrc +++ b/sw/inc/strings.hrc @@ -1545,6 +1545,9 @@ #define STR_BACKGROUND_BITMAP NC_("STR_BACKGROUND_BITMAP", "Background bitmap") #define STR_BACKGROUND_PATTERN NC_("STR_BACKGROUND_PATTERN", "Background pattern") +#define STR_UNDO_MAKE_FOOTNOTES_ENDNOTES NC_("STR_UNDO_MAKE_FOOTNOTES_ENDNOTES", "Make all footnotes endnotes") +#define STR_UNDO_MAKE_ENDNOTES_FOOTNOTES NC_("STR_UNDO_MAKE_ENDNOTES_FOOTNOTES", "Make all endnotes footnotes") + #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/inc/swundo.hxx b/sw/inc/swundo.hxx index dc91de5aff4d..4641f0e9e9af 100644 --- a/sw/inc/swundo.hxx +++ b/sw/inc/swundo.hxx @@ -180,6 +180,8 @@ enum class SwUndoId CHANGE_THEME = 148, DELETE_SECTIONS = 149, FLYFRMFMT_DECORATIVE = 150, + MAKE_FOOTNOTES_ENDNOTES = 151, + MAKE_ENDNOTES_FOOTNOTES = 152, }; OUString GetUndoComment(SwUndoId eId); diff --git a/sw/source/core/undo/undobj.cxx b/sw/source/core/undo/undobj.cxx index ed4dc2dcc8e3..5be5ab479445 100644 --- a/sw/source/core/undo/undobj.cxx +++ b/sw/source/core/undo/undobj.cxx @@ -685,6 +685,12 @@ OUString GetUndoComment(SwUndoId eId) case SwUndoId::FLYFRMFMT_DECORATIVE: pId = STR_UNDO_FLYFRMFMT_DECORATIVE; break; + case SwUndoId::MAKE_FOOTNOTES_ENDNOTES: + pId = STR_UNDO_MAKE_FOOTNOTES_ENDNOTES; + break; + case SwUndoId::MAKE_ENDNOTES_FOOTNOTES: + pId = STR_UNDO_MAKE_ENDNOTES_FOOTNOTES; + break; } assert(pId); diff --git a/sw/source/uibase/utlui/content.cxx b/sw/source/uibase/utlui/content.cxx index 8f43e6cc8186..8cd40cf97914 100644 --- a/sw/source/uibase/utlui/content.cxx +++ b/sw/source/uibase/utlui/content.cxx @@ -229,6 +229,43 @@ namespace { return weld::fromId<const SwRegionContent*>(rTreeView.get_id(rEntry))->GetRegionLevel() < nLevel; } + + void lcl_SelectAllFootnotesOrEndnotes(SwWrtShell& rWrtShell, SwContentType* pContentType) + { + const auto nCount = pContentType->GetMemberCount(); + if (nCount == 0) + return; + + rWrtShell.AssureStdMode(); + SwCursor* pCursor = rWrtShell.getShellCursor(true); + + rWrtShell.StartAction(); + rWrtShell.EnterAddMode(); + for (size_t i = 0; i < nCount; i++) + { + const SwTextFootnoteContent* pTextFootnoteCnt + = static_cast<const SwTextFootnoteContent*>(pContentType->GetMember(i)); + if (pTextFootnoteCnt && !pTextFootnoteCnt->IsInvisible()) + { + if (const SwTextAttr* pTextAttr = pTextFootnoteCnt->GetTextFootnote()) + { + const SwTextFootnote* pTextFootnote + = pTextAttr->GetFootnote().GetTextFootnote(); + if (!pTextFootnote) + continue; + const SwTextNode& rTextNode = pTextFootnote->GetTextNode(); + auto nStart = pTextAttr->GetStart(); + pCursor->GetPoint()->Assign(rTextNode, nStart + 1); + rWrtShell.SetMark(); + rWrtShell.SttSelect(); + pCursor->GetPoint()->Assign(rTextNode, nStart); + rWrtShell.EndSelect(); + } + } + } + rWrtShell.LeaveAddMode(); + rWrtShell.EndAction(); + } } // Content, contains names and reference at the content type. @@ -1729,6 +1766,8 @@ IMPL_LINK(SwContentTree, CommandHdl, const CommandEvent&, rCEvt, bool) bRemoveDeleteFootnoteEntry = true, bRemoveDeleteAllEndnotesEntry = true, bRemoveDeleteEndnoteEntry = true; + bool bRemoveMakeAllFootnotesEndnotesEntry = true, + bRemoveMakeAllEndnotesFootnotesEntry = true; bool bRemoveRenameEntry = true; bool bRemoveSelectEntry = true; bool bRemoveToggleExpandEntry = true; @@ -2033,9 +2072,11 @@ IMPL_LINK(SwContentTree, CommandHdl, const CommandEvent&, rCEvt, bool) break; case ContentTypeId::FOOTNOTE: bRemoveDeleteAllFootnotesEntry = false; + bRemoveMakeAllFootnotesEndnotesEntry = false; break; case ContentTypeId::ENDNOTE: bRemoveDeleteAllEndnotesEntry = false; + bRemoveMakeAllEndnotesFootnotesEntry = false; break; default: break; } @@ -2136,7 +2177,11 @@ IMPL_LINK(SwContentTree, CommandHdl, const CommandEvent&, rCEvt, bool) if (bRemoveDeleteEndnoteEntry) xPop->remove(u"deleteendnote"_ustr); - // bRemoveDeleteEntry is used in determining separator 2 + if (bRemoveMakeAllFootnotesEndnotesEntry) + xPop->remove(u"makeallfootnotesendnotes"_ustr); + if (bRemoveMakeAllEndnotesFootnotesEntry) + xPop->remove(u"makeallendnotesfootnotes"_ustr); + bool bRemoveDeleteEntry = bRemoveDeleteChapterEntry && bRemoveDeleteTableEntry && @@ -2168,6 +2213,10 @@ IMPL_LINK(SwContentTree, CommandHdl, const CommandEvent&, rCEvt, bool) bRemoveDeleteAllFootnotesEntry && bRemoveDeleteAllEndnotesEntry; + bool bRemoveMakeFootnotesEndnotesViceVersaEntry = + bRemoveMakeAllFootnotesEndnotesEntry && + bRemoveMakeAllEndnotesFootnotesEntry; + if (bRemoveRenameEntry) xPop->remove(OUString::number(502)); @@ -2194,6 +2243,7 @@ IMPL_LINK(SwContentTree, CommandHdl, const CommandEvent&, rCEvt, bool) bRemoveCopyEntry && bRemoveSelectEntry && bRemoveDeleteEntry && + bRemoveMakeFootnotesEndnotesViceVersaEntry && bRemoveChapterEntries && bRemovePostItEntries && bRemoveRenameEntry && @@ -5416,6 +5466,23 @@ IMPL_LINK(SwContentTree, QueryTooltipHdl, const weld::TreeIter&, rEntry, OUStrin void SwContentTree::ExecuteContextMenuAction(const OUString& rSelectedPopupEntry) { + if (rSelectedPopupEntry == "makeallfootnotesendnotes" + || rSelectedPopupEntry == "makeallendnotesfootnotes") + { + std::unique_ptr<weld::TreeIter> xEntryIter(m_xTreeView->make_iterator()); + if (!m_xTreeView->get_selected(xEntryIter.get())) + return; // this shouldn't happen + SwContentType* pContentType = weld::fromId<SwContentType*>(m_xTreeView->get_id(*xEntryIter)); + m_pActiveShell->StartUndo(rSelectedPopupEntry == "makeallfootnotesendnotes" + ? SwUndoId::MAKE_FOOTNOTES_ENDNOTES + : SwUndoId::MAKE_ENDNOTES_FOOTNOTES); + lcl_SelectAllFootnotesOrEndnotes(*m_pActiveShell, pContentType); + SwFormatFootnote aNote(rSelectedPopupEntry == "makeallfootnotesendnotes"); + m_pActiveShell->SetCurFootnote(aNote); + m_pActiveShell->EndUndo(); + return; + } + if (rSelectedPopupEntry == "copy") { CopyOutlineSelections(); @@ -6452,39 +6519,7 @@ void SwContentTree::DeleteAllContentOfEntryContentType(const weld::TreeIter& rEn else if (eContentTypeId == ContentTypeId::FOOTNOTE || eContentTypeId == ContentTypeId::ENDNOTE) { //MakeAllOutlineContentTemporarilyVisible a(m_pActiveShell->GetDoc()); - - m_pActiveShell->AssureStdMode(); - - SwCursor* pCursor = m_pActiveShell->getShellCursor(true); - - const auto nCount = pContentType->GetMemberCount(); - - m_pActiveShell->StartAction(); - m_pActiveShell->EnterAddMode(); - for (size_t i = 0; i < nCount; i++) - { - const SwTextFootnoteContent* pTextFootnoteCnt = - static_cast<const SwTextFootnoteContent*>(pContentType->GetMember(i)); - if (pTextFootnoteCnt && !pTextFootnoteCnt->IsInvisible()) - { - if (const SwTextAttr* pTextAttr = pTextFootnoteCnt->GetTextFootnote()) - { - const SwTextFootnote* pTextFootnote = pTextAttr->GetFootnote().GetTextFootnote(); - if (!pTextFootnote) - continue; - const SwTextNode& rTextNode = pTextFootnote->GetTextNode(); - auto nStart = pTextAttr->GetStart(); - pCursor->GetPoint()->Assign(rTextNode, nStart + 1); - m_pActiveShell->SetMark(); - m_pActiveShell->SttSelect(); - pCursor->GetPoint()->Assign(rTextNode, nStart); - m_pActiveShell->EndSelect(); - } - } - } - m_pActiveShell->LeaveAddMode(); - m_pActiveShell->EndAction(); - + lcl_SelectAllFootnotesOrEndnotes(*m_pActiveShell, pContentType); SwRewriter aRewriter; aRewriter.AddRule(UndoArg1, pContentType->GetName()); m_pActiveShell->StartUndo(SwUndoId::DELETE, &aRewriter); diff --git a/sw/uiconfig/swriter/ui/navigatorcontextmenu.ui b/sw/uiconfig/swriter/ui/navigatorcontextmenu.ui index da10303b7ca0..530da9796c21 100644 --- a/sw/uiconfig/swriter/ui/navigatorcontextmenu.ui +++ b/sw/uiconfig/swriter/ui/navigatorcontextmenu.ui @@ -381,6 +381,22 @@ <accelerator key="Delete" signal="activate"/> </object> </child> + <child> + <object class="GtkMenuItem" id="makeallfootnotesendnotes"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="label" translatable="yes" context="navigatorcontextmenu|STR_MAKE_ALL_FOOTNOTES_ENDNOTES">Make All Footnotes Endnotes</property> + <property name="use-underline">True</property> + </object> + </child> + <child> + <object class="GtkMenuItem" id="makeallendnotesfootnotes"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="label" translatable="yes" context="navigatorcontextmenu|STR_MAKE_ALL_ENDNOTES_FOOTNOTES">Make All Endnotes Footnotes</property> + <property name="use-underline">True</property> + </object> + </child> <child> <object class="GtkMenuItem" id="502"> <property name="visible">True</property>