refactored IDE library import dialog

pull/95/head
jmoenig 2020-05-01 13:42:13 +02:00
rodzic c60febd50e
commit d33455a08c
1 zmienionych plików z 20 dodań i 27 usunięć

Wyświetl plik

@ -7541,15 +7541,13 @@ LibraryImportDialogMorph.prototype.initializeLibraryDescription = function () {
}; };
LibraryImportDialogMorph.prototype.installLibrariesList = function () { LibraryImportDialogMorph.prototype.installLibrariesList = function () {
var myself = this;
if (this.listField) {this.listField.destroy(); } if (this.listField) {this.listField.destroy(); }
this.listField = new ListMorph( this.listField = new ListMorph(
this.librariesData, this.librariesData,
function (element) {return element.name; }, element => element.name,
null, null,
function () {myself.importLibrary(); } () => this.importLibrary()
); );
this.fixListFieldItemColors(); this.fixListFieldItemColors();
@ -7562,28 +7560,24 @@ LibraryImportDialogMorph.prototype.installLibrariesList = function () {
this.listField.render = InputFieldMorph.prototype.render; this.listField.render = InputFieldMorph.prototype.render;
this.listField.drawRectBorder = InputFieldMorph.prototype.drawRectBorder; this.listField.drawRectBorder = InputFieldMorph.prototype.drawRectBorder;
this.listField.action = function (item) { this.listField.action = (item) => {
if (isNil(item)) {return; } if (isNil(item)) {return; }
myself.notesText.text = localize(item.description || ''); this.notesText.text = localize(item.description || '');
myself.notesText.rerender(); this.notesText.rerender();
myself.notesField.contents.adjustBounds(); this.notesField.contents.adjustBounds();
if (myself.hasCached(item.fileName)) { if (this.hasCached(item.fileName)) {
myself.displayBlocks(item.fileName); this.displayBlocks(item.fileName);
} else { } else {
myself.showMessage( this.showMessage(localize('Loading') + '\n' + localize(item.name));
localize('Loading') + '\n' + localize(item.name) this.ide.getURL(
); this.ide.resourceURL('libraries', item.fileName),
myself.ide.getURL( libraryXML => this.cacheLibrary(
myself.ide.resourceURL('libraries', item.fileName), item.fileName,
function(libraryXML) { this.ide.serializer.loadBlocks(libraryXML)
myself.cacheLibrary( ),
item.fileName, this.displayBlocks(item.fileName)
myself.ide.serializer.loadBlocks(libraryXML)
);
myself.displayBlocks(item.fileName);
}
); );
} }
}; };
@ -7689,7 +7683,7 @@ LibraryImportDialogMorph.prototype.importLibrary = function () {
if (this.hasCached(selectedLibrary)) { if (this.hasCached(selectedLibrary)) {
blocks = this.cachedLibrary(selectedLibrary); blocks = this.cachedLibrary(selectedLibrary);
blocks.forEach(function (def) { blocks.forEach(def => {
def.receiver = ide.stage; def.receiver = ide.stage;
ide.stage.globalBlocks.push(def); ide.stage.globalBlocks.push(def);
ide.stage.replaceDoubleDefinitionsFor(def); ide.stage.replaceDoubleDefinitionsFor(def);
@ -7710,7 +7704,6 @@ LibraryImportDialogMorph.prototype.importLibrary = function () {
LibraryImportDialogMorph.prototype.displayBlocks = function (libraryKey) { LibraryImportDialogMorph.prototype.displayBlocks = function (libraryKey) {
var x, y, blockImage, previousCategory, blockContainer, var x, y, blockImage, previousCategory, blockContainer,
myself = this,
padding = 4, padding = 4,
blocksList = this.cachedLibrary(libraryKey); blocksList = this.cachedLibrary(libraryKey);
@ -7720,8 +7713,8 @@ LibraryImportDialogMorph.prototype.displayBlocks = function (libraryKey) {
x = this.palette.left() + padding; x = this.palette.left() + padding;
y = this.palette.top(); y = this.palette.top();
SpriteMorph.prototype.categories.forEach(function (category) { SpriteMorph.prototype.categories.forEach(category => {
blocksList.forEach(function (definition) { blocksList.forEach(definition => {
if (definition.category !== category) {return; } if (definition.category !== category) {return; }
if (category !== previousCategory) { if (category !== previousCategory) {
y += padding; y += padding;
@ -7736,7 +7729,7 @@ LibraryImportDialogMorph.prototype.displayBlocks = function (libraryKey) {
); );
blockContainer.cachedImage = blockImage; blockContainer.cachedImage = blockImage;
blockContainer.setPosition(new Point(x, y)); blockContainer.setPosition(new Point(x, y));
myself.palette.addContents(blockContainer); this.palette.addContents(blockContainer);
y += blockContainer.fullBounds().height() + padding; y += blockContainer.fullBounds().height() + padding;
}); });