From 50b731c84cb17d7f05a690d90588e90ee267d1c2 Mon Sep 17 00:00:00 2001 From: Jim Raykowski Date: Thu, 12 Nov 2020 13:18:16 -0900 Subject: tdf#34828 Give draw object a name when made For Writer and Calc this patch sets a name to a newly created draw object. The name is constructed from the defined singular name of the object, followed by a space, followed by the first available whole number begining with 1 that will provide name uniqueness. For Draw/Impress names are not set for an object on creation. Unnamed objects have unique names given only in the Navigator tree. The unnamed object names shown in the tree are based on the order of shapes in the document. This patch does not change any name behavior for Draw/Impress. Change-Id: I91f31364c8258f7abb5810a5865fefd6b249da03 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105774 Tested-by: Jenkins Reviewed-by: Noel Grandin --- svx/source/svdraw/svdedtv.cxx | 12 ++++++++++++ svx/source/svdraw/svdobj.cxx | 38 ++++++++++++++++++++++++++++++-------- 2 files changed, 42 insertions(+), 8 deletions(-) (limited to 'svx') diff --git a/svx/source/svdraw/svdedtv.cxx b/svx/source/svdraw/svdedtv.cxx index 56cd41c700b1..c49474cf6c20 100644 --- a/svx/source/svdraw/svdedtv.cxx +++ b/svx/source/svdraw/svdedtv.cxx @@ -36,6 +36,7 @@ #include #include +#include using namespace com::sun::star; @@ -1002,6 +1003,17 @@ bool SdrEditView::InsertObjectAtView(SdrObject* pObj, SdrPageView& rPV, SdrInser AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoNewObject(*pObj)); } + css::uno::Reference xServices(GetModel()->getUnoModel(), + css::uno::UNO_QUERY); + if (xServices->supportsService("com.sun.star.sheet.SpreadsheetDocument") || + xServices->supportsService("com.sun.star.text.TextDocument")) + { + const bool bUndo(IsUndoEnabled()); + GetModel()->EnableUndo(false); + pObj->MakeNameUnique(); + GetModel()->EnableUndo(bUndo); + } + if (!(nOptions & SdrInsertFlags::DONTMARK)) { if (!(nOptions & SdrInsertFlags::ADDMARK)) UnmarkAllObj(); MarkObj(pObj,&rPV); diff --git a/svx/source/svdraw/svdobj.cxx b/svx/source/svdraw/svdobj.cxx index 9413f5152d47..71272cb85a20 100644 --- a/svx/source/svdraw/svdobj.cxx +++ b/svx/source/svdraw/svdobj.cxx @@ -118,6 +118,9 @@ #include #include +#include +#include + using namespace ::com::sun::star; @@ -3060,6 +3063,22 @@ bool SdrObject::IsTextBox() const void SdrObject::MakeNameUnique() { + if (GetName().isEmpty()) + { + if (const E3dScene* pE3dObj = dynamic_cast(this)) + { + SdrObjList* pObjList = pE3dObj->GetSubList(); + if (pObjList) + { + SdrObject* pObj0 = pObjList->GetObj(0); + if (pObj0) + SetName(pObj0->TakeObjNameSingul()); + } + } + else + SetName(TakeObjNameSingul()); + } + std::unordered_set aNameSet; MakeNameUnique(aNameSet); } @@ -3086,17 +3105,20 @@ void SdrObject::MakeNameUnique(std::unordered_set& rNameSet) } } - OUString sName(GetName()); - OUString sRootName(GetName()); - sal_Int32 index = sName.lastIndexOf("_"); - if ( index > 0) - sRootName = sRootName.copy(0, index); + OUString sName(GetName().trim()); + OUString sRootName(sName); - sal_uInt32 n = 0; - while (rNameSet.find(sName) != rNameSet.end()) + if (!sName.isEmpty() && rtl::isAsciiDigit(sName[sName.getLength() - 1])) { - sName = sRootName + "_" + OUString::number(n++); + sal_Int32 nPos(sName.getLength() - 1); + while (nPos > 0 && rtl::isAsciiDigit(sName[--nPos])); + sRootName = sName.copy(0, nPos + 1).trim(); } + else + sName += " 1"; + + for (sal_uInt32 n = 1; rNameSet.find(sName) != rNameSet.end(); n++) + sName = sRootName + " " + OUString::number(n); rNameSet.insert(sName); SetName(sName); -- cgit