sw/inc/doc.hxx | 3 ++ sw/source/core/doc/docbm.cxx | 5 ++++ sw/source/uibase/sidebar/CommentsPanel.cxx | 33 +++++++++++++++++++++++++++++ sw/source/uibase/sidebar/CommentsPanel.hxx | 4 +++ 4 files changed, 45 insertions(+)
New commits: commit 1efe756d46cb5144da749a3b5279a8bc178dc802 Author: Mohit Marathe <mohitmara...@proton.me> AuthorDate: Tue Jul 30 12:51:18 2024 +0530 Commit: Sarper Akdemir <sarper.akde...@allotropia.de> CommitDate: Thu Sep 19 13:48:23 2024 +0200 display reference text on thread Change-Id: Ieeabde081c88473efa127c906b7ba12ba14bec17 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171233 Reviewed-by: Sarper Akdemir <sarper.akde...@allotropia.de> Tested-by: Jenkins diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx index 1f5ec0e53094..83c64f06409b 100644 --- a/sw/inc/doc.hxx +++ b/sw/inc/doc.hxx @@ -449,6 +449,9 @@ private: public: sal_Int32 getReferenceCount() const; + //MarkManager + SW_DLLPUBLIC ::sw::mark::MarkManager& GetMarkManager(); + // IDocumentSettingAccess SW_DLLPUBLIC IDocumentSettingAccess const & getIDocumentSettingAccess() const; //The IDocumentSettingAccess interface SW_DLLPUBLIC IDocumentSettingAccess & getIDocumentSettingAccess(); diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx index d1259cde3dbc..956af5c3afdd 100644 --- a/sw/source/core/doc/docbm.cxx +++ b/sw/source/core/doc/docbm.cxx @@ -1937,6 +1937,11 @@ namespace } } +MarkManager& SwDoc::GetMarkManager() +{ + return *mpMarkManager; +} + // IDocumentMarkAccess for SwDoc IDocumentMarkAccess* SwDoc::getIDocumentMarkAccess() { return static_cast< IDocumentMarkAccess* >(mpMarkManager.get()); } diff --git a/sw/source/uibase/sidebar/CommentsPanel.cxx b/sw/source/uibase/sidebar/CommentsPanel.cxx index de4726f0a372..03fea85534b7 100644 --- a/sw/source/uibase/sidebar/CommentsPanel.cxx +++ b/sw/source/uibase/sidebar/CommentsPanel.cxx @@ -26,6 +26,8 @@ #include <fmtfld.hxx> #include <docufld.hxx> #include <txtfld.hxx> +#include <IDocumentDeviceAccess.hxx> +#include <MarkManager.hxx> #include <ndtxt.hxx> #include <swmodule.hxx> #include <vcl/svapp.hxx> @@ -49,6 +51,7 @@ #include <cmdid.h> #include "CommentsPanel.hxx" +#include <annotationmark.hxx> #include <pam.hxx> #include <com/sun/star/lang/IllegalArgumentException.hpp> @@ -74,6 +77,17 @@ Comment::Comment(weld::Container* pParent, CommentsPanel& rCommentsPanel) mxReply->connect_clicked(LINK(this, Comment, ReplyClicked)); } +OUString CommentsPanel::getReferenceText(SwTextNode* pTextNode, sw::mark::AnnotationMark* pMark) +{ + if (!pMark) + return OUString(); + const SwPosition& rStart = pMark->GetMarkStart(); + const SwPosition& rEnd = pMark->GetMarkEnd(); + OUString sReferenceText = pTextNode->GetText().copy( + rStart.GetContentIndex(), rEnd.GetContentIndex() - rStart.GetContentIndex() - 1); + return sReferenceText; +} + Comment::~Comment() {} void Comment::InitControls(const SwPostItField* pPostItField) @@ -135,6 +149,7 @@ std::unique_ptr<PanelLayout> CommentsPanel::Create(weld::Widget* pParent) CommentsPanel::CommentsPanel(weld::Widget* pParent) : PanelLayout(pParent, "CommentsPanel", "modules/swriter/ui/commentspanel.ui") + , mpDoc(nullptr) , mpPostItMgr(nullptr) , mxFilterAuthor(m_xBuilder->weld_combo_box("filter_author")) , mxFilterDate(new SvtCalendarBox(m_xBuilder->weld_menu_button("filter_date"), true)) @@ -157,6 +172,7 @@ CommentsPanel::CommentsPanel(weld::Widget* pParent) return; SwWrtShell& rSh = pView->GetWrtShell(); mpPostItMgr = rSh.GetPostItMgr(); + mpDoc = rSh.GetDoc(); populateComments(); StartListening(*mpPostItMgr); @@ -411,6 +427,7 @@ void CommentsPanel::populateComments() mpCommentsMap[nId] = std::move(pComment); } mpThreadsMap[nRootId] = std::move(pThread); + setReferenceText(nRootId); } populateAuthorComboBox(); } @@ -452,6 +469,7 @@ void CommentsPanel::addComment(const SwFormatField* pField) pThread->getCommentBoxWidget()->reorder_child(pComment->get_widget(), pThread->mnComments++); mpThreadsMap[nRootId] = std::move(pThread); + setReferenceText(nRootId); pComment->InitControls(pNote->GetPostItField()); mpAuthorSet.insert(pComment->GetAuthor()); mpCommentsMap[nNoteId] = std::move(pComment); @@ -522,6 +540,21 @@ void CommentsPanel::editComment(SwPostItField* pPostItField, Comment* pComment) pComment->mxTextView->set_text(sText); } +void CommentsPanel::setReferenceText(sal_uInt32 nRootId) +{ + Thread* pThread = mpThreadsMap[nRootId].get(); + Comment* pRootComment = mpCommentsMap[nRootId].get(); + sw::annotation::SwAnnotationWin* pRootNote = getAnnotationWin(pRootComment); + SwFormatField* pField = pRootNote->GetFormatField(); + const SwPosition pAnchor = getAnchorPosition(pField); + SwNodeIndex aIdx(pAnchor.nNode); + SwTextNode* pTextNode = aIdx.GetNode().GetTextNode(); + sw::mark::MarkManager& rMarkManager = mpDoc->GetMarkManager(); + sw::mark::AnnotationMark* pMark = rMarkManager.getAnnotationMarkFor(pAnchor); + OUString sText = getReferenceText(pTextNode, pMark); + pThread->mxText->set_label(sText); +} + void CommentsPanel::EditComment(Comment* pComment) { if (!pComment) diff --git a/sw/source/uibase/sidebar/CommentsPanel.hxx b/sw/source/uibase/sidebar/CommentsPanel.hxx index d5e22c6ef076..9902f35887d8 100644 --- a/sw/source/uibase/sidebar/CommentsPanel.hxx +++ b/sw/source/uibase/sidebar/CommentsPanel.hxx @@ -19,6 +19,7 @@ #pragma once +#include <annotationmark.hxx> #include <svtools/ctrlbox.hxx> #include <rtl/ustring.hxx> #include <memory> @@ -141,6 +142,7 @@ public: static OUString FormatTime(tools::Time& rTime); private: + SwDoc* mpDoc; SwPostItMgr* mpPostItMgr; std::unordered_map<sal_uInt32, std::unique_ptr<Thread>> mpThreadsMap; @@ -174,6 +176,8 @@ private: void deleteComment(sal_uInt32 nId); void setResolvedStatus(sw::annotation::SwAnnotationWin* pAnnotationWin); static void editComment(SwPostItField* pPostItField, Comment* pComment); + static OUString getReferenceText(SwTextNode* pTextNode, sw::mark::AnnotationMark* pMark); + void setReferenceText(sal_uInt32 nRootId); void populateAuthorComboBox(); };