sc/source/ui/inc/viewfunc.hxx  |    3 -
 sc/source/ui/undo/undoblk3.cxx |    3 -
 sc/source/ui/view/cellsh3.cxx  |    8 ---
 sc/source/ui/view/viewfun2.cxx |   96 +++++++++++++++++++++++------------------
 4 files changed, 60 insertions(+), 50 deletions(-)

New commits:
commit 5c77b34a2004a2f6e7cab7a81b111ba22c2b96ba
Author:     Michael Meeks <michael.me...@collabora.com>
AuthorDate: Thu Nov 16 19:28:21 2023 +0000
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Sun Nov 19 02:18:27 2023 +0100

    lok: async calc merge-cells popup dialog.
    
    Change-Id: I6f7d1e8de4ac36f546706f7702157cc7e49c80b2
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159520
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/sc/source/ui/inc/viewfunc.hxx b/sc/source/ui/inc/viewfunc.hxx
index 0d8d7515441a..a62406020de5 100644
--- a/sc/source/ui/inc/viewfunc.hxx
+++ b/sc/source/ui/inc/viewfunc.hxx
@@ -236,7 +236,8 @@ public:
     bool            TestMergeCells();
     bool            TestRemoveMerge();
 
-    bool            MergeCells( bool bApi, bool& rDoContents, bool bCenter );
+    void            MergeCells( bool bApi, bool bDoContents, bool bCenter,
+                                const sal_uInt16 nSlot );
     bool            RemoveMerge();
 
     SC_DLLPUBLIC void
diff --git a/sc/source/ui/undo/undoblk3.cxx b/sc/source/ui/undo/undoblk3.cxx
index f614e0ff0b4a..43363fd6722c 100644
--- a/sc/source/ui/undo/undoblk3.cxx
+++ b/sc/source/ui/undo/undoblk3.cxx
@@ -755,8 +755,7 @@ void ScUndoMerge::Repeat(SfxRepeatTarget& rTarget)
     if (auto pViewTarget = dynamic_cast<ScTabViewTarget*>( &rTarget))
     {
         ScTabViewShell& rViewShell = *pViewTarget->GetViewShell();
-        bool bCont = false;
-        rViewShell.MergeCells( false, bCont, false );
+        rViewShell.MergeCells( false, false, false, 0 );
     }
 }
 
diff --git a/sc/source/ui/view/cellsh3.cxx b/sc/source/ui/view/cellsh3.cxx
index 72c7d94ff625..dab2ee7b6a3f 100644
--- a/sc/source/ui/view/cellsh3.cxx
+++ b/sc/source/ui/view/cellsh3.cxx
@@ -944,13 +944,7 @@ void ScCellShell::Execute( SfxRequest& rReq )
                         bMoveContents = static_cast<const 
SfxBoolItem*>(pItem)->GetValue();
                     }
 
-                    if (pTabViewShell->MergeCells( bApi, bMoveContents, 
bCenter ))
-                    {
-                        if (!bApi && bMoveContents)             // "yes" 
clicked in dialog
-                            rReq.AppendItem( SfxBoolItem( nSlot, bMoveContents 
) );
-                        rBindings.Invalidate( nSlot );
-                        rReq.Done();
-                    }
+                    pTabViewShell->MergeCells( bApi, bMoveContents, bCenter, 
nSlot );
                 }
                 else
                 {
diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx
index 884722204f0a..45aeb2a3cdce 100644
--- a/sc/source/ui/view/viewfun2.cxx
+++ b/sc/source/ui/view/viewfun2.cxx
@@ -20,6 +20,7 @@
 #include <scitems.hxx>
 
 #include <sfx2/app.hxx>
+#include <sfx2/request.hxx>
 #include <editeng/borderline.hxx>
 #include <editeng/boxitem.hxx>
 #include <editeng/fontitem.hxx>
@@ -1178,7 +1179,8 @@ bool ScViewFunc::TestMergeCells()           // pre-test 
(for menu)
         return false;
 }
 
-bool ScViewFunc::MergeCells( bool bApi, bool& rDoContents, bool bCenter )
+void ScViewFunc::MergeCells( bool bApi, bool bDoContents, bool bCenter,
+                             const sal_uInt16 nSlot )
 {
     //  Editable- and Being-Nested- test must be at the beginning (in DocFunc 
too),
     //  so that the Contents-QueryBox won't appear
@@ -1186,7 +1188,7 @@ bool ScViewFunc::MergeCells( bool bApi, bool& 
rDoContents, bool bCenter )
     if (!aTester.IsEditable())
     {
         ErrorMessage(aTester.GetMessageId());
-        return false;
+        return;
     }
 
     ScMarkData& rMark = GetViewData().GetMarkData();
@@ -1194,7 +1196,7 @@ bool ScViewFunc::MergeCells( bool bApi, bool& 
rDoContents, bool bCenter )
     if (!rMark.IsMarked())
     {
         ErrorMessage(STR_NOMULTISELECT);
-        return false;
+        return;
     }
 
     ScDocShell* pDocSh = GetViewData().GetDocShell();
@@ -1210,14 +1212,14 @@ bool ScViewFunc::MergeCells( bool bApi, bool& 
rDoContents, bool bCenter )
     if ( nStartCol == nEndCol && nStartRow == nEndRow )
     {
         // nothing to do
-        return true;
+        return;
     }
 
     if ( rDoc.HasAttrib( nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, 
nEndTab,
                             HasAttrFlags::Merged | HasAttrFlags::Overlapped ) )
     {       // "Don't nest merging  !"
         ErrorMessage(STR_MSSG_MERGECELLS_0);
-        return false;
+        return;
     }
 
     // Check for the contents of all selected tables.
@@ -1240,7 +1242,7 @@ bool ScViewFunc::MergeCells( bool bApi, bool& 
rDoContents, bool bCenter )
             {
                 // this range contains only one data cell.
                 if (nStartCol != aState.mnCol1 || nStartRow != aState.mnRow1)
-                    rDoContents = true; // move the value to the top-left.
+                    bDoContents = true; // move the value to the top-left.
                 break;
             }
             default:
@@ -1248,61 +1250,75 @@ bool ScViewFunc::MergeCells( bool bApi, bool& 
rDoContents, bool bCenter )
         }
     }
 
-    bool bOk = true;
     bool bEmptyMergedCells = 
officecfg::Office::Calc::Compatibility::MergeCells::EmptyMergedCells::get();
 
+    auto doMerge = [this, pDocSh, aMergeOption, bApi, nStartCol, nStartRow, 
aMarkRange]
+        (bool bNowDoContents, bool bNowEmptyMergedCells)
+    {
+        if (pDocSh->GetDocFunc().MergeCells(aMergeOption, bNowDoContents, 
true/*bRecord*/,
+                                             bApi, bNowEmptyMergedCells))
+        {
+            SetCursor( nStartCol, nStartRow );
+            // DoneBlockMode( sal_False);
+            Unmark();
+
+            pDocSh->UpdateOle(GetViewData());
+            UpdateInputLine();
+
+            OUString aStartAddress = aMarkRange.aStart.GetColRowString();
+            OUString aEndAddress = aMarkRange.aEnd.GetColRowString();
+
+            collectUIInformation({{"RANGE", aStartAddress + ":" + 
aEndAddress}}, "MERGE_CELLS");
+        }
+    };
+
     if (bAskDialog)
     {
         bool bShowDialog = 
officecfg::Office::Calc::Compatibility::MergeCells::ShowDialog::get();
         if (!bApi && bShowDialog)
         {
-            ScMergeCellsDialog aBox(GetViewData().GetDialogParent());
-            sal_uInt16 nRetVal = aBox.run();
+            auto pBox = 
std::make_shared<ScMergeCellsDialog>(GetViewData().GetDialogParent());
 
-            if ( nRetVal == RET_OK )
-            {
-                switch (aBox.GetMergeCellsOption())
+            SfxViewShell* pViewShell = GetViewData().GetViewShell();
+
+            pBox->runAsync(pBox, [=](sal_Int32 nRetVal) {
+                if (nRetVal == RET_OK)
                 {
+                    bool bRealDoContents = bDoContents;
+                    bool bRealEmptyMergedCells = bEmptyMergedCells;
+                    switch (pBox->GetMergeCellsOption())
+                    {
                     case MoveContentHiddenCells:
-                        rDoContents = true;
+                        bRealDoContents = true;
                         break;
                     case KeepContentHiddenCells:
-                        bEmptyMergedCells = false;
+                        bRealEmptyMergedCells = false;
                         break;
                     case EmptyContentHiddenCells:
-                        bEmptyMergedCells = true;
+                        bRealEmptyMergedCells = true;
                         break;
                     default:
                         assert(!"Unknown option for merge cells.");
                         break;
-                }
-            }
-            else if ( nRetVal == RET_CANCEL )
-                bOk = false;
-        }
-    }
-
-    if (bOk)
-    {
-        bOk = pDocSh->GetDocFunc().MergeCells( aMergeOption, rDoContents, 
true/*bRecord*/, bApi, bEmptyMergedCells );
-
-        if (bOk)
-        {
-            SetCursor( nStartCol, nStartRow );
-            //DoneBlockMode( sal_False);
-            Unmark();
-
-            pDocSh->UpdateOle(GetViewData());
-            UpdateInputLine();
+                    }
 
-            OUString aStartAddress = aMarkRange.aStart.GetColRowString();
-            OUString aEndAddress = aMarkRange.aEnd.GetColRowString();
+                    doMerge(bRealDoContents, bRealEmptyMergedCells);
 
-            collectUIInformation({{"RANGE", aStartAddress + ":" + 
aEndAddress}}, "MERGE_CELLS");
+                    if (nSlot != 0)
+                    {
+                        SfxRequest aReq(pViewShell->GetViewFrame(), nSlot);
+                        if (!bApi && bRealDoContents)
+                            aReq.AppendItem(SfxBoolItem(nSlot, bDoContents));
+                        SfxBindings& rBindings = 
pViewShell->GetViewFrame()->GetBindings();
+                        rBindings.Invalidate(nSlot);
+                        aReq.Done();
+                    }
+                }
+                // else cancelled
+            });
         }
-    }
-
-    return bOk;
+    } else
+        doMerge(bDoContents, bEmptyMergedCells);
 }
 
 bool ScViewFunc::TestRemoveMerge()

Reply via email to