new BlockVisibilityDialogMorph for bulk-selecting blocks to hide / show in the palette

snap7
jmoenig 2021-10-07 14:27:29 +02:00
rodzic 4e80d7cb0c
commit 905cd6baa9
4 zmienionych plików z 173 dodań i 10 usunięć

Wyświetl plik

@ -37,6 +37,9 @@
* German
* Chinese, thanks, Simon!
### 2021-10-07
* objects, byob: new BlockVisibilityDialogMorph for bulk-selecting blocks to hide / show in the palette
### 2021-10-06
* threads: programmatically hide individual variables in palette
* extensions: new extension primitives for hiding and showing arbitrary blocks in the palette

Wyświetl plik

@ -18,12 +18,12 @@
<script src="src/widgets.js?version=2021-07-21"></script>
<script src="src/blocks.js?version=2021-10-04"></script>
<script src="src/threads.js?version=2021-10-06"></script>
<script src="src/objects.js?version=2021-10-06"></script>
<script src="src/objects.js?version=2021-10-07"></script>
<script src="src/scenes.js?version=2021-07-21"></script>
<script src="src/gui.js?version=2021-09-30"></script>
<script src="src/paint.js?version=2021-07-05"></script>
<script src="src/lists.js?version=2021-07-19"></script>
<script src="src/byob.js?version=2021-08-03"></script>
<script src="src/byob.js?version=2021-10-07"></script>
<script src="src/tables.js?version=2021-05-07"></script>
<script src="src/sketch.js?version=2021-07-05"></script>
<script src="src/video.js?version=2019-06-27"></script>

Wyświetl plik

@ -108,7 +108,7 @@ WatcherMorph, XML_Serializer, SnapTranslator, SnapExtensions*/
// Global stuff ////////////////////////////////////////////////////////
modules.byob = '2021-August-03';
modules.byob = '2021-October-07';
// Declarations
@ -4450,3 +4450,150 @@ BlockRemovalDialogMorph.prototype.removeBlocks = function () {
BlockRemovalDialogMorph.prototype.fixLayout
= BlockEditorMorph.prototype.fixLayout;
// BlockVisibilityDialogMorph //////////////////////////////////////////////////
// BlockVisibilityDialogMorph inherits from DialogBoxMorph
// and pseudo-inherits from BlockExportDialogMorph:
BlockVisibilityDialogMorph.prototype = new DialogBoxMorph();
BlockVisibilityDialogMorph.prototype.constructor = BlockVisibilityDialogMorph;
BlockVisibilityDialogMorph.uber = DialogBoxMorph.prototype;
// BlockVisibilityDialogMorph constants:
BlockVisibilityDialogMorph.prototype.key = 'blockVisibility';
// BlockVisibilityDialogMorph instance creation:
function BlockVisibilityDialogMorph(target) {
this.init(target);
}
BlockVisibilityDialogMorph.prototype.init = function (target) {
// additional properties:
this.blocks = target.allPaletteBlocks();
this.selection = this.blocks.filter(each => target.isHidingBlock(each));
this.handle = null;
// initialize inherited properties:
BlockVisibilityDialogMorph.uber.init.call(
this,
target,
() => this.hideBlocks(),
null // environment
);
// override inherited properites:
this.labelString = localize('Hide blocks in palette')
+ (name ? ': ' : '')
+ name || '';
this.createLabel();
// build contents
this.buildContents();
};
BlockVisibilityDialogMorph.prototype.buildContents = function () {
var palette, x, y, checkBox, lastCat,
padding = 4;
// create plaette
palette = new ScrollFrameMorph(
null,
null,
SpriteMorph.prototype.sliderColor
);
palette.color = SpriteMorph.prototype.paletteColor;
palette.padding = padding;
palette.isDraggable = false;
palette.acceptsDrops = false;
palette.contents.acceptsDrops = false;
// populate palette
x = palette.left() + padding;
y = palette.top() + padding;
this.blocks.forEach(block => {
if (lastCat && (block.category !== lastCat)) {
y += padding;
}
lastCat = block.category;
checkBox = new ToggleMorph(
'checkbox',
this,
() => {
var idx = this.selection.indexOf(block);
if (idx > -1) {
this.selection.splice(idx, 1);
} else {
this.selection.push(block);
}
},
null,
() => contains(this.selection, block),
null,
null,
block.fullImage()
);
checkBox.setPosition(new Point(
x,
y + (checkBox.top() - checkBox.toggleElement.top())
));
palette.addContents(checkBox);
y += checkBox.fullBounds().height() + padding;
});
palette.scrollX(padding);
palette.scrollY(padding);
this.addBody(palette);
this.addButton('ok', 'OK');
this.addButton('cancel', 'Cancel');
this.setExtent(new Point(220, 300));
this.fixLayout();
};
BlockVisibilityDialogMorph.prototype.popUp
= BlockExportDialogMorph.prototype.popUp;
// BlockVisibilityDialogMorph menu
BlockVisibilityDialogMorph.prototype.userMenu
= BlockExportDialogMorph.prototype.userMenu;
BlockVisibilityDialogMorph.prototype.selectAll = function () {
this.selection = this.blocks.slice(0);
this.body.contents.children.forEach(checkBox => {
checkBox.refresh();
});
};
BlockVisibilityDialogMorph.prototype.selectNone = function () {
this.selection = [];
this.body.contents.children.forEach(checkBox => {
checkBox.refresh();
});
};
// BlockVisibilityDialogMorph ops
BlockVisibilityDialogMorph.prototype.hideBlocks = function () {
var ide = this.target.parentThatIsA(IDE_Morph);
this.blocks.forEach(block => this.target.changeBlockVisibility(
block,
contains(this.selection, block))
);
if (this.selection.length === 0) {
StageMorph.prototype.hiddenPrimitives = [];
ide.flushBlocksCache();
ide.refreshPalette();
}
};
// BlockVisibilityDialogMorph layout
BlockVisibilityDialogMorph.prototype.fixLayout
= BlockEditorMorph.prototype.fixLayout;

Wyświetl plik

@ -82,11 +82,12 @@ VariableDialogMorph, HTMLCanvasElement, Context, List, RingMorph, HandleMorph,
SpeechBubbleMorph, InputSlotMorph, isNil, FileReader, TableDialogMorph, String,
BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, BooleanSlotMorph,
localize, TableMorph, TableFrameMorph, normalizeCanvas, VectorPaintEditorMorph,
AlignmentMorph, Process, WorldMap, copyCanvas, useBlurredShadows*/
AlignmentMorph, Process, WorldMap, copyCanvas, useBlurredShadows,
BlockVisibilityDialogMorph*/
/*jshint esversion: 6*/
modules.objects = '2021-October-06';
modules.objects = '2021-October-07';
var SpriteMorph;
var StageMorph;
@ -2304,14 +2305,17 @@ SpriteMorph.prototype.variableBlock = function (varName, isLocalTemplate) {
// SpriteMorph block templates
SpriteMorph.prototype.blockTemplates = function (category = 'motion') {
SpriteMorph.prototype.blockTemplates = function (
category = 'motion',
all = false // include hidden blocks
) {
var blocks = [], myself = this, varNames,
inheritedVars = this.inheritedVariableNames(),
wrld = this.world(),
devMode = wrld && wrld.isDevMode;
function block(selector, isGhosted) {
if (StageMorph.prototype.hiddenPrimitives[selector]) {
if (StageMorph.prototype.hiddenPrimitives[selector] && !all) {
return null;
}
var newBlock = SpriteMorph.prototype.blockForSelector(selector, true);
@ -3141,6 +3145,12 @@ SpriteMorph.prototype.freshPalette = function (category) {
}
);
}
menu.addItem( // +++
'hide blocks...',
() => new BlockVisibilityDialogMorph(myself).popUp(myself.world())
);
menu.addLine();
menu.addItem(
'make a category...',
@ -3236,7 +3246,7 @@ SpriteMorph.prototype.allPaletteBlocks = function () {
// private - only to be used for showing & hiding blocks im the palette
var blocks = SpriteMorph.prototype.allCategories().reduce(
(blocks, category) => {
let primitives = this.blockTemplates(category),
let primitives = this.blockTemplates(category, true),
customs = this.customBlockTemplatesForCategory(category, true);
return blocks.concat(
primitives,
@ -8695,11 +8705,14 @@ StageMorph.prototype.pauseGenericHatBlocks = function () {
// StageMorph block templates
StageMorph.prototype.blockTemplates = function (category = 'motion') {
StageMorph.prototype.blockTemplates = function (
category = 'motion',
all = false // include hidden blocks
) {
var blocks = [], myself = this, varNames, txt;
function block(selector) {
if (myself.hiddenPrimitives[selector]) {
if (myself.hiddenPrimitives[selector] && !all) {
return null;
}
var newBlock = SpriteMorph.prototype.blockForSelector(selector, true);