diff --git a/HISTORY.md b/HISTORY.md index a809a83b..7ffac0a5 100755 --- a/HISTORY.md +++ b/HISTORY.md @@ -20,6 +20,7 @@ * blocks: new "export script" feature (including dependencies) * blocks: tweaked "export scripts" for reporters * German translation update (for "export script" feature) +* blocks: added BlockMorph >> toXMLString() api ### 2022-03-14 * gui, byob: refactored library serialization diff --git a/src/blocks.js b/src/blocks.js index b7a68a82..dea4a9bf 100644 --- a/src/blocks.js +++ b/src/blocks.js @@ -3966,12 +3966,33 @@ BlockMorph.prototype.exportResultPic = function () { BlockMorph.prototype.exportScript = function () { // assumes this is the script's top block + var ide = this.parentThatIsA(IDE_Morph), + blockEditor = this.parentThatIsA(BlockEditorMorph), + xml; + + if (!ide && blockEditor) { + ide = blockEditor.target.parentThatIsA(IDE_Morph); + } + if (!ide) { + return; + } + + xml = this.toXMLString(); + if (xml) { + ide.saveXMLAs( + xml, + this.selector + ' script', + false + ); + } +}; + +BlockMorph.prototype.toXMLString = function () { var ide = this.parentThatIsA(IDE_Morph), blockEditor = this.parentThatIsA(BlockEditorMorph), rcvr = this.scriptTarget(), dependencies = [], - isReporter = this instanceof ReporterBlockMorph, - str; + isReporter = this instanceof ReporterBlockMorph; if (!ide && blockEditor) { ide = blockEditor.target.parentThatIsA(IDE_Morph); @@ -3996,7 +4017,7 @@ BlockMorph.prototype.exportScript = function () { } }); - str = '