sc/qa/uitest/pasteSpecial/tdf139858.py |    7 ++++
 sc/qa/uitest/pasteSpecial/tdf158110.py |   48 +++++++++++++++++++++++++++++++++
 sc/qa/uitest/pasteSpecial/tdf160765.py |    9 +++++-
 sc/source/ui/miscdlgs/inscodlg.cxx     |    7 ++--
 sc/source/ui/view/viewfun3.cxx         |   21 ++++++++------
 5 files changed, 78 insertions(+), 14 deletions(-)

New commits:
commit 76941af9837406b1526b2f2d13c89df7a2023072
Author:     Andreas Heinisch <andreas.heini...@yahoo.de>
AuthorDate: Mon May 6 14:53:19 2024 +0200
Commit:     Andreas Heinisch <andreas.heini...@yahoo.de>
CommitDate: Wed May 22 07:27:32 2024 +0200

    tdf#158110 - Paste special: Remove special ADDNOTES flag handling
    
    Remove special ADDNOTES flag handling and just add it to existing NOTE flag 
to ensure no content will be deleted. However, the check for empty cells needs 
to be improved.
    
    Change-Id: I44ae75aa3997a0b1041447106bc3c07146043351
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167202
    Reviewed-by: Andreas Heinisch <andreas.heini...@yahoo.de>
    Tested-by: Jenkins

diff --git a/sc/qa/uitest/pasteSpecial/tdf139858.py 
b/sc/qa/uitest/pasteSpecial/tdf139858.py
old mode 100755
new mode 100644
index ca81c7715cb6..b5689ec3fdca
--- a/sc/qa/uitest/pasteSpecial/tdf139858.py
+++ b/sc/qa/uitest/pasteSpecial/tdf139858.py
@@ -12,6 +12,7 @@ from uitest.framework import UITestCase
 from libreoffice.calc.document import get_cell_by_position
 from libreoffice.uno.propertyvalue import mkPropertyValues
 from uitest.uihelper.calc import enter_text_to_cell
+from uitest.uihelper.common import get_state_as_dict
 from libreoffice.calc.paste_special import reset_default_values
 
 class tdf139858(UITestCase):
@@ -51,6 +52,12 @@ class tdf139858(UITestCase):
                     xCommentsChkBox = xPasteSpecialDlg.getChild("comments")
                     xCommentsChkBox.executeAction("CLICK", tuple())
 
+                # After tdf#158110 when an existing comment is overwritten, a 
confirmation dialog is shown
+                xCheckWarningDlg = self.xUITest.getTopFocusWindow()
+                if get_state_as_dict(xCheckWarningDlg)["ID"] == 
"CheckWarningDialog":
+                    xYesBtn = xCheckWarningDlg.getChild("yes")
+                    xYesBtn.executeAction("CLICK", tuple())
+
                 # Without the fix in place, this test would have failed with
                 # AssertionError: 'A1 sample text' != ''
                 # i.e., the cell content was overwritten
diff --git a/sc/qa/uitest/pasteSpecial/tdf158110.py 
b/sc/qa/uitest/pasteSpecial/tdf158110.py
new file mode 100644
index 000000000000..9b0dba6ed8cd
--- /dev/null
+++ b/sc/qa/uitest/pasteSpecial/tdf158110.py
@@ -0,0 +1,48 @@
+# -*- 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 libreoffice.calc.document import get_cell_by_position
+from libreoffice.uno.propertyvalue import mkPropertyValues
+from libreoffice.calc.paste_special import reset_default_values
+
+class tdf158110(UITestCase):
+    def test_tdf158110_paste_special_multiple_cells(self):
+        with self.ui_test.create_doc_in_start_center("calc") as document:
+            xGridWin = self.xUITest.getTopFocusWindow().getChild("grid_window")
+
+            # Insert a comment in cell A1
+            xGridWin.executeAction("SELECT", mkPropertyValues({"CELL":"A1"}))
+            xArgs = mkPropertyValues({"Text": "Comment 1"})
+            self.xUITest.executeCommandWithParameters(".uno:InsertAnnotation", 
xArgs)
+
+            # Copy cell range A1:A2 to clipboard
+            xGridWin.executeAction("SELECT", mkPropertyValues({"RANGE": 
"A1:A2"}))
+            self.xUITest.executeCommand(".uno:Copy")
+
+            # Paste data using special options (check only comments)
+            xGridWin.executeAction("SELECT", mkPropertyValues({"CELL": "B1"}))
+            with 
self.ui_test.execute_dialog_through_command(".uno:PasteSpecial") as 
xPasteSpecialDlg:
+                reset_default_values(self, xPasteSpecialDlg)
+                xDateTimeChkBox = xPasteSpecialDlg.getChild("datetime")
+                xDateTimeChkBox.executeAction("CLICK", tuple())
+                xTextChkBox = xPasteSpecialDlg.getChild("text")
+                xTextChkBox.executeAction("CLICK", tuple())
+                xNumbersChkBox = xPasteSpecialDlg.getChild("numbers")
+                xNumbersChkBox.executeAction("CLICK", tuple())
+                xCommentsChkBox = xPasteSpecialDlg.getChild("comments")
+                xCommentsChkBox.executeAction("CLICK", tuple())
+
+            # Without the fix in place, this test would have failed with
+            # AssertionError: 'Comment 1' != ''
+            # i.e., the comment was not copied
+            self.assertEqual("Comment 1", get_cell_by_position(document, 0, 1, 
0).Annotation.String)
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sc/qa/uitest/pasteSpecial/tdf160765.py 
b/sc/qa/uitest/pasteSpecial/tdf160765.py
old mode 100755
new mode 100644
index c0c264432ef4..7c4dd4b9cf5c
--- a/sc/qa/uitest/pasteSpecial/tdf160765.py
+++ b/sc/qa/uitest/pasteSpecial/tdf160765.py
@@ -42,7 +42,8 @@ class tdf160765(UITestCase):
                 xCommentsChkBox = xPasteSpecialDlg.getChild("comments")
                 xCommentsChkBox.executeAction("CLICK", tuple())
 
-            with 
self.ui_test.execute_dialog_through_command(".uno:PasteSpecial") as 
xPasteSpecialDlg:
+            # After tdf#158110 when an existing comment is overwritten, a 
confirmation dialog is shown, so close dialog without any action
+            with 
self.ui_test.execute_dialog_through_command(".uno:PasteSpecial", 
close_button="cancel") as xPasteSpecialDlg:
                 xCommentsChkBox = xPasteSpecialDlg.getChild("comments")
                 # Without the fix in place, this test would have failed with
                 # AssertionError: 'true' != 'false'
@@ -85,6 +86,12 @@ class tdf160765(UITestCase):
                     xCommentsChkBox = xPasteSpecialDlg.getChild("comments")
                     xCommentsChkBox.executeAction("CLICK", tuple())
 
+                # After tdf#158110 when an existing comment is overwritten, a 
confirmation dialog is shown
+                xCheckWarningDlg = self.xUITest.getTopFocusWindow()
+                if get_state_as_dict(xCheckWarningDlg)["ID"] == 
"CheckWarningDialog":
+                    xYesBtn = xCheckWarningDlg.getChild("yes")
+                    xYesBtn.executeAction("CLICK", tuple())
+
             # Undo both inserted comments
             self.xUITest.executeCommand(".uno:Undo")
             # Without the fix in place, this test would have failed with
diff --git a/sc/source/ui/miscdlgs/inscodlg.cxx 
b/sc/source/ui/miscdlgs/inscodlg.cxx
index 378b10f37fd0..1bff0777792b 100644
--- a/sc/source/ui/miscdlgs/inscodlg.cxx
+++ b/sc/source/ui/miscdlgs/inscodlg.cxx
@@ -215,7 +215,8 @@ InsertDeleteFlags 
ScInsertContentsDlg::GetInsContentsCmdBits() const
         ScInsertContentsDlg::nPreviousChecks |= InsertDeleteFlags::FORMULA;
     // tdf#139858 - do not delete existing cell contents when pasting notes
     if ( mxBtnInsNotes->get_active()   )
-        ScInsertContentsDlg::nPreviousChecks |= InsertDeleteFlags::ADDNOTES;
+        ScInsertContentsDlg::nPreviousChecks
+            |= InsertDeleteFlags::NOTE | InsertDeleteFlags::ADDNOTES;
     if ( mxBtnInsAttrs->get_active()   )
         ScInsertContentsDlg::nPreviousChecks |= InsertDeleteFlags::ATTRIB;
     if ( mxBtnInsObjects->get_active() )
@@ -231,9 +232,7 @@ void ScInsertContentsDlg::SetInsContentsCmdBits(const 
InsertDeleteFlags eFlags)
     mxBtnInsNumbers->set_active((InsertDeleteFlags::VALUE & eFlags) == 
InsertDeleteFlags::VALUE);
     mxBtnInsDateTime->set_active((InsertDeleteFlags::DATETIME & eFlags) == 
InsertDeleteFlags::DATETIME);
     mxBtnInsStrings->set_active((InsertDeleteFlags::STRING & eFlags) == 
InsertDeleteFlags::STRING);
-    // tdf#160765 - additionally check either NOTE or ADDNOTES
-    mxBtnInsNotes->set_active(((InsertDeleteFlags::NOTE | 
InsertDeleteFlags::ADDNOTES) & eFlags)
-                              != InsertDeleteFlags::NONE);
+    mxBtnInsNotes->set_active((InsertDeleteFlags::NOTE & eFlags) == 
InsertDeleteFlags::NOTE);
     mxBtnInsFormulas->set_active((InsertDeleteFlags::FORMULA & eFlags) == 
InsertDeleteFlags::FORMULA);
     mxBtnInsAttrs->set_active((InsertDeleteFlags::ATTRIB & eFlags) == 
InsertDeleteFlags::ATTRIB);
     mxBtnInsObjects->set_active((InsertDeleteFlags::OBJECTS & eFlags) == 
InsertDeleteFlags::OBJECTS);
diff --git a/sc/source/ui/view/viewfun3.cxx b/sc/source/ui/view/viewfun3.cxx
index e287609906b6..bed890278a3f 100644
--- a/sc/source/ui/view/viewfun3.cxx
+++ b/sc/source/ui/view/viewfun3.cxx
@@ -846,7 +846,9 @@ static bool lcl_SelHasAttrib( const ScDocument& rDoc, SCCOL 
nCol1, SCROW nRow1,
 
 namespace {
 
-bool checkDestRangeForOverwrite(const ScRangeList& rDestRanges, const 
ScDocument& rDoc, const ScMarkData& rMark, weld::Window* pParentWnd)
+bool checkDestRangeForOverwrite(InsertDeleteFlags nFlags, const ScRangeList& 
rDestRanges,
+                                const ScDocument& rDoc, const ScMarkData& 
rMark,
+                                weld::Window* pParentWnd)
 {
     bool bIsEmpty = true;
     size_t nRangeSize = rDestRanges.size();
@@ -855,9 +857,11 @@ bool checkDestRangeForOverwrite(const ScRangeList& 
rDestRanges, const ScDocument
         for (size_t i = 0; i < nRangeSize && bIsEmpty; ++i)
         {
             const ScRange& rRange = rDestRanges[i];
-            bIsEmpty = rDoc.IsBlockEmpty(
-                rRange.aStart.Col(), rRange.aStart.Row(),
-                rRange.aEnd.Col(), rRange.aEnd.Row(), rTab );
+            if (nFlags & InsertDeleteFlags::ADDNOTES)
+                bIsEmpty = !rDoc.HasNote(rRange.aStart) && 
!rDoc.HasNote(rRange.aEnd);
+            else
+                bIsEmpty = rDoc.IsBlockEmpty(rRange.aStart.Col(), 
rRange.aStart.Row(),
+                                             rRange.aEnd.Col(), 
rRange.aEnd.Row(), rTab);
         }
         if (!bIsEmpty)
             break;
@@ -894,8 +898,7 @@ bool ScViewFunc::PasteFromClip( InsertDeleteFlags nFlags, 
ScDocument* pClipDoc,
 
     //  undo: save all or no content
     InsertDeleteFlags nContFlags = InsertDeleteFlags::NONE;
-    // tdf#160765 - save content for undo when pasting notes, even if no 
content was changed
-    if (nFlags & (InsertDeleteFlags::CONTENTS | InsertDeleteFlags::ADDNOTES))
+    if (nFlags & InsertDeleteFlags::CONTENTS)
         nContFlags |= InsertDeleteFlags::CONTENTS;
     if (nFlags & InsertDeleteFlags::ATTRIB)
         nContFlags |= InsertDeleteFlags::ATTRIB;
@@ -1167,7 +1170,7 @@ bool ScViewFunc::PasteFromClip( InsertDeleteFlags nFlags, 
ScDocument* pClipDoc,
         if ( bAskIfNotEmpty )
         {
             ScRangeList aTestRanges(aUserRange);
-            if (!checkDestRangeForOverwrite(aTestRanges, rDoc, aFilteredMark, 
GetViewData().GetDialogParent()))
+            if (!checkDestRangeForOverwrite(nFlags, aTestRanges, rDoc, 
aFilteredMark, GetViewData().GetDialogParent()))
                 return false;
         }
     }
@@ -1552,7 +1555,7 @@ bool 
ScViewFunc::PasteMultiRangesFromClip(InsertDeleteFlags nFlags, ScDocument*
     if (bAskIfNotEmpty)
     {
         ScRangeList aTestRanges(aMarkedRange);
-        if (!checkDestRangeForOverwrite(aTestRanges, rDoc, aMark, 
GetViewData().GetDialogParent()))
+        if (!checkDestRangeForOverwrite(nFlags, aTestRanges, rDoc, aMark, 
GetViewData().GetDialogParent()))
             return false;
     }
 
@@ -1719,7 +1722,7 @@ bool ScViewFunc::PasteFromClipToMultiRanges(
 
     if (bAskIfNotEmpty)
     {
-        if (!checkDestRangeForOverwrite(aRanges, rDoc, aMark, 
GetViewData().GetDialogParent()))
+        if (!checkDestRangeForOverwrite(nFlags, aRanges, rDoc, aMark, 
GetViewData().GetDialogParent()))
             return false;
     }
 

Reply via email to