diff options
author | Jim Raykowski <raykowj@gmail.com> | 2021-09-25 21:56:48 -0800 |
---|---|---|
committer | Jim Raykowski <raykowj@gmail.com> | 2021-09-30 05:06:00 +0200 |
commit | cdc1f41d4530ad3ec553d90dad803bc5b940656c (patch) | |
tree | 652c0033b641ff53833bb325a4e3120e0f35ebf5 /sw/source | |
parent | ebc454ad4eb1f4cd4d84a7db367bb71a457c4e5c (diff) |
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 <raykowj@gmail.com>
Diffstat (limited to 'sw/source')
-rw-r--r-- | sw/source/uibase/utlui/content.cxx | 41 |
1 files changed, 41 insertions, 0 deletions
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) && |