sw/inc/PostItMgr.hxx                      |    1 +
 sw/source/uibase/docvw/AnnotationWin2.cxx |   22 +++++++++++++++++++++-
 sw/source/uibase/docvw/PostItMgr.cxx      |    5 +++++
 3 files changed, 27 insertions(+), 1 deletion(-)

New commits:
commit 124a988ea99096ea5080060c0d1a801528bd7a5c
Author:     Pranam Lashkari <lpra...@collabora.com>
AuthorDate: Wed May 22 11:57:57 2024 +0100
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Wed May 29 14:24:31 2024 +0200

    create comment reply synchronously
    
    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/+/168190
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sw/inc/PostItMgr.hxx b/sw/inc/PostItMgr.hxx
index 1a6dac4a8f62..e2922a045a1c 100644
--- a/sw/inc/PostItMgr.hxx
+++ b/sw/inc/PostItMgr.hxx
@@ -195,6 +195,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/AnnotationWin2.cxx 
b/sw/source/uibase/docvw/AnnotationWin2.cxx
index 75edfe80edb2..a20255f1c37b 100644
--- a/sw/source/uibase/docvw/AnnotationWin2.cxx
+++ b/sw/source/uibase/docvw/AnnotationWin2.cxx
@@ -1053,6 +1053,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())
@@ -1063,16 +1064,35 @@ void SwAnnotationWin::ExecuteCommand(sal_uInt16 nSlot)
             if (mrMgr.HasActiveSidebarWin())
                 mrMgr.SetActiveSidebarWin(nullptr);
             SwitchToFieldPos();
+
+            SwDocShell* pShell = mrView.GetDocShell();
+            if (bReply)
+                
pShell->GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::START, nullptr);
+
+            // synchronous dispatch
             mrView.GetViewFrame().GetDispatcher()->Execute(FN_POSTIT);
 
-            if (nSlot == FN_REPLY)
+            if (bReply)
             {
+                SwUndoId nUndoId(SwUndoId::END);
+                mrView.GetWrtShell().GetLastUndoInfo(nullptr, &nUndoId);
+
                 // Get newly created SwPostItField and set its paraIdParent
                 auto pPostItField = mrMgr.GetLatestPostItField();
                 pPostItField->SetParentId(GetTopReplyNote()->GetParaId());
                 
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(nUndoId, 
&aRewriter);
             }
             break;
         }
diff --git a/sw/source/uibase/docvw/PostItMgr.cxx 
b/sw/source/uibase/docvw/PostItMgr.cxx
index ebd1223c586d..afb2238c3a04 100644
--- a/sw/source/uibase/docvw/PostItMgr.cxx
+++ b/sw/source/uibase/docvw/PostItMgr.cxx
@@ -1858,6 +1858,11 @@ SwPostItField* SwPostItMgr::GetLatestPostItField()
     return 
static_cast<SwPostItField*>(mvPostItFields.back()->GetFormatField().GetField());
 }
 
+sw::annotation::SwAnnotationWin* 
SwPostItMgr::GetOrCreateAnnotationWindowForLatestPostItField()
+{
+    return GetOrCreateAnnotationWindow(*mvPostItFields.back());
+}
+
 SwAnnotationWin* SwPostItMgr::GetNextPostIt( sal_uInt16 aDirection,
                                           SwAnnotationWin* aPostIt )
 {

Reply via email to