tdf#151828 fix table name changes on cut and paste
Change-Id: Ibd9fc78d88732b63d418404fa23e1560bf531fbf
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142984
Tested-by: Jenkins
Tested-by: Heiko Tietze <heiko.tietze@documentfoundation.org>
Reviewed-by: Heiko Tietze <heiko.tietze@documentfoundation.org>
Reviewed-by: Jim Raykowski <raykowj@gmail.com>
diff --git a/sw/qa/extras/uiwriter/uiwriter6.cxx b/sw/qa/extras/uiwriter/uiwriter6.cxx
index ad883c5..dc6db05 100644
--- a/sw/qa/extras/uiwriter/uiwriter6.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter6.cxx
@@ -2259,6 +2259,43 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf151828_Comment2)
CPPUNIT_ASSERT_EQUAL(OUString("Shape"), pObject->GetName());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf151828)
{
createSwDoc();
SwDoc* pDoc = getSwDoc();
SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
// insert a table
SwInsertTableOptions TableOpt(SwInsertTableFlags::DefaultBorder, 0);
pWrtShell->InsertTable(TableOpt, 1, 1);
// move cursor into the table
CPPUNIT_ASSERT(pWrtShell->MoveTable(GotoPrevTable, fnTableStart));
SwFrameFormat* pFormat = pWrtShell->GetTableFormat();
CPPUNIT_ASSERT(pFormat);
// set name of table to 'MyTableName'
pWrtShell->SetTableName(*pFormat, "MyTableName");
// cut and paste the table
dispatchCommand(mxComponent, ".uno:SelectTable", {});
Scheduler::ProcessEventsToIdle();
dispatchCommand(mxComponent, ".uno:Cut", {});
Scheduler::ProcessEventsToIdle();
dispatchCommand(mxComponent, ".uno:Paste", {});
Scheduler::ProcessEventsToIdle();
// move cursor into the pasted table
CPPUNIT_ASSERT(pWrtShell->MoveTable(GotoPrevTable, fnTableStart));
pFormat = pWrtShell->GetTableFormat();
CPPUNIT_ASSERT(pFormat);
// Before the fix the pasted table name was 'Table1'.
CPPUNIT_ASSERT_EQUAL(OUString("MyTableName"), pFormat->GetName());
}
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/docnode/ndcopy.cxx b/sw/source/core/docnode/ndcopy.cxx
index b5383174..1f27421 100644
--- a/sw/source/core/docnode/ndcopy.cxx
+++ b/sw/source/core/docnode/ndcopy.cxx
@@ -258,11 +258,14 @@ SwTableNode* SwTableNode::MakeCopy( SwDoc& rDoc, const SwNodeIndex& rIdx ) const
{
const SwFrameFormats& rTableFormats = *rDoc.GetTableFrameFormats();
for( size_t n = rTableFormats.size(); n; )
if( rTableFormats[ --n ]->GetName() == sTableName )
{
const SwFrameFormat* pFormat = rTableFormats[--n];
if (pFormat->GetName() == sTableName && rDoc.IsUsed(*pFormat))
{
sTableName = rDoc.GetUniqueTableName();
break;
}
}
}
SwFrameFormat* pTableFormat = rDoc.MakeTableFrameFormat( sTableName, rDoc.GetDfltFrameFormat() );