From ff43f55e698292753bfdd511874a4a1405e81d7c Mon Sep 17 00:00:00 2001 From: Pranam Lashkari Date: Wed, 22 May 2024 11:57:57 +0100 Subject: create comment reply synchronously MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit so we can bundle the creation of the comment and the insertion of its "reply" characteristics together as a single Undo group. wrap the new combination with a single undo operation showing "Insert Comment" using Rewriter Change-Id: I5927fa5501da0c49cc1182c60e23be290b8c37c5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168171 Reviewed-by: Caolán McNamara Tested-by: Jenkins CollaboraOffice Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168236 Reviewed-by: Pranam Lashkari --- sw/inc/PostItMgr.hxx | 1 + sw/source/uibase/docvw/AnnotationWin.cxx | 9 ++++++--- sw/source/uibase/docvw/AnnotationWin2.cxx | 22 ++++++++++++++++++++-- sw/source/uibase/docvw/PostItMgr.cxx | 5 +++++ 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/sw/inc/PostItMgr.hxx b/sw/inc/PostItMgr.hxx index f66e38748a64..5a877a6c8afe 100644 --- a/sw/inc/PostItMgr.hxx +++ b/sw/inc/PostItMgr.hxx @@ -233,6 +233,7 @@ class SAL_DLLPUBLIC_RTTI SwPostItMgr final : public SfxListener sw::annotation::SwAnnotationWin* GetNextPostIt( sal_uInt16 aDirection, sw::annotation::SwAnnotationWin* aPostIt); SwPostItField* GetLatestPostItField(); + sw::annotation::SwAnnotationWin* GetOrCreateAnnotationWindowForLatestPostItField(); tools::Long GetNextBorder(); diff --git a/sw/source/uibase/docvw/AnnotationWin.cxx b/sw/source/uibase/docvw/AnnotationWin.cxx index 16acc0cbf589..adc487422466 100644 --- a/sw/source/uibase/docvw/AnnotationWin.cxx +++ b/sw/source/uibase/docvw/AnnotationWin.cxx @@ -119,9 +119,12 @@ SwAnnotationWin::SwAnnotationWin( SwEditWin& rEditWin, } #if !ENABLE_WASM_STRIP_ACCESSIBILITY - mrMgr.ConnectSidebarWinToFrame( *(mrSidebarItem.maLayoutInfo.mpAnchorFrame), - mrSidebarItem.GetFormatField(), - *this ); + if (rSidebarItem.maLayoutInfo.mpAnchorFrame) + { + mrMgr.ConnectSidebarWinToFrame( *(rSidebarItem.maLayoutInfo.mpAnchorFrame), + mrSidebarItem.GetFormatField(), + *this ); + } #endif if (SupportsDoubleBuffering()) diff --git a/sw/source/uibase/docvw/AnnotationWin2.cxx b/sw/source/uibase/docvw/AnnotationWin2.cxx index 4de72ca4d270..ef7300ad8314 100644 --- a/sw/source/uibase/docvw/AnnotationWin2.cxx +++ b/sw/source/uibase/docvw/AnnotationWin2.cxx @@ -1101,6 +1101,7 @@ void SwAnnotationWin::ExecuteCommand(sal_uInt16 nSlot) case FN_POSTIT: case FN_REPLY: { + const bool bReply = nSlot == FN_REPLY; // if this note is empty, it will be deleted once losing the focus, so no reply, but only a new note // will be created if (!mpOutliner->GetEditEngine().GetText().isEmpty()) @@ -1111,9 +1112,15 @@ void SwAnnotationWin::ExecuteCommand(sal_uInt16 nSlot) if (mrMgr.HasActiveSidebarWin()) mrMgr.SetActiveSidebarWin(nullptr); SwitchToFieldPos(); + + SwDocShell* pShell = mrView.GetDocShell(); + if (bReply) + pShell->GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::INSERT, nullptr); + + // synchronous dispatch mrView.GetViewFrame()->GetDispatcher()->Execute(FN_POSTIT); - if (nSlot == FN_REPLY) + if (bReply) { // Get newly created SwPostItField and set its paraIdParent auto pPostItField = mrMgr.GetLatestPostItField(); @@ -1121,6 +1128,16 @@ void SwAnnotationWin::ExecuteCommand(sal_uInt16 nSlot) pPostItField->SetParentPostItId(GetTopReplyNote()->GetPostItField()->GetPostItId()); this->GeneratePostItName(); pPostItField->SetParentName(GetTopReplyNote()->GetPostItField()->GetName()); + + // In this case, force generating the associated window + // synchronously so we can bundle its use of the registered + // "Answer" into the same undo group that the synchronous + // FN_POSTIT was put in + mrMgr.GetOrCreateAnnotationWindowForLatestPostItField(); + + SwRewriter aRewriter; + aRewriter.AddRule(UndoArg1, pPostItField->GetDescription()); + pShell->GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::INSERT, &aRewriter); } break; } @@ -1461,7 +1478,7 @@ void SwAnnotationWin::ChangeSidebarItem( SwSidebarItem const & rSidebarItem ) { #if !ENABLE_WASM_STRIP_ACCESSIBILITY const bool bAnchorChanged = mpAnchorFrame != rSidebarItem.maLayoutInfo.mpAnchorFrame; - if ( bAnchorChanged ) + if (bAnchorChanged && mpAnchorFrame) { mrMgr.DisconnectSidebarWinFromFrame( *mpAnchorFrame, *this ); } @@ -1469,6 +1486,7 @@ void SwAnnotationWin::ChangeSidebarItem( SwSidebarItem const & rSidebarItem ) mrSidebarItem = rSidebarItem; mpAnchorFrame = mrSidebarItem.maLayoutInfo.mpAnchorFrame; + assert(mpAnchorFrame); #if !ENABLE_WASM_STRIP_ACCESSIBILITY if (mxSidebarWinAccessible) diff --git a/sw/source/uibase/docvw/PostItMgr.cxx b/sw/source/uibase/docvw/PostItMgr.cxx index 501e3fa449d2..efd6e847563e 100644 --- a/sw/source/uibase/docvw/PostItMgr.cxx +++ b/sw/source/uibase/docvw/PostItMgr.cxx @@ -1866,6 +1866,11 @@ SwPostItField* SwPostItMgr::GetLatestPostItField() return static_cast(mvPostItFields.back()->GetFormatField().GetField()); } +sw::annotation::SwAnnotationWin* SwPostItMgr::GetOrCreateAnnotationWindowForLatestPostItField() +{ + return GetOrCreateAnnotationWindow(*mvPostItFields.back()); +} + SwAnnotationWin* SwPostItMgr::GetNextPostIt( sal_uInt16 aDirection, SwAnnotationWin* aPostIt ) { -- cgit v1.2.3