renameObjectId method

bool renameObjectId(
  1. String currentId,
  2. String nextId
)

Renames an object's id for layer panels and app-level references.

Implementation

bool renameObjectId(String currentId, String nextId) {
  if (currentId == nextId) return objectById(currentId) != null;
  if (objectById(nextId) != null) return false;
  final object = objectById(currentId);
  if (object == null) return false;
  final renamed = _copyObjectWithMeta(object, id: nextId);
  final changed = update(currentId, renamed);
  if (!changed) return false;
  final selectedIndex = _selectedObjectIds.indexOf(currentId);
  if (selectedIndex >= 0) _selectedObjectIds[selectedIndex] = nextId;
  render();
  _emitSelect();
  return true;
}