sd/qa/unit/misc-tests.cxx   |   25 +++++++++++++++++++++++++
 sd/source/core/drawdoc3.cxx |    5 ++++-
 2 files changed, 29 insertions(+), 1 deletion(-)

New commits:
commit 8e489b8e47dce672aa558920a50721ac1f4ed1aa
Author:     Andreas Heinisch <andreas.heini...@yahoo.de>
AuthorDate: Sun Jan 12 12:44:50 2025 +0100
Commit:     Adolfo Jayme Barrientos <fit...@ubuntu.com>
CommitDate: Tue Jan 14 11:31:19 2025 +0100

    tdf#164284 - Prevent page name change during page move
    
    Change-Id: I341c5b9baf7cc39b8d543df89b4c46a59bf2a9e6
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180138
    Tested-by: Jenkins
    Reviewed-by: Andreas Heinisch <andreas.heini...@yahoo.de>
    (cherry picked from commit 74358a0f500a5f102791a55ac9e090df0c236488)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180154
    Reviewed-by: Adolfo Jayme Barrientos <fit...@ubuntu.com>

diff --git a/sd/qa/unit/misc-tests.cxx b/sd/qa/unit/misc-tests.cxx
index 7d66061c69ec..59628256fcce 100644
--- a/sd/qa/unit/misc-tests.cxx
+++ b/sd/qa/unit/misc-tests.cxx
@@ -83,6 +83,7 @@ public:
     void testTdf129898LayerDrawnInSlideshow();
     void testTdf136956();
     void testTdf39519();
+    void testTdf164284();
     void testEncodedTableStyles();
     void testTdf157117();
 
@@ -107,6 +108,7 @@ public:
     CPPUNIT_TEST(testTdf129898LayerDrawnInSlideshow);
     CPPUNIT_TEST(testTdf136956);
     CPPUNIT_TEST(testTdf39519);
+    CPPUNIT_TEST(testTdf164284);
     CPPUNIT_TEST(testEncodedTableStyles);
     CPPUNIT_TEST(testTdf157117);
     CPPUNIT_TEST_SUITE_END();
@@ -909,6 +911,29 @@ void SdMiscTest::testTdf39519()
     CPPUNIT_ASSERT(pCopiedPage->GetName() != pPage->GetName());
 }
 
+void SdMiscTest::testTdf164284()
+{
+    createSdImpressDoc();
+    SdXImpressDocument* pXImpressDocument = 
dynamic_cast<SdXImpressDocument*>(mxComponent.get());
+    CPPUNIT_ASSERT(pXImpressDocument);
+
+    // Change the name of the first page in the newly created document
+    SdDrawDocument* pDoc = pXImpressDocument->GetDoc();
+    SdPage* pPage = static_cast<SdPage*>(pDoc->GetPage(1));
+    pPage->SetName(u"Test"_ustr);
+
+    // Move a bookmark as a page using the same name
+    pDoc->DoMakePageObjectsNamesUnique(false);
+    std::vector<OUString> aBookmarkList = { u"Test"_ustr };
+    pDoc->InsertBookmarkAsPage(aBookmarkList, nullptr, false, false, 2, true, 
pDoc->GetDocSh(),
+                               true, false, false);
+
+    // Check if the moved page has the same name
+    SdPage* pMovedPage = static_cast<SdPage*>(pDoc->GetPage(2));
+    // Without the fix in place, the names of the pages would be different
+    CPPUNIT_ASSERT_EQUAL(pPage->GetName(), pMovedPage->GetName());
+}
+
 void SdMiscTest::testEncodedTableStyles()
 {
     // Silence unrelated failure:
diff --git a/sd/source/core/drawdoc3.cxx b/sd/source/core/drawdoc3.cxx
index f04e56712940..3e8c088e1067 100644
--- a/sd/source/core/drawdoc3.cxx
+++ b/sd/source/core/drawdoc3.cxx
@@ -724,7 +724,10 @@ bool SdDrawDocument::InsertBookmarkAsPage(
 
                 // tdf#39519 - rename page if its name is not unique, e.g., if 
a slide is copied by
                 // ctrl + drag and drop (DND_ACTION_COPY)
-                if (bMustRename || !mpDocSh->IsPageNameUnique(aPgName))
+                if (bMustRename
+                    // tdf#164284 - prevent page name change during page move
+                    || (pBookmarkDoc->DoesMakePageObjectsNamesUnique()
+                        && !mpDocSh->IsPageNameUnique(aPgName)))
                 {
                     // Page name already in use -> use default name for 
default and
                     // notes page

Reply via email to