bool CommentsPanel::comp_dateTime(SwFormatField* a, SwFormatField* b)
{
SwPostItField* pA = static_cast<SwPostItField*>(a->GetField());
SwPostItField* pB = static_cast<SwPostItField*>(b->GetField());
Date aDateA(pA->GetDateTime());
tools::Time aTimeA(pA->GetDateTime());
Date aDateB(pB->GetDateTime());
tools::Time aTimeB(pB->GetDateTime());
bool CommentsPanel::comp_position(SwFormatField* a, SwFormatField* b)
{
SwPosition aPosA = getAnchorPosition(a);
SwPosition aPosB = getAnchorPosition(b);
return aPosA < aPosB;
}
void CommentsPanel::populateComments()
{ if (!mpCommentsMap.empty())
{ for (auto it = mpCommentsMap.begin(); it != mpCommentsMap.end();)
{
sal_uInt32 nId = it->first;
it++;
deleteComment(nId);
}
}
if (!mpPostItMgr) return;
std::vector<SwFormatField*> vFormatFields = mpPostItMgr->UpdatePostItsParentInfo(); if (mxSortbyTime->get_active())
{
std::sort(vFormatFields.begin(), vFormatFields.end(),
[](SwFormatField* a, SwFormatField* b) { return sw::sidebar::CommentsPanel::comp_dateTime(a, b);
});
} else
{
std::stable_sort(vFormatFields.begin(), vFormatFields.end(),
[](SwFormatField* a, SwFormatField* b) { return sw::sidebar::CommentsPanel::comp_position(a, b);
});
}
for (auto pFormatField : vFormatFields)
{
sw::annotation::SwAnnotationWin* pRootNote = getRootCommentWin(pFormatField); if (!pRootNote) continue;
sal_uInt32 nRootId = getPostItId(pRootNote);
if (mpThreadsMap.contains(nRootId))
{ if (mxSortbyPosition->get_active()) continue; else
{ auto pThread = mpThreadsMap[nRootId].get();
SwPostItField* pPostItField = static_cast<SwPostItField*>(pFormatField->GetField());
sal_uInt32 nId = pPostItField->GetPostItId(); auto pComment = std::make_unique<Comment>(pThread->getCommentBoxWidget(), *this);
pThread->getCommentBoxWidget()->reorder_child(pComment->get_widget(),
pThread->mnComments++);
pComment->InitControls(pPostItField);
mpAuthorSet.insert(pComment->GetAuthor());
mpCommentsMap[nId] = std::move(pComment); continue;
}
}
auto pThread = std::make_unique<Thread>(mxThreadsContainer.get());
mxThreadsContainer->reorder_child(pThread->get_widget(), mnThreads++);
if (mxSortbyPosition->get_active())
{ for (sw::annotation::SwAnnotationWin* pCurrent = pRootNote;;)
{
sal_uInt32 nId = getPostItId(pCurrent); auto pComment = std::make_unique<Comment>(pThread->getCommentBoxWidget(), *this);
pThread->getCommentBoxWidget()->reorder_child(pComment->get_widget(),
pThread->mnComments++);
pComment->InitControls(pCurrent->GetPostItField());
mpAuthorSet.insert(pComment->GetAuthor());
mpCommentsMap[nId] = std::move(pComment);
sw::annotation::SwAnnotationWin* next
= mpPostItMgr->GetNextPostIt(KEY_PAGEDOWN, pCurrent); if (!next || next->GetTopReplyNote() != pRootNote) break;
pCurrent = next;
}
} else
{
SwPostItField* pPostItField = static_cast<SwPostItField*>(pFormatField->GetField());
sal_uInt32 nId = pPostItField->GetPostItId(); auto pComment = std::make_unique<Comment>(pThread->getCommentBoxWidget(), *this);
pThread->getCommentBoxWidget()->reorder_child(pComment->get_widget(),
pThread->mnComments++);
pComment->InitControls(pPostItField);
mpAuthorSet.insert(pComment->GetAuthor());
mpCommentsMap[nId] = std::move(pComment);
}
mpThreadsMap[nRootId] = std::move(pThread);
setReferenceText(nRootId);
}
populateAuthorComboBox();
}
void CommentsPanel::addComment(const SwFormatField* pField)
{ // Get id of the note const SwPostItField* pPostItField = static_cast<const SwPostItField*>(pField->GetField());
sal_uInt32 nNoteId = pPostItField->GetPostItId();
if (mpCommentsMap.contains(nNoteId)) return;
// Get id of the root note
sw::annotation::SwAnnotationWin* pRootNote = getRootCommentWin(pField); if (!pRootNote) return;
sal_uInt32 nRootId = getPostItId(pRootNote);
sw::annotation::SwAnnotationWin* pNote
= mpPostItMgr->GetAnnotationWin(static_cast<const SwPostItField*>(pField->GetField())); // If comment is added to an existing thread if (mpThreadsMap.contains(nRootId))
{ auto& pThread = mpThreadsMap[nRootId]; auto pComment = std::make_unique<Comment>(pThread->getCommentBoxWidget(), *this);
pThread->getCommentBoxWidget()->reorder_child(pComment->get_widget(),
pThread->mnComments++);
pComment->InitControls(pNote->GetPostItField());
pComment->getTextView()->set_tooltip_text(SwResId(STR_COMMENT_EDIT_MODE));
mpAuthorSet.insert(pComment->GetAuthor());
mpCommentsMap[nNoteId] = std::move(pComment);
} // If a new thread is created else
{ auto pThread = std::make_unique<Thread>(mxThreadsContainer.get());
mxThreadsContainer->reorder_child(pThread->get_widget(), mnThreads++); auto pComment = std::make_unique<Comment>(pThread->getCommentBoxWidget(), *this);
pThread->getCommentBoxWidget()->reorder_child(pComment->get_widget(),
pThread->mnComments++);
mpThreadsMap[nRootId] = std::move(pThread);
setReferenceText(nRootId);
pComment->InitControls(pNote->GetPostItField());
pComment->getTextView()->set_tooltip_text(SwResId(STR_COMMENT_EDIT_MODE));
mpAuthorSet.insert(pComment->GetAuthor());
mpCommentsMap[nNoteId] = std::move(pComment);
}
populateComments();
}
void CommentsPanel::deleteComment(sal_uInt32 nId)
{
sw::annotation::SwAnnotationWin* pAnnotationWin = getAnnotationWin(mpCommentsMap[nId].get());
SwFormatField* pFormatField = pAnnotationWin->GetFormatField();
sw::annotation::SwAnnotationWin* pRootNote = getRootCommentWin(pFormatField); // // If the root comment is deleted, the new root comment of the thread should be the next comment in the thread // // but due to a bug `getRootCommentWin` returns root comment of some other/random thread so we completely lose // // access to the current thread. // if (mpThreadsMap.contains(nId)) // { // pRootNote = mpThreadsMap[nId]; // } // else // { // pRootNote = getRootCommentWin(pFormatField); // }
sal_uInt32 nRootId = getPostItId(pRootNote);
if (!mpThreadsMap.contains(nRootId))
{
SAL_WARN("sw", "Comments Panel is unable to delete comment: Referenced thread does not exist!"); return;
} auto& pComment = mpCommentsMap[nId]; auto& pThread = mpThreadsMap[nRootId]; if (!pComment)
{
SAL_WARN("sw", "Comments Panel is unable to delete comment: Referenced comment does not exist!"); return;
}
// If the last comment in the thread is deleted, delete the thread if (--pThread->mnComments == 0)
{
mxThreadsContainer->move(pThread->get_widget(), nullptr); if (mpThreadsMap.contains(nRootId))
mpThreadsMap.erase(nRootId);
mnThreads--;
}
}
void CommentsPanel::setResolvedStatus(const sw::annotation::SwAnnotationWin* pAnnotationWin)
{
sal_uInt32 nId = getPostItId(pAnnotationWin); if (!mpCommentsMap.contains(nId)) return; auto& pComment = mpCommentsMap[nId]; if (!pComment) return;
SwPostItField* pPostItField = const_cast<SwPostItField*>(pAnnotationWin->GetPostItField()); if (pPostItField->GetResolved() == pComment->mbResolved)
{
editComment(pPostItField, pComment.get()); return;
}
pComment->mbResolved = pPostItField->GetResolved();
pComment->mxResolve->set_active(pComment->mbResolved);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.