refactored block export dialog in byob.js

pull/95/head
jmoenig 2020-04-28 16:33:32 +02:00
rodzic 843c51323a
commit 11f4c3a701
1 zmienionych plików z 18 dodań i 32 usunięć

Wyświetl plik

@ -3622,17 +3622,14 @@ InputSlotDialogMorph.prototype.addSlotsMenu = function () {
}; };
InputSlotDialogMorph.prototype.editSlotOptions = function () { InputSlotDialogMorph.prototype.editSlotOptions = function () {
var myself = this;
new DialogBoxMorph( new DialogBoxMorph(
myself, this,
function (options) { options => this.fragment.options = options.trim(),
myself.fragment.options = options.trim(); this
},
myself
).promptCode( ).promptCode(
'Input Slot Options', 'Input Slot Options',
myself.fragment.options, this.fragment.options,
myself.world(), this.world(),
null, null,
localize('Enter one option per line.\n' + localize('Enter one option per line.\n' +
'Optionally use "=" as key/value delimiter ' + 'Optionally use "=" as key/value delimiter ' +
@ -3739,17 +3736,15 @@ VariableDialogMorph.prototype.init = function (target, action, environment) {
}; };
VariableDialogMorph.prototype.createTypeButtons = function () { VariableDialogMorph.prototype.createTypeButtons = function () {
var myself = this;
this.addTypeButton( this.addTypeButton(
function () {myself.setType('global'); }, () => this.setType('global'),
"for all sprites", "for all sprites",
function () {return myself.isGlobal; } () => this.isGlobal
); );
this.addTypeButton( this.addTypeButton(
function () {myself.setType('local'); }, () => this.setType('local'),
"for this sprite only", "for this sprite only",
function () {return !myself.isGlobal; } () => !this.isGlobal
); );
}; };
@ -3845,8 +3840,6 @@ function BlockExportDialogMorph(serializer, blocks) {
} }
BlockExportDialogMorph.prototype.init = function (serializer, blocks) { BlockExportDialogMorph.prototype.init = function (serializer, blocks) {
var myself = this;
// additional properties: // additional properties:
this.serializer = serializer; this.serializer = serializer;
this.blocks = blocks.slice(0); this.blocks = blocks.slice(0);
@ -3856,7 +3849,7 @@ BlockExportDialogMorph.prototype.init = function (serializer, blocks) {
BlockExportDialogMorph.uber.init.call( BlockExportDialogMorph.uber.init.call(
this, this,
null, // target null, // target
function () {myself.exportBlocks(); }, () => this.exportBlocks(),
null // environment null // environment
); );
@ -3870,7 +3863,6 @@ BlockExportDialogMorph.prototype.init = function (serializer, blocks) {
BlockExportDialogMorph.prototype.buildContents = function () { BlockExportDialogMorph.prototype.buildContents = function () {
var palette, x, y, block, checkBox, lastCat, var palette, x, y, block, checkBox, lastCat,
myself = this,
padding = 4; padding = 4;
// create plaette // create plaette
@ -3888,8 +3880,8 @@ BlockExportDialogMorph.prototype.buildContents = function () {
// populate palette // populate palette
x = palette.left() + padding; x = palette.left() + padding;
y = palette.top() + padding; y = palette.top() + padding;
SpriteMorph.prototype.categories.forEach(function (category) { SpriteMorph.prototype.categories.forEach(category => {
myself.blocks.forEach(function (definition) { this.blocks.forEach(definition => {
if (definition.category === category) { if (definition.category === category) {
if (lastCat && (category !== lastCat)) { if (lastCat && (category !== lastCat)) {
y += padding; y += padding;
@ -3898,22 +3890,17 @@ BlockExportDialogMorph.prototype.buildContents = function () {
block = definition.templateInstance(); block = definition.templateInstance();
checkBox = new ToggleMorph( checkBox = new ToggleMorph(
'checkbox', 'checkbox',
myself, this,
function () { () => {
var idx = myself.blocks.indexOf(definition); var idx = this.blocks.indexOf(definition);
if (idx > -1) { if (idx > -1) {
myself.blocks.splice(idx, 1); this.blocks.splice(idx, 1);
} else { } else {
myself.blocks.push(definition); this.blocks.push(definition);
} }
}, },
null, null,
function () { () => contains(this.blocks, definition),
return contains(
myself.blocks,
definition
);
},
null, null,
null, null,
block.fullImage() block.fullImage()
@ -3937,7 +3924,6 @@ BlockExportDialogMorph.prototype.buildContents = function () {
this.setExtent(new Point(220, 300)); this.setExtent(new Point(220, 300));
this.fixLayout(); this.fixLayout();
}; };
BlockExportDialogMorph.prototype.popUp = function (wrrld) { BlockExportDialogMorph.prototype.popUp = function (wrrld) {