sc/inc/globstr.hrc                    |    2 ++
 sc/inc/table.hxx                      |    2 +-
 sc/qa/uitest/calc_tests9/tdf115474.py |   29 +++++++++++++++++++++++++++++
 sc/source/core/data/documen3.cxx      |    7 +++++--
 sc/source/core/data/table4.cxx        |    5 ++++-
 sc/source/ui/docshell/docfunc.cxx     |   11 +++++++++++
 6 files changed, 52 insertions(+), 4 deletions(-)

New commits:
commit 52b95cfbb0aba120229f9f92570f2aa6f1fe3e33
Author:     Oliver Specht <oliver.spe...@cib.de>
AuthorDate: Wed May 22 12:39:12 2024 +0200
Commit:     Thorsten Behrens <thorsten.behr...@allotropia.de>
CommitDate: Tue Jun 18 22:06:42 2024 +0200

    Add warning and progress to AutoFormat
    
    Applying AutoFormat to large selections may take really long.
    A warning has been added to warn users.
    Additionally a progress is shown while AutoFormat is working.
    
    Change-Id: I74909a6243748ebfe0089406ebe947bb48eb93d5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167950
    Reviewed-by: Thorsten Behrens <thorsten.behr...@allotropia.de>
    Tested-by: Jenkins

diff --git a/sc/inc/globstr.hrc b/sc/inc/globstr.hrc
index 04bfae4f6f82..b7e695404743 100644
--- a/sc/inc/globstr.hrc
+++ b/sc/inc/globstr.hrc
@@ -270,6 +270,8 @@
 #define STR_HIDE                                NC_("STR_HIDE", "Hide")
 #define STR_PRINT                               NC_("STR_PRINT", "Print")
 #define STR_INVALID_AFAREA                      NC_("STR_INVALID_AFAREA", "To 
apply an AutoFormat,
a table range of at least
3 × 3 cells must be selected.")
+#define STR_AUTOFORMAT_WAIT_WARNING_TITLE       
NC_("STR_AUTOFORMAT_WAIT_WARNING_TITLE", "")
+#define STR_AUTOFORMAT_WAIT_WARNING             
NC_("STR_AUTOFORMAT_WAIT_WARNING", "Applying AutoFormat to the selected range 
may take a long time.
Do you want to proceed?")
 #define STR_OPTIONAL                            NC_("STR_OPTIONAL", 
"(optional)")
 #define STR_REQUIRED                            NC_("STR_REQUIRED", 
"(required)")
 #define STR_NOTES                               NC_("STR_NOTES", "Comments")
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 08f2fbce3015..8ddc5cdc3b09 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -723,7 +723,7 @@ public:
     void UpdateSelectionFunction( ScFunctionData& rData, const ScMarkData& 
rMark );
 
     void        AutoFormat( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, 
SCROW nEndRow,
-                                    sal_uInt16 nFormatNo );
+                                    sal_uInt16 nFormatNo, ScProgress* 
pProgress );
     void        GetAutoFormatData(SCCOL nStartCol, SCROW nStartRow, SCCOL 
nEndCol, SCROW nEndRow, ScAutoFormatData& rData);
     bool        SearchAndReplace(
         const SvxSearchItem& rSearchItem, SCCOL& rCol, SCROW& rRow, const 
ScMarkData& rMark,
diff --git a/sc/qa/uitest/calc_tests9/tdf115474.py 
b/sc/qa/uitest/calc_tests9/tdf115474.py
new file mode 100644
index 000000000000..92ca5cc7b7e6
--- /dev/null
+++ b/sc/qa/uitest/calc_tests9/tdf115474.py
@@ -0,0 +1,29 @@
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+from uitest.framework import UITestCase
+from uitest.uihelper.common import get_state_as_dict
+from uitest.uihelper.common import select_by_text, select_pos
+from libreoffice.calc.document import get_cell_by_position
+
+from libreoffice.uno.propertyvalue import mkPropertyValues
+
+class tdf115474(UITestCase):
+    def test_tdf115474_Warning_Dialog(self):
+        with self.ui_test.create_doc_in_start_center("calc") as document:
+            gridwin = self.xUITest.getTopFocusWindow().getChild("grid_window")
+            gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": 
"A1:C1000000"}))
+            with 
self.ui_test.execute_dialog_through_command(".uno:AutoFormat", close_button="") 
as xDialog:
+                formatlb = xDialog.getChild("formatlb")
+                entry = formatlb.getChild("2") # pick Box list blue
+                entry.executeAction("SELECT", tuple())
+
+                xOKBtn = xDialog.getChild("ok")
+                with 
self.ui_test.execute_blocking_action(xOKBtn.executeAction, args=('CLICK', ()), 
close_button="no"):
+                    # no background color set, we've skipped autoformat!
+                    self.assertEqual(get_cell_by_position(document, 0, 0, 
0).CellBackColor, -1)
diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx
index db8a9972e43f..6007ecf6d78f 100644
--- a/sc/source/core/data/documen3.cxx
+++ b/sc/source/core/data/documen3.cxx
@@ -55,6 +55,8 @@
 #include <inputopt.hxx>
 #include <chartlis.hxx>
 #include <sc.hrc>
+#include <globstr.hrc>
+#include <scresid.hxx>
 #include <hints.hxx>
 #include <dpobject.hxx>
 #include <drwlayer.hxx>
@@ -70,7 +72,7 @@
 #include <scopetools.hxx>
 #include <filterentries.hxx>
 #include <queryparam.hxx>
-
+#include <progress.hxx>
 #include <globalnames.hxx>
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
 #include <comphelper/lok.hxx>
@@ -1190,6 +1192,7 @@ OUString ScDocument::GetAutoFillPreview( const ScRange& 
rSource, SCCOL nEndX, SC
 void ScDocument::AutoFormat( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, 
SCROW nEndRow,
                                     sal_uInt16 nFormatNo, const ScMarkData& 
rMark )
 {
+    ScProgress aProgress(GetDocumentShell(), ScResId(STR_UNDO_AUTOFORMAT), 
nEndCol - nStartCol + 1, true);
     PutInOrder( nStartCol, nEndCol );
     PutInOrder( nStartRow, nEndRow );
     SCTAB nMax = maTabs.size();
@@ -1198,7 +1201,7 @@ void ScDocument::AutoFormat( SCCOL nStartCol, SCROW 
nStartRow, SCCOL nEndCol, SC
         if (rTab >= nMax)
             break;
         if (maTabs[rTab])
-            maTabs[rTab]->AutoFormat( nStartCol, nStartRow, nEndCol, nEndRow, 
nFormatNo );
+            maTabs[rTab]->AutoFormat( nStartCol, nStartRow, nEndCol, nEndRow, 
nFormatNo, &aProgress );
     }
 }
 
diff --git a/sc/source/core/data/table4.cxx b/sc/source/core/data/table4.cxx
index 63c595955220..157b0f01fac7 100644
--- a/sc/source/core/data/table4.cxx
+++ b/sc/source/core/data/table4.cxx
@@ -2684,7 +2684,7 @@ void ScTable::AutoFormatArea(SCCOL nStartCol, SCROW 
nStartRow, SCCOL nEndCol, SC
 }
 
 void ScTable::AutoFormat( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, 
SCROW nEndRow,
-                            sal_uInt16 nFormatNo )
+                            sal_uInt16 nFormatNo, ScProgress* pProgress )
 {
     if (!(ValidColRow(nStartCol, nStartRow) && ValidColRow(nEndCol, nEndRow)))
         return;
@@ -2814,6 +2814,9 @@ void ScTable::AutoFormat( SCCOL nStartCol, SCROW 
nStartRow, SCCOL nEndCol, SCROW
                     nIndex = 6;
                 else
                     nIndex = 5;
+                if (pProgress)
+                    pProgress->SetStateOnPercent(nCol);
+
             } // for nCol
         } // if not equal Column
     } // if not all equal
diff --git a/sc/source/ui/docshell/docfunc.cxx 
b/sc/source/ui/docshell/docfunc.cxx
index 61dc9d5603ae..fa2a37ea79d0 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -117,6 +117,8 @@
 using namespace com::sun::star;
 using ::std::vector;
 
+#define AUTOFORMAT_WARN_SIZE 0x10ffffUL
+
 void ScDocFunc::NotifyDrawUndo( std::unique_ptr<SdrUndoAction> pUndoAction)
 {
     // #i101118# if drawing layer collects the undo actions, add it there
@@ -4256,6 +4258,15 @@ bool ScDocFunc::AutoFormat( const ScRange& rRange, const 
ScMarkData* pTabMark,
         weld::WaitObject aWait( ScDocShell::GetActiveDialogParent() );
 
         bool bSize = 
pAutoFormat->findByIndex(nFormatNo)->GetIncludeWidthHeight();
+        if (sal_uInt64(nEndCol - nStartCol + 1) * sal_uInt64(nEndRow - 
nStartRow + 1) > AUTOFORMAT_WARN_SIZE)
+        {
+            std::unique_ptr<weld::MessageDialog> 
xQueryBox(Application::CreateMessageDialog(ScDocShell::GetActiveDialogParent(),
+                                                           
VclMessageType::Warning, VclButtonsType::YesNo,
+                                                           
ScResId(STR_AUTOFORMAT_WAIT_WARNING)));
+            xQueryBox->set_default_response(RET_NO);
+            if (xQueryBox->run() != RET_YES)
+                return false;
+        }
 
         SCTAB nTabCount = rDoc.GetTableCount();
         ScDocumentUniquePtr pUndoDoc;

Reply via email to