diff options
author | Jaume Pujantell <jaume.pujantell@collabora.com> | 2024-09-08 20:52:28 +0200 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2024-09-16 09:46:24 +0200 |
commit | 3bb2668f5e753e9fa6aa7eea74454bf11cdfc853 (patch) | |
tree | ade2167e80814d299e566ce488a0749499ddb1e6 /sw/source/uibase | |
parent | 5b7c389f05319d6405a371eafce7cea5a8f62144 (diff) |
sw: add new command to make a response comment root
Adds the option to convert a reply comment into a new top comment
while preserving the parent-child realtions of the other comments
in the thread.
Change-Id: I3cd5e5466fadc2226651d7c244b5139ec2d1f949
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173051
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sw/source/uibase')
-rw-r--r-- | sw/source/uibase/docvw/AnnotationMenuButton.cxx | 4 | ||||
-rw-r--r-- | sw/source/uibase/docvw/AnnotationWin.cxx | 18 | ||||
-rw-r--r-- | sw/source/uibase/docvw/AnnotationWin2.cxx | 12 | ||||
-rw-r--r-- | sw/source/uibase/docvw/PostItMgr.cxx | 56 | ||||
-rw-r--r-- | sw/source/uibase/shells/annotsh.cxx | 10 | ||||
-rw-r--r-- | sw/source/uibase/shells/textfld.cxx | 21 |
6 files changed, 106 insertions, 15 deletions
diff --git a/sw/source/uibase/docvw/AnnotationMenuButton.cxx b/sw/source/uibase/docvw/AnnotationMenuButton.cxx index 5e42d15c879e..ac8dd0c8e031 100644 --- a/sw/source/uibase/docvw/AnnotationMenuButton.cxx +++ b/sw/source/uibase/docvw/AnnotationMenuButton.cxx @@ -55,6 +55,8 @@ IMPL_LINK(SwAnnotationWin, SelectHdl, const OUString&, rIdent, void) ExecuteCommand(FN_DELETE_ALL_NOTES); else if (rIdent == "formatall") ExecuteCommand(FN_FORMAT_ALL_NOTES); + else if (rIdent == "promote") + ExecuteCommand(FN_PROMOTE_COMMENT); if (bSwitchedFocus) UnsetActiveSidebarWin(); @@ -76,6 +78,7 @@ IMPL_LINK_NOARG(SwAnnotationWin, ToggleHdl, weld::Toggleable&, void) mxMenuButton->set_item_visible("resolvethread", false); mxMenuButton->set_item_visible("unresolvethread", false); mxMenuButton->set_item_visible("delete", false ); + mxMenuButton->set_item_visible("promote", false); } else { @@ -86,6 +89,7 @@ IMPL_LINK_NOARG(SwAnnotationWin, ToggleHdl, weld::Toggleable&, void) mxMenuButton->set_item_visible("resolvethread", !IsThreadResolved()); mxMenuButton->set_item_visible("unresolvethread", IsThreadResolved()); mxMenuButton->set_item_visible("delete", !IsReadOnlyOrProtected()); + mxMenuButton->set_item_visible("promote", !IsReadOnlyOrProtected() && !IsRootNote()); } mxMenuButton->set_item_visible("deletethread", !bReadOnly); diff --git a/sw/source/uibase/docvw/AnnotationWin.cxx b/sw/source/uibase/docvw/AnnotationWin.cxx index 426c097e9e58..75569fcd5cf3 100644 --- a/sw/source/uibase/docvw/AnnotationWin.cxx +++ b/sw/source/uibase/docvw/AnnotationWin.cxx @@ -307,6 +307,24 @@ bool SwAnnotationWin::IsThreadResolved() } } +bool SwAnnotationWin::IsRootNote() const +{ + return static_cast<SwPostItField*>(mpFormatField->GetField())->GetParentPostItId() == 0; +} + +void SwAnnotationWin::SetAsRoot() +{ + if (!IsRootNote()) + { + SwPostItField* pPostIt = static_cast<SwPostItField*>(mpFormatField->GetField()); + pPostIt->SetParentId(0); + pPostIt->SetParentPostItId(0); + pPostIt->SetParentName(""); + mrMgr.MoveSubthreadToRoot(this); + mpFormatField->Broadcast(SwFormatFieldHint(nullptr, SwFormatFieldHintWhich::CHANGED)); + } +} + void SwAnnotationWin::UpdateData() { if ( mpOutliner->IsModified() || mbResolvedStateUpdated ) diff --git a/sw/source/uibase/docvw/AnnotationWin2.cxx b/sw/source/uibase/docvw/AnnotationWin2.cxx index 73c035abdaf7..e1feb6bda484 100644 --- a/sw/source/uibase/docvw/AnnotationWin2.cxx +++ b/sw/source/uibase/docvw/AnnotationWin2.cxx @@ -1072,10 +1072,10 @@ void SwAnnotationWin::ExecuteCommand(sal_uInt16 nSlot) { // Get newly created SwPostItField and set its paraIdParent auto pPostItField = mrMgr.GetLatestPostItField(); - pPostItField->SetParentId(GetTopReplyNote()->GetParaId()); - pPostItField->SetParentPostItId(GetTopReplyNote()->GetPostItField()->GetPostItId()); + pPostItField->SetParentId(GetParaId()); + pPostItField->SetParentPostItId(GetPostItField()->GetPostItId()); this->GeneratePostItName(); - pPostItField->SetParentName(GetTopReplyNote()->GetPostItField()->GetName()); + pPostItField->SetParentName(GetPostItField()->GetName()); // In this case, force generating the associated window // synchronously so we can bundle its use of the registered @@ -1126,6 +1126,12 @@ void SwAnnotationWin::ExecuteCommand(sal_uInt16 nSlot) mrView.GetViewFrame().GetBindings().Execute( nSlot, aItems, SfxCallMode::ASYNCHRON ); } break; + case FN_PROMOTE_COMMENT: + SetAsRoot(); + DoResize(); + Invalidate(); + mrMgr.LayoutPostIts(); + break; default: mrView.GetViewFrame().GetBindings().Execute( nSlot ); break; diff --git a/sw/source/uibase/docvw/PostItMgr.cxx b/sw/source/uibase/docvw/PostItMgr.cxx index f712188bcba2..bc4df5ecb409 100644 --- a/sw/source/uibase/docvw/PostItMgr.cxx +++ b/sw/source/uibase/docvw/PostItMgr.cxx @@ -1713,6 +1713,62 @@ void SwPostItMgr::Delete() LayoutPostIts(); } +void SwPostItMgr::PromoteToRoot(sal_uInt32 nPostItId) +{ + mpWrtShell->StartAllAction(); + + SwRewriter aRewriter; + aRewriter.AddRule(UndoArg1, SwResId(STR_CONTENT_TYPE_SINGLE_POSTIT)); + + // We have no undo ID at the moment. + + IsPostitFieldWithPostitId aFilter(nPostItId); + FieldDocWatchingStack aStack(mvPostItFields, *mpView->GetDocShell(), aFilter); + const SwFormatField* pField = aStack.pop(); + // pField now contains our AnnotationWin object + if (pField) + { + SwAnnotationWin* pWin = GetSidebarWin(pField); + pWin->SetAsRoot(); + } + PrepareView(); + mpWrtShell->EndAllAction(); + mbLayout = true; + CalcRects(); + LayoutPostIts(); +} + +void SwPostItMgr::MoveSubthreadToRoot(const sw::annotation::SwAnnotationWin* pNewRoot) +{ + std::vector<std::unique_ptr<SwSidebarItem>>::iterator first, middle, last; + first = std::find_if(mvPostItFields.begin(), mvPostItFields.end(), + [&pNewRoot](const std::unique_ptr<SwSidebarItem>& pField) { + return pField->mpPostIt == pNewRoot; + }); + if (first == mvPostItFields.end()) + return; + std::set<int> aPostItIds; + aPostItIds.insert(pNewRoot->GetPostItField()->GetPostItId()); + middle = first + 1; + while (middle != mvPostItFields.end() + && aPostItIds.contains((*middle)->mpPostIt->GetPostItField()->GetParentPostItId())) + { + aPostItIds.insert((*middle)->mpPostIt->GetPostItField()->GetPostItId()); + ++middle; + } + if (middle == mvPostItFields.end()) + return; + last = middle; + while (last != mvPostItFields.end() + && (*last)->mpPostIt->GetPostItField()->GetParentPostItId() != 0) + ++last; + if (last == middle) + return; + std::rotate(first, middle, last); + CalcRects(); + LayoutPostIts(); +} + void SwPostItMgr::ExecuteFormatAllDialog(SwView& rView) { if (mvPostItFields.empty()) diff --git a/sw/source/uibase/shells/annotsh.cxx b/sw/source/uibase/shells/annotsh.cxx index 5c9ed82b4114..4d87aacd451e 100644 --- a/sw/source/uibase/shells/annotsh.cxx +++ b/sw/source/uibase/shells/annotsh.cxx @@ -1114,6 +1114,7 @@ void SwAnnotationShell::NoteExec(SfxRequest const &rReq) case FN_DELETE_COMMENT_THREAD: case FN_RESOLVE_NOTE: case FN_RESOLVE_NOTE_THREAD: + case FN_PROMOTE_COMMENT: if ( pPostItMgr->HasActiveSidebarWin() ) pPostItMgr->GetActiveSidebarWin()->ExecuteCommand(nSlot); break; @@ -1240,6 +1241,15 @@ void SwAnnotationShell::GetNoteState(SfxItemSet &rSet) } break; } + case FN_PROMOTE_COMMENT: + { + if (!pPostItMgr || !pPostItMgr->HasActiveAnnotationWin() + || pPostItMgr->GetActiveSidebarWin()->IsRootNote()) + { + rSet.DisableItem(nWhich); + } + break; + } default: rSet.InvalidateItem( nWhich ); break; diff --git a/sw/source/uibase/shells/textfld.cxx b/sw/source/uibase/shells/textfld.cxx index 87aa34ffd724..d20a37ffe1d3 100644 --- a/sw/source/uibase/shells/textfld.cxx +++ b/sw/source/uibase/shells/textfld.cxx @@ -506,18 +506,6 @@ void SwTextShell::ExecField(SfxRequest &rReq) sText = pTextItem->GetValue(); pMgr->RegisterAnswerText(sText); pWin->ExecuteCommand(nSlot); - - SwPostItField* pLatestPostItField = pMgr->GetLatestPostItField(); - if (pLatestPostItField) - { - // Set the parent postit id of the reply. - pLatestPostItField->SetParentPostItId(pIdItem->GetValue().toUInt32()); - - // If name of the replied comment is empty, we need to set a name in order to connect them in the xml file. - pWin->GeneratePostItName(); // Generates a name if the current name is empty. - - pLatestPostItField->SetParentName(pWin->GetPostItField()->GetName()); - } } } } @@ -549,6 +537,15 @@ void SwTextShell::ExecField(SfxRequest &rReq) } } break; + case FN_PROMOTE_COMMENT: + { + const SvxPostItIdItem* pIdItem = rReq.GetArg<SvxPostItIdItem>(SID_ATTR_POSTIT_ID); + if (pIdItem && !pIdItem->GetValue().isEmpty() && GetView().GetPostItMgr()) + { + GetView().GetPostItMgr()->PromoteToRoot(pIdItem->GetValue().toUInt32()); + } + break; + } case FN_REDLINE_COMMENT: { /* this code can be used once we want redline comments in the margin, all other stuff can |