summaryrefslogtreecommitdiff
path: root/sw/source/uibase/utlui/content.cxx
diff options
context:
space:
mode:
authorJim Raykowski <raykowj@gmail.com>2020-04-21 01:49:36 -0800
committerJim Raykowski <raykowj@gmail.com>2020-09-20 08:25:24 +0200
commit6f7f5f280abaf4ee84472359acd4952b2eea40a4 (patch)
treef8684852dfb7b5e9a1b5f5e8d1abb588bb8aa02a /sw/source/uibase/utlui/content.cxx
parentc6b6995004d34cadaec68e2b6e17667d43f9995e (diff)
tdf#132366 Writer enhancement that highlights search results
This enhancement selects outline headings in the Writer Navigator content tree according to 'Find All' search results. It does this when the content navigation view is set to show headings content only. Change-Id: I77dabcdd38c8877b7f8a177689da094638d5fe00 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92886 Tested-by: Jenkins Reviewed-by: Jim Raykowski <raykowj@gmail.com>
Diffstat (limited to 'sw/source/uibase/utlui/content.cxx')
-rw-r--r--sw/source/uibase/utlui/content.cxx68
1 files changed, 68 insertions, 0 deletions
diff --git a/sw/source/uibase/utlui/content.cxx b/sw/source/uibase/utlui/content.cxx
index 36cf1449881c..97dc04351d26 100644
--- a/sw/source/uibase/utlui/content.cxx
+++ b/sw/source/uibase/utlui/content.cxx
@@ -2700,6 +2700,20 @@ void SwContentTree::Notify(SfxBroadcaster & rBC, SfxHint const& rHint)
}
switch (rHint.GetId())
{
+ case SfxHintId::SwNavigatorSelectOutlinesWithSelections:
+ {
+ if (m_nRootType == ContentTypeId::OUTLINE)
+ {
+ SelectOutlinesWithSelection();
+ // make first selected entry visible
+ std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator());
+ if (xEntry && m_xTreeView->get_selected(xEntry.get()))
+ m_xTreeView->scroll_to_row(*xEntry);
+ }
+ else if (m_nRootType == ContentTypeId::UNKNOWN)
+ m_xTreeView->unselect_all();
+ break;
+ }
case SfxHintId::DocChanged:
if (!m_bIgnoreViewChange)
{
@@ -3160,6 +3174,60 @@ IMPL_LINK_NOARG(SwContentTree, TimerUpdate, Timer *, void)
}
}
+void SwContentTree::SelectOutlinesWithSelection()
+{
+ SwCursor* pFirstCursor = m_pActiveShell->GetSwCursor();
+ SwCursor* pCursor = pFirstCursor;
+ std::vector<SwOutlineNodes::size_type> aOutlinePositions;
+ do
+ {
+ if (pCursor)
+ {
+ if (pCursor->HasMark())
+ {
+ aOutlinePositions.push_back(m_pActiveShell->GetOutlinePos(UCHAR_MAX, pCursor));
+ }
+ pCursor = pCursor->GetNext();
+ }
+ } while (pCursor && pCursor != pFirstCursor);
+
+ if (!aOutlinePositions.empty())
+ {
+ // remove duplicates before selecting
+ aOutlinePositions.erase(std::unique(aOutlinePositions.begin(), aOutlinePositions.end()),
+ aOutlinePositions.end());
+
+ m_xTreeView->unselect_all();
+
+ for (auto nOutlinePosition : aOutlinePositions)
+ {
+ m_xTreeView->all_foreach([this, nOutlinePosition](const weld::TreeIter& rEntry){
+ if (lcl_IsContent(rEntry, *m_xTreeView) &&
+ reinterpret_cast<SwContent*>(
+ m_xTreeView->get_id(rEntry).toInt64())->GetParent()->GetType() ==
+ ContentTypeId::OUTLINE)
+ {
+ if (reinterpret_cast<SwOutlineContent*>(
+ m_xTreeView->get_id(rEntry).toInt64())->GetOutlinePos() ==
+ nOutlinePosition)
+ {
+ std::unique_ptr<weld::TreeIter> xParent =
+ m_xTreeView->make_iterator(&rEntry);
+ if (m_xTreeView->iter_parent(*xParent) &&
+ !m_xTreeView->get_row_expanded(*xParent))
+ m_xTreeView->expand_row(*xParent);
+ m_xTreeView->select(rEntry);
+ return true;
+ }
+ }
+ return false;
+ });
+ }
+
+ Select();
+ }
+}
+
void SwContentTree::MoveOutline(SwOutlineNodes::size_type nTargetPos)
{
SwWrtShell *const pShell = GetWrtShell();