kopia lustrzana https://github.com/backface/turtlestitch
Merge pull request #1867 from bromagosa/download-stacks
Download script (as a hidden menu item)upd4.1
commit
c580ac0efc
20
blocks.js
20
blocks.js
|
@ -2589,6 +2589,26 @@ BlockMorph.prototype.userMenu = function () {
|
||||||
},
|
},
|
||||||
'open a new window\nwith a picture of this script'
|
'open a new window\nwith a picture of this script'
|
||||||
);
|
);
|
||||||
|
if (shiftClicked) {
|
||||||
|
menu.addItem(
|
||||||
|
'download script',
|
||||||
|
function () {
|
||||||
|
var ide = myself.parentThatIsA(IDE_Morph),
|
||||||
|
blockEditor = myself.parentThatIsA(BlockEditorMorph);
|
||||||
|
if (!ide && blockEditor) {
|
||||||
|
ide = blockEditor.target.parentThatIsA(IDE_Morph);
|
||||||
|
}
|
||||||
|
if (ide) {
|
||||||
|
ide.saveXMLAs(
|
||||||
|
ide.serializer.serialize(myself),
|
||||||
|
myself.selector + ' script',
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'download this script\nas an XML file',
|
||||||
|
new Color(100, 0, 0)
|
||||||
|
);
|
||||||
|
}
|
||||||
if (proc) {
|
if (proc) {
|
||||||
if (vNames.length) {
|
if (vNames.length) {
|
||||||
menu.addLine();
|
menu.addLine();
|
||||||
|
|
57
gui.js
57
gui.js
|
@ -1904,6 +1904,9 @@ IDE_Morph.prototype.droppedText = function (aString, name) {
|
||||||
if (aString.indexOf('<media') === 0) {
|
if (aString.indexOf('<media') === 0) {
|
||||||
return this.openMediaString(aString);
|
return this.openMediaString(aString);
|
||||||
}
|
}
|
||||||
|
if (aString.indexOf('<script') === 0) {
|
||||||
|
return this.openScriptString(aString);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
IDE_Morph.prototype.droppedBinary = function (anArrayBuffer, name) {
|
IDE_Morph.prototype.droppedBinary = function (anArrayBuffer, name) {
|
||||||
|
@ -4278,6 +4281,60 @@ IDE_Morph.prototype.openMediaString = function (str) {
|
||||||
this.showMessage('Imported Media Module.', 2);
|
this.showMessage('Imported Media Module.', 2);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
IDE_Morph.prototype.openScriptString = function (str) {
|
||||||
|
var msg,
|
||||||
|
myself = this;
|
||||||
|
this.nextSteps([
|
||||||
|
function () {
|
||||||
|
msg = myself.showMessage('Opening script...');
|
||||||
|
},
|
||||||
|
function () {nop(); }, // yield (bug in Chrome)
|
||||||
|
function () {
|
||||||
|
myself.rawOpenScriptString(str);
|
||||||
|
},
|
||||||
|
function () {
|
||||||
|
msg.destroy();
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
};
|
||||||
|
|
||||||
|
IDE_Morph.prototype.rawOpenScriptString = function (str) {
|
||||||
|
var xml,
|
||||||
|
script,
|
||||||
|
scripts = this.currentSprite.scripts,
|
||||||
|
world = this.world(),
|
||||||
|
dropPosition = world.hand.position(),
|
||||||
|
myself = this;
|
||||||
|
|
||||||
|
if (Process.prototype.isCatchingErrors) {
|
||||||
|
try {
|
||||||
|
xml = this.serializer.parse(str, this.currentSprite);
|
||||||
|
script = this.serializer.loadScript(xml, this.currentSprite);
|
||||||
|
} catch (err) {
|
||||||
|
this.showMessage('Load failed: ' + err);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
xml = this.serializer.loadScript(str, this.currentSprite);
|
||||||
|
script = this.serializer.loadScript(xml, this.currentSprite);
|
||||||
|
}
|
||||||
|
|
||||||
|
scripts.add(script);
|
||||||
|
|
||||||
|
if (world.topMorphAt(dropPosition) !== scripts) {
|
||||||
|
dropPosition = new Point(
|
||||||
|
scripts.left() + scripts.cleanUpMargin,
|
||||||
|
scripts.top() + scripts.cleanUpMargin);
|
||||||
|
}
|
||||||
|
|
||||||
|
script.setCenter(dropPosition);
|
||||||
|
scripts.adjustBounds();
|
||||||
|
|
||||||
|
this.showMessage(
|
||||||
|
'Imported Script.',
|
||||||
|
2
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
IDE_Morph.prototype.openProject = function (name) {
|
IDE_Morph.prototype.openProject = function (name) {
|
||||||
var str;
|
var str;
|
||||||
if (name) {
|
if (name) {
|
||||||
|
|
4
store.js
4
store.js
|
@ -1116,7 +1116,7 @@ SnapSerializer.prototype.loadBlock = function (model, isReporter, object) {
|
||||||
} else if (model.tag === 'custom-block') {
|
} else if (model.tag === 'custom-block') {
|
||||||
isGlobal = model.attributes.scope ? false : true;
|
isGlobal = model.attributes.scope ? false : true;
|
||||||
receiver = isGlobal ? this.project.stage : object;
|
receiver = isGlobal ? this.project.stage : object;
|
||||||
if (isGlobal) {
|
if (isGlobal && receiver) {
|
||||||
info = detect(receiver.globalBlocks, function (block) {
|
info = detect(receiver.globalBlocks, function (block) {
|
||||||
return block.blockSpec() === model.attributes.s;
|
return block.blockSpec() === model.attributes.s;
|
||||||
});
|
});
|
||||||
|
@ -1128,7 +1128,7 @@ SnapSerializer.prototype.loadBlock = function (model, isReporter, object) {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else if (receiver) {
|
||||||
// lookup in inherited methods
|
// lookup in inherited methods
|
||||||
info = detect(receiver.customBlocks, function (block) {
|
info = detect(receiver.customBlocks, function (block) {
|
||||||
return block.blockSpec() === model.attributes.s;
|
return block.blockSpec() === model.attributes.s;
|
||||||
|
|
Ładowanie…
Reference in New Issue