summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorJim Raykowski <raykowj@gmail.com>2020-11-12 13:18:16 -0900
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-03-25 20:28:30 +0100
commit50b731c84cb17d7f05a690d90588e90ee267d1c2 (patch)
tree588cf6a410afb89e0827ed4f6658693693bd1ef4 /svx
parent042dbf83122b14fd1dd32705c8f8b7d65c22f21b (diff)
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.grandin@collabora.co.uk>
Diffstat (limited to 'svx')
-rw-r--r--svx/source/svdraw/svdedtv.cxx12
-rw-r--r--svx/source/svdraw/svdobj.cxx38
2 files changed, 42 insertions, 8 deletions
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);