From 17d7dd67206314d7d683500472d40cebcc55fa12 Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Tue, 29 Jun 2021 22:23:06 -0700 Subject: [PATCH] tidy up some code, undo some improper git merging --- src/blocks.js | 23 +++++++++++---------- src/gui.js | 54 ++++++++++++++++++-------------------------------- src/objects.js | 53 +++++++++++++++++++++++-------------------------- 3 files changed, 57 insertions(+), 73 deletions(-) diff --git a/src/blocks.js b/src/blocks.js index 657df834..3450de16 100644 --- a/src/blocks.js +++ b/src/blocks.js @@ -7200,7 +7200,7 @@ ScriptsMorph.prototype.userMenu = function () { } else { obj.customBlocks.push(definition); } - ide.flushBlocksCache(); + ide.flushPaletteCache(); ide.refreshPalette(); new BlockEditorMorph(definition, obj).popUp(); } @@ -9776,16 +9776,19 @@ InputSlotMorph.prototype.audioMenu = function (searching) { }; InputSlotMorph.prototype.scenesMenu = function (searching) { - var scenes = this.parentThatIsA(IDE_Morph).scenes, - dict = {}; - - if (!searching && scenes.length() > 1) { - scenes.itemsArray().forEach(scn => { - if (scn.name) { - dict[scn.name] = scn.name; - } - }); + var dict = {}, + scenes; + if (!searching) { + scenes = this.parentThatIsA(IDE_Morph).scenes; + if (scenes.length() > 1) { + scenes.itemsArray().forEach(scn => { + if (scn.name) { + dict[scn.name] = scn.name; + } + }); + } } + dict['~'] = null; dict.next = ['next']; dict.previous = ['previous']; diff --git a/src/gui.js b/src/gui.js index 12a706cf..da068456 100644 --- a/src/gui.js +++ b/src/gui.js @@ -2049,29 +2049,6 @@ IDE_Morph.prototype.createCorral = function (keepSceneAlbum) { }; }; -IDE_Morph.prototype.unsetUnifiedPalete = function () { - this.scene.unifiedPalette = false; - this.currentCategory = 'motion'; - this.createCategories(); - this.categories.fixLayout(); - this.fixLayout(); - this.flushBlocksCache(); - this.currentSprite.palette(this.currentCategory); - this.refreshPalette(true); -} - -IDE_Morph.prototype.setUnifiedPalete = function () { - this.scene.unifiedPalette = true; - this.currentCategory = 'unified'; - this.createCategories(); - this.categories.fixLayout(); - this.fixLayout(); - this.flushBlocksCache(); - this.flushPaletteCache(); - this.currentSprite.palette(this.currentCategory); - this.refreshPalette(true); -} - // IDE_Morph layout IDE_Morph.prototype.fixLayout = function (situation) { @@ -4050,13 +4027,7 @@ IDE_Morph.prototype.settingsMenu = function () { ); addPreference( 'Unified Palette', - () => { - if (this.scene.unifiedPalette) { - this.unsetUnifiedPalete(); - } else { - this.setUnifiedPalete(); - } - }, + () => this.toggleUnifiedPalette(), this.scene.unifiedPalette, 'uncheck to show only the selected category\'s blocks', 'check to show all blocks in a single palette', @@ -5602,9 +5573,9 @@ IDE_Morph.prototype.switchToScene = function (scene, refreshAlbum) { this.world().keyboardFocus = this.stage; if (this.currentCategory != 'unified' && scene.unifiedPalette) { - this.setUnifiedPalete(); + this.toggleUnifiedPalette(); } else if (this.currentCategory == 'unified' && !scene.unifiedPalette) { - this.unsetUnifiedPalete(); + this.toggleUnifiedPalette(); } this.fixLayout(); @@ -5766,14 +5737,11 @@ IDE_Morph.prototype.switchToDevMode = function () { IDE_Morph.prototype.flushBlocksCache = function (category) { // if no category is specified, the whole cache gets flushed - // the 'unified' category is always flushed. if (category) { this.stage.primitivesCache[category] = null; - this.stage.primitivesCache.unified = null; this.stage.children.forEach(m => { if (m instanceof SpriteMorph) { m.primitivesCache[category] = null; - m.primitivesCache.unified = null; } }); } else { @@ -6049,6 +6017,22 @@ IDE_Morph.prototype.toggleStageSize = function (isSmall, forcedRatio) { } }; +IDE_Morph.prototype.toggleUnifiedPalette = function () { + this.scene.unifiedPalette = !this.scene.unifiedPalette; + if (this.scene.unifiedPalette) { + this.currentCategory = 'unified'; + } else { + this.currentCategory = 'motion'; + } + + this.createCategories(); + this.categories.fixLayout(); + this.fixLayout(); + this.flushBlocksCache(); + this.currentSprite.palette(this.currentCategory); + this.refreshPalette(true); +} + IDE_Morph.prototype.setPaletteWidth = function (newWidth) { var msecs = this.isAnimating ? 100 : 0, world = this.world(); diff --git a/src/objects.js b/src/objects.js index 9a257b7d..f0201df3 100644 --- a/src/objects.js +++ b/src/objects.js @@ -2637,7 +2637,7 @@ SpriteMorph.prototype.blockTemplates = function (category) { // for debugging: /////////////// if (this.world().isDevMode) { blocks.push('-'); - blocks.push(devModeText()); + blocks.push(this.devModeText()); blocks.push('-'); blocks.push(block('reportTypeOf')); blocks.push(block('reportTextFunction')); @@ -2645,7 +2645,7 @@ SpriteMorph.prototype.blockTemplates = function (category) { } else if (category === 'variables') { - blocks.push(this.makeAVariableButton()); + blocks.push(this.makeVariableButton()); if (this.deletableVariableNames().length > 0) { blocks.push(this.deleteVariableButton()); } @@ -2713,7 +2713,7 @@ SpriteMorph.prototype.blockTemplates = function (category) { // for debugging: /////////////// if (this.world().isDevMode) { blocks.push('-'); - blocks.push(devModeText()); + blocks.push(this.devModeText()); blocks.push('-'); blocks.push(block('doShowTable')); blocks.push('-'); @@ -2735,7 +2735,7 @@ SpriteMorph.prototype.blockTemplates = function (category) { }; // Utitlies displayed in the palette -SpriteMorph.prototype.makeAVariableButton = function() { +SpriteMorph.prototype.makeVariableButton = function () { let button, myself = this; function addVar(pair) { @@ -2769,7 +2769,7 @@ SpriteMorph.prototype.makeAVariableButton = function() { }, 'Make a variable' ); - button.userMenu = this.newHelpMenu; + button.userMenu = this.helpMenu; button.selector = 'addVariable'; button.showHelp = BlockMorph.prototype.showHelp; return button; @@ -2802,7 +2802,7 @@ SpriteMorph.prototype.deleteVariableButton = function () { }, 'Delete a variable' ); - button.userMenu = this.newHelpMenu; + button.userMenu = this.helpMenu; button.selector = 'deleteVariable'; button.showHelp = BlockMorph.prototype.showHelp; return button; @@ -2815,7 +2815,7 @@ SpriteMorph.prototype.devModeText = function () { return txt; } -SpriteMorph.prototype.newHelpMenu = function () { +SpriteMorph.prototype.helpMenu = function () { // return a 1 item context menu for anything that implements a 'showHelp' method. var menu = new MenuMorph(this); menu.addItem('help...', 'showHelp'); @@ -2865,7 +2865,7 @@ SpriteMorph.prototype.makeBlockButton = function (category) { 'Make a block' ); - button.userMenu = this.newHelpMenu; + button.userMenu = this.helpMenu; button.selector = 'addCustomBlock'; button.showHelp = BlockMorph.prototype.showHelp; return button; @@ -2887,7 +2887,7 @@ SpriteMorph.prototype.makeBlock = function () { } else { this.customBlocks.push(definition); } - ide.flushBlocksCache(); + ide.flushPaletteCache(); ide.refreshPalette(); ide.recordUnsavedChanges(); new BlockEditorMorph(definition, this).popUp(); @@ -8780,7 +8780,7 @@ StageMorph.prototype.blockTemplates = function (category) { } if (category === 'variables') { - blocks.push(this.makeAVariableButton()); + blocks.push(this.makeVariableButton()); if (this.variables.allNames().length > 0) { blocks.push(this.deleteVariableButton()); } @@ -8856,24 +8856,12 @@ StageMorph.prototype.blockTemplates = function (category) { blocks.push(block('doMapListCode')); blocks.push('-'); blocks.push(block('reportMappedCode')); - blocks.push('='); } } return blocks; }; -// StageMorph Palette Utilities -StageMorph.prototype.newHelpMenu = SpriteMorph.prototype.newHelpMenu; -StageMorph.prototype.makeBlockButton = SpriteMorph.prototype.makeBlockButton; -StageMorph.prototype.makeAVariableButton = SpriteMorph.prototype.makeAVariableButton; -StageMorph.prototype.devModeText = SpriteMorph.prototype.devModeText; -StageMorph.prototype.deleteVariableButton = SpriteMorph.prototype.deleteVariableButton; -StageMorph.prototype.customBlockTemplatesForCategory = - SpriteMorph.prototype.customBlockTemplatesForCategory; -StageMorph.prototype.getPrimitiveTemplates = - SpriteMorph.prototype.getPrimitiveTemplates; - // StageMorph primitives StageMorph.prototype.clear = function () { @@ -9151,18 +9139,27 @@ StageMorph.prototype.categories = SpriteMorph.prototype.categories; StageMorph.prototype.blockColor = SpriteMorph.prototype.blockColor; StageMorph.prototype.paletteColor = SpriteMorph.prototype.paletteColor; StageMorph.prototype.setName = SpriteMorph.prototype.setName; -StageMorph.prototype.makeBlockButton = SpriteMorph.prototype.makeBlockButton; -StageMorph.prototype.makeBlock = SpriteMorph.prototype.makeBlock; -StageMorph.prototype.palette = SpriteMorph.prototype.palette; -StageMorph.prototype.freshPalette = SpriteMorph.prototype.freshPalette; -StageMorph.prototype.blocksMatching = SpriteMorph.prototype.blocksMatching; -StageMorph.prototype.searchBlocks = SpriteMorph.prototype.searchBlocks; StageMorph.prototype.reporterize = SpriteMorph.prototype.reporterize; StageMorph.prototype.variableBlock = SpriteMorph.prototype.variableBlock; StageMorph.prototype.showingWatcher = SpriteMorph.prototype.showingWatcher; StageMorph.prototype.addVariable = SpriteMorph.prototype.addVariable; StageMorph.prototype.deleteVariable = SpriteMorph.prototype.deleteVariable; +// StageMorph Palette Utilities + +StageMorph.prototype.makeBlock = SpriteMorph.prototype.makeBlock; +StageMorph.prototype.helpMenu = SpriteMorph.prototype.helpMenu; +StageMorph.prototype.makeBlockButton = SpriteMorph.prototype.makeBlockButton; +StageMorph.prototype.makeVariableButton = SpriteMorph.prototype.makeVariableButton; +StageMorph.prototype.devModeText = SpriteMorph.prototype.devModeText; +StageMorph.prototype.deleteVariableButton = SpriteMorph.prototype.deleteVariableButton; +StageMorph.prototype.customBlockTemplatesForCategory = SpriteMorph.prototype.customBlockTemplatesForCategory; +StageMorph.prototype.getPrimitiveTemplates = SpriteMorph.prototype.getPrimitiveTemplates; +StageMorph.prototype.palette = SpriteMorph.prototype.palette; +StageMorph.prototype.freshPalette = SpriteMorph.prototype.freshPalette; +StageMorph.prototype.blocksMatching = SpriteMorph.prototype.blocksMatching; +StageMorph.prototype.searchBlocks = SpriteMorph.prototype.searchBlocks; + // StageMorph neighbor detection StageMorph.prototype.neighbors = SpriteMorph.prototype.neighbors;