sc/inc/globstr.hrc                         |    8 ++-
 sc/qa/uitest/calc_tests/calcSheetDelete.py |    9 +--
 sc/qa/uitest/calc_tests2/tdf114992.py      |    3 -
 sc/qa/uitest/range_name/tdf150307.py       |    3 -
 sc/source/ui/view/tabvwshf.cxx             |   71 ++++++++++++++++++++++-------
 5 files changed, 66 insertions(+), 28 deletions(-)

New commits:
commit 41b991ea0cf3f8ce36cbdbf16b9c2c6d2bb16b5d
Author:     Laurent Balland <laurent.ball...@mailo.fr>
AuthorDate: Mon Feb 20 08:46:23 2023 +0100
Commit:     Laurent Balland <laurent.ball...@mailo.fr>
CommitDate: Mon Feb 27 09:43:03 2023 +0000

    tdf#153709 Adapt message for Delete Sheet
    
    When deleting sheets, the message is adapted to the count of selected
    sheets (singular or plural).
    The confirmation message is skipped if selected sheets are empty
    The message for pivot table data losing is replaced by regular
    confirmation message if both pivot table and data are selected
    
    Update UItests when there is no more confirmation
    
    Change-Id: I5cbd6d7cbe271ad86c5c68820b23df5a2307f3bc
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147309
    Reviewed-by: Eike Rathke <er...@redhat.com>
    Tested-by: Jenkins
    Reviewed-by: Laurent Balland <laurent.ball...@mailo.fr>

diff --git a/sc/inc/globstr.hrc b/sc/inc/globstr.hrc
index 19e99d1c47d0..95f7138c81c9 100644
--- a/sc/inc/globstr.hrc
+++ b/sc/inc/globstr.hrc
@@ -268,7 +268,9 @@
 #define STR_OPTIONAL                            NC_("STR_OPTIONAL", 
"(optional)")
 #define STR_REQUIRED                            NC_("STR_REQUIRED", 
"(required)")
 #define STR_NOTES                               NC_("STR_NOTES", "Comments")
-#define STR_QUERY_DELTAB                        NC_("STR_QUERY_DELTAB", "Are 
you sure you want to delete the selected sheet(s)?")
+/* %d will be replaced by the number of selected sheets
+     e.g. Are you sure you want to delete the 3 selected sheets? */
+#define STR_QUERY_DELTAB                        NNC_("STR_QUERY_DELTAB", "Are 
you sure you want to delete the selected sheet?", "Are you sure you want to 
delete the %d selected sheets?")
 #define STR_QUERY_DELSCENARIO                   NC_("STR_QUERY_DELSCENARIO", 
"Are you sure you want to delete the selected scenario?")
 #define STR_EXPORT_ASCII                        NC_("STR_EXPORT_ASCII", 
"Export Text File")
 #define STR_IMPORT_LOTUS                        NC_("STR_IMPORT_LOTUS", 
"Import Lotus files")
@@ -533,7 +535,9 @@
 #define STR_FRACTION                            NC_("STR_FRACTION", "Fraction")
 #define STR_BOOLEAN_VALUE                       NC_("STR_BOOLEAN_VALUE", 
"Boolean Value")
 #define STR_TEXT                                NC_("STR_TEXT", "Text")
-#define STR_QUERY_PIVOTTABLE_DELTAB             
NC_("STR_QUERY_PIVOTTABLE_DELTAB", "The selected sheet(s) contain source data 
of related pivot tables that will be lost. Are you sure you want to delete the 
selected sheet(s)?")
+/* %d will be replaced by the number of selected sheets
+    e.g. The 3 selected sheets contain source data of related pivot tables 
that will be lost. */
+#define STR_QUERY_PIVOTTABLE_DELTAB             
NNC_("STR_QUERY_PIVOTTABLE_DELTAB", "The selected sheet contains source data of 
related pivot tables that will be lost.", "The %d selected sheets contain 
source data of related pivot tables that will be lost.")
 #define STR_ERR_NAME_INVALID_CELL_REF           
NC_("STR_ERR_NAME_INVALID_CELL_REF", "Invalid name. Reference to a cell, or a 
range of cells not allowed.")
 #define STR_ERR_LONG_LINK_FORMULA_NEEDING_CHECK 
NC_("STR_ERR_LONG_LINK_FORMULA_NEEDING_CHECK", "External content disabled.")
 #define STR_TEXTORIENTANGLE                     NC_("STR_TEXTORIENTANGLE", 
"Text orientation angle")
diff --git a/sc/qa/uitest/calc_tests/calcSheetDelete.py 
b/sc/qa/uitest/calc_tests/calcSheetDelete.py
index 3e9da3f516d4..380d6766943e 100644
--- a/sc/qa/uitest/calc_tests/calcSheetDelete.py
+++ b/sc/qa/uitest/calc_tests/calcSheetDelete.py
@@ -28,8 +28,7 @@ class calcSheetDelete(UITestCase):
 
             self.assertEqual(document.Sheets.getCount(), nrSheets + 1)
 
-            with self.ui_test.execute_dialog_through_command(".uno:Remove", 
close_button="yes"):
-                pass
+            self.xUITest.executeCommand(".uno:Remove")
             xToolkit = 
self.xContext.ServiceManager.createInstance('com.sun.star.awt.Toolkit')
             xToolkit.processEventsToIdle()
 
@@ -85,8 +84,7 @@ class calcSheetDelete(UITestCase):
                 self.xUITest.executeCommand(".uno:JumpToNextTableSel")  
#select next sheet
                 i = i + 1
 
-            with self.ui_test.execute_dialog_through_command(".uno:Remove", 
close_button="yes"):
-                pass
+            self.xUITest.executeCommand(".uno:Remove")
 
             xToolkit = 
self.xContext.ServiceManager.createInstance('com.sun.star.awt.Toolkit')
             xToolkit.processEventsToIdle()
@@ -115,8 +113,7 @@ class calcSheetDelete(UITestCase):
                 self.xUITest.executeCommand(".uno:JumpToNextTableSel")  
#select next sheet
                 i = i + 1
 
-            with self.ui_test.execute_dialog_through_command(".uno:Remove", 
close_button="yes"):
-                pass
+            self.xUITest.executeCommand(".uno:Remove")
 
             self.assertEqual(document.Sheets.getCount(), nrSheets)
             self.xUITest.executeCommand(".uno:Undo")
diff --git a/sc/qa/uitest/calc_tests2/tdf114992.py 
b/sc/qa/uitest/calc_tests2/tdf114992.py
index 6b3a97b0ec13..6f1b888d616c 100644
--- a/sc/qa/uitest/calc_tests2/tdf114992.py
+++ b/sc/qa/uitest/calc_tests2/tdf114992.py
@@ -14,8 +14,7 @@ from uitest.uihelper.common import get_url_for_data_file
 class tdf114992(UITestCase):
     def test_tdf114992_delete_sheet_crash(self):
         with self.ui_test.load_file(get_url_for_data_file("tdf114992.ods")) as 
calc_doc:
-            with self.ui_test.execute_dialog_through_command(".uno:Remove", 
close_button="yes"):
-                pass
+            self.xUITest.executeCommand(".uno:Remove")
 
             self.assertEqual(calc_doc.Sheets.getCount(), 1)
             self.xUITest.executeCommand(".uno:Undo")
diff --git a/sc/qa/uitest/range_name/tdf150307.py 
b/sc/qa/uitest/range_name/tdf150307.py
index 056445408fce..2f9e44720bc6 100644
--- a/sc/qa/uitest/range_name/tdf150307.py
+++ b/sc/qa/uitest/range_name/tdf150307.py
@@ -57,8 +57,7 @@ class tdf150307(UITestCase):
 
             self.check_navigator(xGridWin, 2)
 
-            with self.ui_test.execute_dialog_through_command(".uno:Remove", 
close_button="yes"):
-                pass
+            self.xUITest.executeCommand(".uno:Remove")
 
             self.check_navigator(xGridWin, 1)
 
diff --git a/sc/source/ui/view/tabvwshf.cxx b/sc/source/ui/view/tabvwshf.cxx
index 7580ba7fe603..5029f6088cb0 100644
--- a/sc/source/ui/view/tabvwshf.cxx
+++ b/sc/source/ui/view/tabvwshf.cxx
@@ -660,27 +660,49 @@ void ScTabViewShell::ExecuteTable( SfxRequest& rReq )
                         if (pDPs)
                         {
                             const ScMarkData::MarkedTabsType& rSelectedTabs = 
rViewData.GetMarkData().GetSelectedTabs();
-                            for (const SCTAB nSelTab : rSelectedTabs)
+                            const size_t nCount = pDPs->GetCount();
+                            for (size_t i = 0; i < nCount; ++i)
                             {
-                                const size_t nCount = pDPs->GetCount();
-                                for (size_t i = 0; i < nCount; ++i)
+                                const ScDPObject& rDPObj = (*pDPs)[i];
+                                const ScSheetSourceDesc* pSheetSourceDesc = 
rDPObj.GetSheetDesc();
+                                if (pSheetSourceDesc)
                                 {
-                                    const ScDPObject& rDPObj = (*pDPs)[i];
-                                    const ScSheetSourceDesc* pSheetSourceDesc 
= rDPObj.GetSheetDesc();
-                                    if (pSheetSourceDesc && 
pSheetSourceDesc->GetSourceRange().aStart.Tab() == nSelTab)
-                                        bTabWithPivotTable = true;
+                                    SCTAB nTabOut = 
rDPObj.GetOutRange().aStart.Tab();
+                                    SCTAB nTabSource = 
pSheetSourceDesc->GetSourceRange().aStart.Tab();
+                                    bool bTabOutSel = false;
+                                    for (const SCTAB nSelTab : rSelectedTabs)
+                                    {
+                                        if (nSelTab == nTabSource)
+                                            bTabWithPivotTable = true;
+                                        if (nSelTab == nTabOut)
+                                            bTabOutSel = true;
+                                        if (bTabWithPivotTable && bTabOutSel)
+                                            break;
+                                    }
+                                    // if both pivot table and data are 
selected
+                                    // no need to warn for source data loosing
+                                    if (bTabWithPivotTable && bTabOutSel)
+                                        bTabWithPivotTable = false;
+                                    if (bTabWithPivotTable)
+                                        break;
                                 }
-                                if (bTabWithPivotTable)
-                                    break;
                             }
                         }
                     }
 
+                    SCTAB nTabSelCnt = 
rViewData.GetMarkData().GetSelectCount();
+                    OUString aTabSelCnt = 
Application::GetSettings().GetUILocaleDataWrapper().getNum( nTabSelCnt, 0 );
+                    OUString aQueryDeleteTab = ScResId( STR_QUERY_DELTAB, 
nTabSelCnt )
+                                                        .replaceAll( "%d", 
aTabSelCnt );
                     if (bTabWithPivotTable)
                     {
+                        OUString aStr = ScResId( STR_QUERY_PIVOTTABLE_DELTAB, 
nTabSelCnt )
+                                                        .replaceAll( "%d", 
aTabSelCnt )
+                                                        + " " + 
aQueryDeleteTab;
+
                         std::unique_ptr<weld::MessageDialog> 
xQueryBox(Application::CreateMessageDialog(GetFrameWeld(),
                                                                        
VclMessageType::Question, VclButtonsType::YesNo,
-                                                                       
ScResId(STR_QUERY_PIVOTTABLE_DELTAB)));
+                                                                       aStr));
                         xQueryBox->set_default_response(RET_NO);
 
                         // Hard warning as there is potential of data loss on 
deletion
@@ -688,13 +710,30 @@ void ScTabViewShell::ExecuteTable( SfxRequest& rReq )
                     }
                     else
                     {
-                        std::unique_ptr<weld::MessageDialog> 
xQueryBox(Application::CreateMessageDialog(GetFrameWeld(),
-                                                                       
VclMessageType::Question, VclButtonsType::YesNo,
-                                                                       
ScResId(STR_QUERY_DELTAB)));
-                        xQueryBox->set_default_response(RET_YES);
+                        bool bHasData = false;
+                        ScMarkData& rMark = rViewData.GetMarkData();
+                        for ( SCTAB i = 0; i < nTabCount && !bHasData; i++ )
+                        {
+                            if ( rMark.GetTableSelect(i) && 
!rDoc.IsTabProtected(i) )
+                            {
+                                SCCOL nStartCol;
+                                SCROW nStartRow;
+                                bHasData = rDoc.GetDataStart( i, nStartCol, 
nStartRow );
+                            }
+                        }
+                        // Do not ask for confirmation if all selected tabs 
are empty
+                        if (bHasData)
+                        {
+                            std::unique_ptr<weld::MessageDialog> 
xQueryBox(Application::CreateMessageDialog(GetFrameWeld(),
+                                                                           
VclMessageType::Question, VclButtonsType::YesNo,
+                                                                           
aQueryDeleteTab));
+                            xQueryBox->set_default_response(RET_YES);
 
-                        // no parameter given, ask for confirmation
-                        bDoIt = (RET_YES == xQueryBox->run());
+                            // no parameter given, ask for confirmation
+                            bDoIt = (RET_YES == xQueryBox->run());
+                        }
+                        else
+                            bDoIt = true;
                     }
                 }
 

Reply via email to