| 245 | } |
| 246 | |
| 247 | void addChild (SharedObject* child, int index, UndoManager* undoManager) |
| 248 | { |
| 249 | if (child != nullptr && child->parent != this) |
| 250 | { |
| 251 | if (child != this && ! isAChildOf (child)) |
| 252 | { |
| 253 | // You should always make sure that a child is removed from its previous parent before |
| 254 | // adding it somewhere else - otherwise, it's ambiguous as to whether a different |
| 255 | // undomanager should be used when removing it from its current parent.. |
| 256 | jassert (child->parent == nullptr); |
| 257 | |
| 258 | if (child->parent != nullptr) |
| 259 | { |
| 260 | jassert (child->parent->children.indexOf (child) >= 0); |
| 261 | child->parent->removeChild (child->parent->children.indexOf (child), undoManager); |
| 262 | } |
| 263 | |
| 264 | if (undoManager == nullptr) |
| 265 | { |
| 266 | children.insert (index, child); |
| 267 | child->parent = this; |
| 268 | sendChildAddedMessage (ValueTree (*child)); |
| 269 | child->sendParentChangeMessage(); |
| 270 | } |
| 271 | else |
| 272 | { |
| 273 | if (! isPositiveAndBelow (index, children.size())) |
| 274 | index = children.size(); |
| 275 | |
| 276 | undoManager->perform (new AddOrRemoveChildAction (*this, index, child)); |
| 277 | } |
| 278 | } |
| 279 | else |
| 280 | { |
| 281 | // You're attempting to create a recursive loop! A node |
| 282 | // can't be a child of one of its own children! |
| 283 | jassertfalse; |
| 284 | } |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | void removeChild (int childIndex, UndoManager* undoManager) |
| 289 | { |
no test coverage detected