From 268e78e4fad815aee99af3633155ae7f34322049 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20M=C3=B6nig?= Date: Wed, 20 Apr 2022 14:40:48 +0200 Subject: [PATCH] export block definitions from inside the block editor --- HISTORY.md | 2 ++ snap.html | 4 ++-- src/blocks.js | 20 ++++++++++++++------ src/byob.js | 19 ++++++++++++++----- 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 7697db68..09624d6f 100755 --- a/HISTORY.md +++ b/HISTORY.md @@ -8,6 +8,7 @@ * new "Menus" library * export script (including dependencies) via its context menu * export / import sprite-local custom block definitions from the palette + * export block definitions from inside the block editor * added "combinations" primitive to the palette * new POSITION primitive reporter in the MOTION category * new MOUSE POSITION primitive reporter in the SENSING category @@ -43,6 +44,7 @@ ### 2022-04-20 * threads: terminate all threads waiting to display a question on ASKing a falsy value * threads: clear "answer" on ASK nothing/falsy +* byob, blocks: export block definition from inside the block editor ### 2022-04-19 * threads: ASK nothing or a falsy value terminates the thread currently displaying a question diff --git a/snap.html b/snap.html index d10cdb8b..38ce37b6 100755 --- a/snap.html +++ b/snap.html @@ -16,14 +16,14 @@ - + - + diff --git a/src/blocks.js b/src/blocks.js index 29b6aa43..c168603d 100644 --- a/src/blocks.js +++ b/src/blocks.js @@ -161,7 +161,7 @@ CostumeIconMorph, SoundIconMorph, SVG_Costume*/ // Global stuff //////////////////////////////////////////////////////// -modules.blocks = '2022-April-08'; +modules.blocks = '2022-April-20'; var SyntaxElementMorph; var BlockMorph; @@ -3348,11 +3348,19 @@ BlockMorph.prototype.userMenu = function () { 'save a picture of both\nthis script and its result' ); } - menu.addItem( - 'export script', - () => top.exportScript(), - 'download this script\nas an XML file' - ); + if (top instanceof PrototypeHatBlockMorph) { + menu.addItem( + "export...", + () => top.exportBlockDefinition(), + 'including dependencies' + ); + } else { + menu.addItem( + 'export script', + () => top.exportScript(), + 'download this script\nas an XML file' + ); + } if (proc) { if (vNames.length) { menu.addLine(); diff --git a/src/byob.js b/src/byob.js index 1b370944..1c9ceae8 100644 --- a/src/byob.js +++ b/src/byob.js @@ -111,7 +111,7 @@ ArgLabelMorph*/ // Global stuff //////////////////////////////////////////////////////// -modules.byob = '2022-March-23'; +modules.byob = '2022-April-20'; // Declarations @@ -1218,6 +1218,11 @@ CustomCommandBlockMorph.prototype.userMenu = function () { 'uncheck to\nhide in palette', 'check to\nshow in palette' ); + menu.addItem( + "export...", + () => hat.exportBlockDefinition(), + 'including dependencies' + ); } else { menu = this.constructor.uber.userMenu.call(this); dlg = this.parentThatIsA(DialogBoxMorph); @@ -1312,10 +1317,11 @@ CustomCommandBlockMorph.prototype.userMenu = function () { }; CustomCommandBlockMorph.prototype.exportBlockDefinition = function () { - var ide = this.parentThatIsA(IDE_Morph), - rcvr = this.scriptTarget(), - def = this.isGlobal ? this.definition - : rcvr.getMethod(this.blockSpec); + var rcvr = this.scriptTarget(), + ide = rcvr.parentThatIsA(IDE_Morph), + def = this.isGlobal || this instanceof PrototypeHatBlockMorph ? + this.definition + : rcvr.getMethod(this.blockSpec); new BlockExportDialogMorph( ide.serializer, [def].concat(def.collectDependencies([], [], rcvr)), @@ -2790,6 +2796,9 @@ PrototypeHatBlockMorph.prototype.userMenu = function () { return this.parts()[0].userMenu(); }; +PrototypeHatBlockMorph.prototype.exportBlockDefinition = + CustomCommandBlockMorph.prototype.exportBlockDefinition; + // PrototypeHatBlockMorph zebra coloring PrototypeHatBlockMorph.prototype.fixBlockColor = function (