svx/source/svdraw/svdedtv.cxx | 12 +++++++++++ svx/source/svdraw/svdobj.cxx | 38 +++++++++++++++++++++++++++++-------- sw/source/core/frmedt/feshview.cxx | 2 - 3 files changed, 43 insertions(+), 9 deletions(-)
New commits: commit 50b731c84cb17d7f05a690d90588e90ee267d1c2 Author: Jim Raykowski <rayk...@gmail.com> AuthorDate: Thu Nov 12 13:18:16 2020 -0900 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Thu Mar 25 20:28:30 2021 +0100 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 <noel.gran...@collabora.co.uk> 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 <svx/scene3d.hxx> #include <svx/xfillit0.hxx> +#include <com/sun/star/lang/XServiceInfo.hpp> 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<lang::XServiceInfo> 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 <libxml/xmlwriter.h> #include <memory> +#include <svx/scene3d.hxx> +#include <rtl/character.hxx> + 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<const E3dScene*>(this)) + { + SdrObjList* pObjList = pE3dObj->GetSubList(); + if (pObjList) + { + SdrObject* pObj0 = pObjList->GetObj(0); + if (pObj0) + SetName(pObj0->TakeObjNameSingul()); + } + } + else + SetName(TakeObjNameSingul()); + } + std::unordered_set<OUString> aNameSet; MakeNameUnique(aNameSet); } @@ -3086,17 +3105,20 @@ void SdrObject::MakeNameUnique(std::unordered_set<OUString>& 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); diff --git a/sw/source/core/frmedt/feshview.cxx b/sw/source/core/frmedt/feshview.cxx index af1a729eb446..749a58439f0d 100644 --- a/sw/source/core/frmedt/feshview.cxx +++ b/sw/source/core/frmedt/feshview.cxx @@ -2038,7 +2038,7 @@ bool SwFEShell::ImpEndCreate() { bool bRestore = GetDoc()->GetIDocumentUndoRedo().DoesDrawUndo(); GetDoc()->GetIDocumentUndoRedo().DoDrawUndo(false); - rSdrObj.SetName(GetUniqueShapeName()); + rSdrObj.MakeNameUnique(); GetDoc()->GetIDocumentUndoRedo().DoDrawUndo(bRestore); } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits