sc/sdi/scalc.sdi | 19 ++++++++++++++ sc/sdi/tabvwsh.sdi | 1 sc/source/ui/inc/content.hxx | 1 sc/source/ui/inc/navipi.hxx | 21 +++++++++++++++ sc/source/ui/inc/tabvwsh.hxx | 1 sc/source/ui/navipi/content.cxx | 53 +++++++++++++++++++++++++++++++++++++++- sc/source/ui/navipi/navipi.cxx | 19 -------------- sc/source/ui/view/tabvwsh9.cxx | 22 ++++++++++++++++ 8 files changed, 117 insertions(+), 20 deletions(-)
New commits: commit 4adef808cb6175c04f70f186332116e5afc09779 Author: Sahil Gautam <[email protected]> AuthorDate: Wed Oct 22 03:40:46 2025 +0530 Commit: Sahil Gautam <[email protected]> CommitDate: Tue Oct 28 14:12:37 2025 +0100 sc: add uno command to select a comment in the navigator Change-Id: I11916b11b5e13a5a0e8379f7ba361e8729c4f101 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192818 Reviewed-by: Michael Stahl <[email protected]> Tested-by: Jenkins diff --git a/sc/sdi/scalc.sdi b/sc/sdi/scalc.sdi index 2ccbae38b739..06c9bd1093b2 100644 --- a/sc/sdi/scalc.sdi +++ b/sc/sdi/scalc.sdi @@ -2543,6 +2543,25 @@ SfxVoidItem GoDownToEndOfData SID_CURSORBLKDOWN ] +SfxVoidItem NavigatorSelectComment SID_NAVIGATOR_SELECT_COMMENT +(SfxUInt16Item CommentId FN_PARAM_1) +[ + AutoUpdate = TRUE, + FastCall = FALSE, + ReadOnlyDoc = TRUE, + Toggle = FALSE, + Container = FALSE, + RecordAbsolute = FALSE, + RecordPerSet; + + + AccelConfig = TRUE, + MenuConfig = TRUE, + ToolBoxConfig = TRUE, + GroupId = SfxGroupId::Navigator; +] + + SfxVoidItem GoDownToEndOfDataSel SID_CURSORBLKDOWN_SEL (SfxInt16Item By FN_PARAM_1) [ diff --git a/sc/sdi/tabvwsh.sdi b/sc/sdi/tabvwsh.sdi index cae6da0dfb4f..42c6018edf1b 100644 --- a/sc/sdi/tabvwsh.sdi +++ b/sc/sdi/tabvwsh.sdi @@ -224,6 +224,7 @@ interface TableEditView SID_PRINTPREVIEW [ ExecMethod = Execute; StateMethod = GetState; ] SID_THEME_DIALOG [ ExecMethod = Execute; StateMethod = GetState; ] + SID_NAVIGATOR_SELECT_COMMENT [ ExecMethod = ExecNavigatorWin; ] // search/replace FID_SEARCH_NOW [ ExecMethod = ExecSearch; StateMethod = NoState; ] diff --git a/sc/source/ui/inc/content.hxx b/sc/source/ui/inc/content.hxx index b57e49eb55f2..fa8af396886c 100644 --- a/sc/source/ui/inc/content.hxx +++ b/sc/source/ui/inc/content.hxx @@ -146,6 +146,7 @@ public: void SetManualDoc(const OUString& rName); void SelectDoc(const OUString& rName); void SelectEntryByName(const ScContentId nRoot, std::u16string_view rName); + void BringCommentToAttention(sal_uInt16 nCommentId); /** Applies the navigator settings to the listbox. */ void ApplyNavigatorSettings(); diff --git a/sc/source/ui/inc/navipi.hxx b/sc/source/ui/inc/navipi.hxx index 12c46f67a82a..aa38a35c4b61 100644 --- a/sc/source/ui/inc/navipi.hxx +++ b/sc/source/ui/inc/navipi.hxx @@ -86,6 +86,7 @@ class ScNavigatorDlg : public PanelLayout, public SfxListener friend class ScNavigatorWin; friend class ScNavigatorControllerItem; friend class ScContentTree; +friend class ScTabViewShell; private: static constexpr int CTRL_ITEMS = 4; @@ -187,4 +188,24 @@ public: SFX_DECL_CHILDWINDOW(ScNavigatorWrapper); }; +class ScNavigatorWin : public SfxNavigator +{ + friend class ScTabViewShell; +private: + std::unique_ptr<ScNavigatorDlg> m_xNavigator; +public: + ScNavigatorWin(SfxBindings* _pBindings, SfxChildWindow* pMgr, + vcl::Window* pParent, SfxChildWinInfo* pInfo); + virtual void StateChanged(StateChangedType nStateChange) override; + virtual void dispose() override + { + m_xNavigator.reset(); + SfxNavigator::dispose(); + } + virtual ~ScNavigatorWin() override + { + disposeOnce(); + } +}; + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/inc/tabvwsh.hxx b/sc/source/ui/inc/tabvwsh.hxx index be283fcffaf8..f437eb5872e3 100644 --- a/sc/source/ui/inc/tabvwsh.hxx +++ b/sc/source/ui/inc/tabvwsh.hxx @@ -303,6 +303,7 @@ public: void GetDrawState(SfxItemSet &rSet); void GetDrawInsState(SfxItemSet &rSet); void ExecGallery(const SfxRequest& rReq); + void ExecNavigatorWin(const SfxRequest& rReq); void ExecChildWin(const SfxRequest& rReq); diff --git a/sc/source/ui/navipi/content.cxx b/sc/source/ui/navipi/content.cxx index 718c5b2ff2fd..8deac205db2a 100644 --- a/sc/source/ui/navipi/content.cxx +++ b/sc/source/ui/navipi/content.cxx @@ -262,8 +262,10 @@ void ScContentTree::GetEntryIndexes(ScContentId& rnRootIndex, sal_uLong& rnChild rnRootIndex = ScContentId::ROOT; rnChildIndex = SC_CONTENT_NOCHILD; - if( !pEntry ) + if( !pEntry ) { + SAL_WARN("sc", "got a null TreeIter"); return; + } std::unique_ptr<weld::TreeIter> xParent(m_xTreeView->make_iterator(pEntry)); if (!m_xTreeView->iter_parent(*xParent)) @@ -1526,6 +1528,55 @@ void ScContentTree::SelectEntryByName(const ScContentId nRoot, std::u16string_vi } } +void ScContentTree::BringCommentToAttention(sal_uInt16 nCommentId) +{ + std::unique_ptr<weld::TreeIter> xIter(m_xTreeView->make_iterator()); + if (!m_xTreeView->get_iter_first(*xIter)) + return; + + do + { + ScContentId nType; + sal_uLong nChild; + GetEntryIndexes(nType, nChild, xIter.get()); + + if (!xIter) + return; + + if (nType == ScContentId::NOTE) + { + m_xTreeView->set_cursor(*xIter); + m_xTreeView->select(*xIter); + m_xTreeView->expand_row(*xIter); + sal_uInt32 nCount = m_xTreeView->iter_n_children(*xIter); + m_xTreeView->iter_children(*xIter); + + std::vector<sc::NoteEntry> aEntries; + ScDocument* pDoc= GetSourceDocument(); + pDoc->GetAllNoteEntries(aEntries); + + if (aEntries.size() != nCount) { + SAL_WARN("sc", "number of comments and children count does not match."); + return; + } + + for (sal_uInt32 i = 0; i < nCount; ++i) + { + const ScPostIt* pPostIt = aEntries[i].mpNote; + if (pPostIt && pPostIt->GetId() == nCommentId) + { + m_xTreeView->select(*xIter); + break; + } + m_xTreeView->iter_next(*xIter); + } + break; + } + else + m_xTreeView->collapse_row(*xIter); + + } while (m_xTreeView->iter_next_sibling(*xIter));} + void ScContentTree::ApplyNavigatorSettings() { const ScNavigatorSettings* pSettings = ScNavigatorDlg::GetNavigatorSettings(); diff --git a/sc/source/ui/navipi/navipi.cxx b/sc/source/ui/navipi/navipi.cxx index 2729cfe9b215..33265211aea9 100644 --- a/sc/source/ui/navipi/navipi.cxx +++ b/sc/source/ui/navipi/navipi.cxx @@ -287,25 +287,6 @@ ScNavigatorSettings::ScNavigatorSettings() maExpandedVec.fill(false); } -class ScNavigatorWin : public SfxNavigator -{ -private: - std::unique_ptr<ScNavigatorDlg> m_xNavigator; -public: - ScNavigatorWin(SfxBindings* _pBindings, SfxChildWindow* pMgr, - vcl::Window* pParent, SfxChildWinInfo* pInfo); - virtual void StateChanged(StateChangedType nStateChange) override; - virtual void dispose() override - { - m_xNavigator.reset(); - SfxNavigator::dispose(); - } - virtual ~ScNavigatorWin() override - { - disposeOnce(); - } -}; - ScNavigatorWin::ScNavigatorWin(SfxBindings* _pBindings, SfxChildWindow* _pMgr, vcl::Window* _pParent, SfxChildWinInfo* pInfo) : SfxNavigator(_pBindings, _pMgr, _pParent, pInfo) diff --git a/sc/source/ui/view/tabvwsh9.cxx b/sc/source/ui/view/tabvwsh9.cxx index 5c4698a9e1d5..ca1375e4f30c 100644 --- a/sc/source/ui/view/tabvwsh9.cxx +++ b/sc/source/ui/view/tabvwsh9.cxx @@ -31,6 +31,7 @@ #include <svl/stritem.hxx> #include "imapwrap.hxx" +#include <navipi.hxx> #include <tabvwsh.hxx> #include <viewdata.hxx> #include <docsh.hxx> @@ -86,6 +87,27 @@ void ScTabViewShell::ExecGallery( const SfxRequest& rReq ) } } +void ScTabViewShell::ExecNavigatorWin(const SfxRequest& rReq) +{ + const SfxItemSet* pArgs = rReq.GetArgs(); + const SfxPoolItem* pItem; + + if (pArgs && pArgs->HasItem(FN_PARAM_1, &pItem)) + { + sal_uInt16 nCommentId = static_cast<const SfxUInt16Item*>(pItem)->GetValue(); + if (SfxChildWindow* pWin = GetViewFrame().GetChildWindow(SID_NAVIGATOR)) + { + ScNavigatorWin* pNavWin = static_cast<ScNavigatorWin*>(pWin->GetWindow()); + if (pNavWin->m_xNavigator && pNavWin->m_xNavigator->m_xLbEntries) + pNavWin->m_xNavigator->m_xLbEntries->BringCommentToAttention(nCommentId); + } + else + SAL_WARN("sc.ui", "GetChildWindow(SID_NAVIGATOR) == nullptr"); + } + else + SAL_WARN("sc.ui", "failed to extract FN_PARAM_1 i.e. CommentNumber"); +} + void ScTabViewShell::ExecImageMap( SfxRequest& rReq ) { sal_uInt16 nSlot = rReq.GetSlot();
