Avoid double-insertion of root layer when importing JSON directly into it.

This commit is contained in:
Jürg Lehni 2014-04-13 16:44:00 +02:00
parent 397c81e060
commit dafdd0ae28

View file

@ -381,8 +381,7 @@ Base.inject(/** @lends Base# */{
* first
*/
deserialize: function(json, create, _data) {
var res = json,
isRoot = !_data;
var res = json;
// A _data side-car to deserialize that can hold any kind of
// 'global' data across a deserialization. It's currently only used
// to hold dictionary definitions.
@ -416,7 +415,7 @@ Base.inject(/** @lends Base# */{
// creation. This is used in #importJSON() to pass
// on insert = false to all items except layers.
if (create) {
res = create(type, args, isRoot);
res = create(type, args);
} else {
res = Base.create(type.prototype);
type.apply(res, args);
@ -442,7 +441,7 @@ Base.inject(/** @lends Base# */{
typeof json === 'string' ? JSON.parse(json) : json,
// Provide our own create function to handle target and
// insertion
function(type, args, isRoot) {
function(type, args) {
// If a target is provided and its of the right type,
// import right into it.
var obj = target && target.constructor === type
@ -453,8 +452,8 @@ Base.inject(/** @lends Base# */{
// we want these to be created on the fly in the active
// project into which we're importing (except for if
// it's a preexisting target layer).
if (!isRoot && args.length === 1 && obj instanceof Item
&& (!(obj instanceof Layer) || isTarget)) {
if (args.length === 1 && obj instanceof Item
&& (isTarget || !(obj instanceof Layer))) {
var arg = args[0];
if (Base.isPlainObject(arg))
arg.insert = false;