sw/source/uibase/inc/conttree.hxx | 5 +++- sw/source/uibase/uiview/viewsrch.cxx | 2 + sw/source/uibase/utlui/glbltree.cxx | 42 ++++++++++++++++++++++++++++++++--- 3 files changed, 45 insertions(+), 4 deletions(-)
New commits: commit 1f9a792a391f0811bbb5f570ad5c84d13312c539 Author: Jim Raykowski <rayk...@gmail.com> AuthorDate: Tue Sep 14 16:07:53 2021 -0800 Commit: Jim Raykowski <rayk...@gmail.com> CommitDate: Sat Sep 18 07:20:36 2021 +0200 tdf#144349 Make Navigator global tree track sub-document sections Master document relies on the Navigator listing all the sub-documents. However there is no connection between the currently selected section (containing the sub-document) and the entry in the Navigator making it very hard to see what file needs to be edited. This patch highlights the corresponding item in the Navigator at the current cursor position in the document. Change-Id: Iee32d1db0e40e302bfff7a879d47a5632ce4ed43 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122103 Tested-by: Jenkins Reviewed-by: Jim Raykowski <rayk...@gmail.com> diff --git a/sw/source/uibase/inc/conttree.hxx b/sw/source/uibase/inc/conttree.hxx index 4ac942e9ecd7..78e078cc78f3 100644 --- a/sw/source/uibase/inc/conttree.hxx +++ b/sw/source/uibase/inc/conttree.hxx @@ -282,7 +282,7 @@ public: SwGlobalTreeDropTarget(SwGlobalTree& rTreeView); }; -class SwGlobalTree final +class SwGlobalTree final : public SfxListener { private: std::unique_ptr<weld::TreeView> m_xTreeView; @@ -368,6 +368,9 @@ public: void ExecuteContextMenuAction(std::string_view rSelectedPopupEntry); const SwWrtShell* GetActiveWrtShell() const {return m_pActiveShell;} + + virtual void Notify(SfxBroadcaster& rBC, SfxHint const& rHint) override; + void UpdateTracking(); }; #endif diff --git a/sw/source/uibase/uiview/viewsrch.cxx b/sw/source/uibase/uiview/viewsrch.cxx index 66fb79ac3809..ba86732a82a3 100644 --- a/sw/source/uibase/uiview/viewsrch.cxx +++ b/sw/source/uibase/uiview/viewsrch.cxx @@ -256,6 +256,8 @@ void SwView::ExecSearch(SfxRequest& rReq) bool bRet = SearchAll(); m_pWrtShell->GetSfxViewShell()->setTiledSearching(false); + GetDocShell()->Broadcast( + SfxHint(SfxHintId::SwNavigatorUpdateTracking)); GetDocShell()->Broadcast( SfxHint(SfxHintId::SwNavigatorSelectOutlinesWithSelections)); diff --git a/sw/source/uibase/utlui/glbltree.cxx b/sw/source/uibase/utlui/glbltree.cxx index 8ea94f9680f8..81c351f7249a 100644 --- a/sw/source/uibase/utlui/glbltree.cxx +++ b/sw/source/uibase/utlui/glbltree.cxx @@ -773,8 +773,33 @@ void SwGlobalTree::ExecuteContextMenuAction(std::string_view rSelectedPopupEntry IMPL_LINK_NOARG(SwGlobalTree, Timeout, Timer *, void) { - if (!m_xTreeView->has_focus() && Update(false)) - Display(); + if (m_pActiveShell && m_pActiveShell->GetView().GetEditWin().HasFocus()) + { + if (Update(false)) + Display(); + UpdateTracking(); + } +} + +void SwGlobalTree::UpdateTracking() +{ + if (!m_pActiveShell) + return; + + // track section at cursor position in document + m_xTreeView->unselect_all(); + + const SwSection* pActiveShellCurrSection = m_pActiveShell->GetCurrSection(); + if (pActiveShellCurrSection) + { + const SwSection* pSection = pActiveShellCurrSection; + SwSection* pParent; + while ((pParent = pSection->GetParent()) != nullptr) + pSection = pParent; + + if (pSection) + m_xTreeView->select_text(pSection->GetSectionName()); + } } void SwGlobalTree::GotoContent(const SwGlblDocContent* pCont) @@ -803,6 +828,7 @@ void SwGlobalTree::ShowTree() { m_aUpdateTimer.Start(); m_xTreeView->show(); + UpdateTracking(); } void SwGlobalTree::HideTree() @@ -854,10 +880,13 @@ bool SwGlobalTree::Update(bool bHard) bool bRet = false; if (pActView && pActView->GetWrtShellPtr()) { - const SwWrtShell* pOldShell = m_pActiveShell; + SwWrtShell* pOldShell = m_pActiveShell; m_pActiveShell = pActView->GetWrtShellPtr(); if(m_pActiveShell != pOldShell) { + if (pOldShell) + EndListening(*pOldShell->GetView().GetDocShell()); + StartListening(*m_pActiveShell->GetView().GetDocShell()); m_pSwGlblDocContents.reset(); } if(!m_pSwGlblDocContents) @@ -1090,4 +1119,11 @@ IMPL_LINK( SwGlobalTree, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg, vo m_pDocContent.reset(); } +void SwGlobalTree::Notify(SfxBroadcaster& rBC, SfxHint const& rHint) +{ + SfxListener::Notify(rBC, rHint); + if (rHint.GetId() == SfxHintId::SwNavigatorUpdateTracking) + UpdateTracking(); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */