sw/source/uibase/utlui/content.cxx | 41 +++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
New commits: commit cdc1f41d4530ad3ec553d90dad803bc5b940656c Author: Jim Raykowski <rayk...@gmail.com> AuthorDate: Sat Sep 25 21:56:48 2021 -0800 Commit: Jim Raykowski <rayk...@gmail.com> CommitDate: Thu Sep 30 05:06:00 2021 +0200 tdf#95378 Writer Navigator: Track bookmarks Resolves bookmark tracking part of the enhancement request. Makes the Navigator content tree highlight the corresponding bookmark item of the first bookmark at the currrent cursor position in the document if there is one. Change-Id: Ida9f512eda9630bd6f1e5db1658715823644969d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122619 Tested-by: Jenkins Reviewed-by: Jim Raykowski <rayk...@gmail.com> diff --git a/sw/source/uibase/utlui/content.cxx b/sw/source/uibase/utlui/content.cxx index ae46fe4272c6..954ac752c22f 100644 --- a/sw/source/uibase/utlui/content.cxx +++ b/sw/source/uibase/utlui/content.cxx @@ -99,6 +99,10 @@ #include <frameformats.hxx> +#include <unotextrange.hxx> +#include <com/sun/star/text/XTextRange.hpp> +#include <com/sun/star/text/XTextRangeCompare.hpp> + #define CTYPE_CNT 0 #define CTYPE_CTT 1 @@ -3408,6 +3412,43 @@ void SwContentTree::UpdateTracking() return; } + // bookmarks - track first bookmark at cursor + SwDoc* pDoc = m_pActiveShell->GetDoc(); + uno::Reference<text::XBookmarksSupplier> xBookmarksSupplier(pDoc->GetDocShell()->GetBaseModel(), + uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xBookmarks(xBookmarksSupplier->getBookmarks(), + uno::UNO_QUERY); + sal_Int32 nBookmarkCount = xBookmarks->getCount(); + if (nBookmarkCount && !(m_bIsRoot && m_nRootType != ContentTypeId::BOOKMARK)) + { + SwPaM* pCursor = pDoc->GetEditShell()->GetCursor(); + uno::Reference<text::XTextRange> xRange( + SwXTextRange::CreateXTextRange(*pDoc, *pCursor->GetPoint(), nullptr)); + for (sal_Int32 i = 0; i < nBookmarkCount; ++i) + { + uno::Reference<text::XTextContent> bookmark; + xBookmarks->getByIndex(i) >>= bookmark; + try + { + uno::Reference<text::XTextRange> bookmarkRange = bookmark->getAnchor(); + uno::Reference<text::XTextRangeCompare> xTextRangeCompare(xRange->getText(), + uno::UNO_QUERY); + if (xTextRangeCompare.is() + && xTextRangeCompare->compareRegionStarts(bookmarkRange, xRange) != -1 + && xTextRangeCompare->compareRegionEnds(xRange, bookmarkRange) != -1) + { + uno::Reference<container::XNamed> xBookmark(bookmark, uno::UNO_QUERY); + lcl_SelectByContentTypeAndName(this, *m_xTreeView, + SwResId(STR_CONTENT_TYPE_BOOKMARK), + xBookmark->getName()); + return; + } + } + catch (const lang::IllegalArgumentException&) + { + } + } + } // references if (SwContentAtPos aContentAtPos(IsAttrAtPos::RefMark); m_pActiveShell->GetContentAtPos(m_pActiveShell->GetCursorDocPos(), aContentAtPos) &&