diff --git a/src/item/Item.js b/src/item/Item.js index f9099fd7..3f17e2c9 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -665,7 +665,7 @@ var Item = this.Item = Base.extend({ */ insertChild: function(index, item) { if (this._children) { - item._removeFromParent(); + item._removeFromParent(false, true); Base.splice(this._children, [item], index, 0); item._parent = this; item._setProject(this._project); @@ -773,11 +773,16 @@ var Item = this.Item = Base.extend({ /** * Removes the item from its parent's children list. */ - _removeFromParent: function() { + _removeFromParent: function(deselect, notify) { if (this._parent) { + if (deselect) + this.setSelected(false); if (this._name) this._removeFromNamed(); Base.splice(this._parent._children, null, this._index, 1); + // Notify parent of changed hierarchy + if (notify) + this._parent._changed(ChangeFlags.HIERARCHY); this._parent = null; return true; } @@ -791,9 +796,7 @@ var Item = this.Item = Base.extend({ * @return {Boolean} {@true the item was removed} */ remove: function() { - if (this.isSelected()) - this.setSelected(false); - return this._removeFromParent(); + return this._removeFromParent(true, true); }, /** @@ -823,7 +826,9 @@ var Item = this.Item = Base.extend({ to = Base.pick(to, this._children.length); var removed = this._children.splice(from, to - from); for (var i = removed.length - 1; i >= 0; i--) - removed[i].remove(); + removed[i]._removeFromParent(true, false); + if (removed.length > 0) + this._changed(ChangeFlags.HIERARCHY); return removed; }, diff --git a/src/item/Layer.js b/src/item/Layer.js index 73d3c23f..6bb2086d 100644 --- a/src/item/Layer.js +++ b/src/item/Layer.js @@ -53,9 +53,17 @@ var Layer = this.Layer = Group.extend({ * Removes the layer from its project's layers list * or its parent's children list. */ - _removeFromParent: function() { - return this._parent ? this.base() - : !!Base.splice(this._project.layers, null, this._index, 1).length; + _removeFromParent: function(deselect, notify) { + if (this._parent) + return this.base(deselect, notify); + if (this._index != null) { + if (deselect) + this.setSelected(false); + Base.splice(this._project.layers, null, this._index, 1); + // TODO: If notify == true, notify project of hierarchy change + return true; + } + return false; }, getNextSibling: function() { @@ -83,9 +91,10 @@ var Layer = this.Layer = Group.extend({ }, new function () { function move(above) { return function(item) { - // if the item is a layer and contained within Project#layers + // If the item is a layer and contained within Project#layers, use + // our own version of move(). if (item instanceof Layer && !item._parent - && this._removeFromParent()) { + && this._removeFromParent(false, true)) { Base.splice(item._project.layers, [this], item._index + (above ? 1 : -1), 0); this._setProject(item._project);