refactored block hiding methods

snap7
jmoenig 2021-10-06 18:34:00 +02:00
rodzic 61c9b2aa94
commit 13590e4b91
4 zmienionych plików z 76 dodań i 70 usunięć

Wyświetl plik

@ -42,6 +42,7 @@
* extensions: new extension primitives for hiding and showing arbitrary blocks in the palette
* threads: keep hidden variables out of the palette and drop-down menus
* objects: added utilities to enumerate all palette blocks for hiding & showing
* objects, threads, extensions: refactored block hiding methods
### 2021-10-05
* threads, store: added infrastructure for hiding individual variables in palette

Wyświetl plik

@ -701,7 +701,7 @@ SnapExtensions.primitives.set(
'ide_hide(block)',
function (context, proc) {
proc.assertType(context, ['command', 'reporter', 'predicate']);
proc.doChangeBlockVisibility(context.expression, true);
this.changeBlockVisibility(context.expression, true);
}
);
@ -709,7 +709,7 @@ SnapExtensions.primitives.set(
'ide_show(block)',
function (context, proc) {
proc.assertType(context, ['command', 'reporter', 'predicate']);
proc.doChangeBlockVisibility(context.expression, false);
this.changeBlockVisibility(context.expression, false);
}
);

Wyświetl plik

@ -3248,6 +3248,60 @@ SpriteMorph.prototype.allPaletteBlocks = function () {
return blocks.filter(each => each instanceof BlockMorph);
};
SpriteMorph.prototype.changeBlockVisibility = function (aBlock, hideIt) {
if (aBlock.isCustomBlock) {
this.changeCustomBlockVisibility(aBlock, hideIt);
} else if (aBlock.selector === 'reportGetVar') {
this.changeVarBlockVisibility(aBlock.blockSpec, hideIt);
} else {
this.changePrimitiveVisibility(aBlock, hideIt);
}
};
SpriteMorph.prototype.changePrimitiveVisibility = function (aBlock, hideIt) {
var ide = this.parentThatIsA(IDE_Morph),
dict,
cat;
if (!ide || (aBlock.selector === 'evaluateCustomBlock')) {
return;
}
if (hideIt) {
StageMorph.prototype.hiddenPrimitives[aBlock.selector] = true;
} else {
delete StageMorph.prototype.hiddenPrimitives[aBlock.selector];
}
dict = {
doWarp: 'control',
reifyScript: 'operators',
reifyReporter: 'operators',
reifyPredicate: 'operators',
doDeclareVariables: 'variables'
};
cat = dict[aBlock.selector] || aBlock.category;
if (cat === 'lists') {cat = 'variables'; }
ide.flushBlocksCache(cat);
ide.refreshPalette();
};
SpriteMorph.prototype.changeCustomBlockVisibility = function (aBlock, hideIt) {
var ide = this.parentThatIsA(IDE_Morph),
method = aBlock.isGlobal ? aBlock.definition
: this.getLocalMethod(aBlock.semanticSpec);
if (!ide || !method || (aBlock.selector !== 'evaluateCustomBlock')) {
return;
}
method.isHelper = !!hideIt; // force type to be Boolean
ide.flushBlocksCache(aBlock.category);
ide.refreshPalette();
};
SpriteMorph.prototype.changeVarBlockVisibility = function (name, hideIt) {
var ide = this.parentThatIsA(IDE_Morph);
this.variables.find(name).vars[name].isHidden = !!hideIt;
ide.flushBlocksCache('variables');
ide.refreshPalette();
};
// SpriteMorph blocks searching
SpriteMorph.prototype.blocksMatching = function (
@ -9335,6 +9389,23 @@ StageMorph.prototype.freshPalette = SpriteMorph.prototype.freshPalette;
StageMorph.prototype.blocksMatching = SpriteMorph.prototype.blocksMatching;
StageMorph.prototype.searchBlocks = SpriteMorph.prototype.searchBlocks;
// StageMorph utilities for showing & hiding blocks in the palette
StageMorph.prototype.allPaletteBlocks
= SpriteMorph.prototype.allPaletteBlocks;
StageMorph.prototype.changeBlockVisibility
= SpriteMorph.prototype.changeBlockVisibility;
StageMorph.prototype.changePrimitiveVisibility
= SpriteMorph.prototype.changePrimitiveVisibility;
StageMorph.prototype.changeCustomBlockVisibility
= SpriteMorph.prototype.changeCustomBlockVisibility;
StageMorph.prototype.changeVarBlockVisibility
= SpriteMorph.prototype.changeVarBlockVisibility;
// StageMorph neighbor detection
StageMorph.prototype.neighbors = SpriteMorph.prototype.neighbors;

Wyświetl plik

@ -1726,11 +1726,7 @@ Process.prototype.doShowVar = function (varName, context) {
if (name.expression.selector === 'reportGetVar') {
name = name.expression.blockSpec;
} else {
if (name.expression.isCustomBlock) {
this.doChangeCustomBlockVisibility(name.expression, false);
} else {
this.doChangePrimitiveVisibility(name.expression, false);
}
this.blockReceiver().changeBlockVisibility(name.expression, false);
return;
}
}
@ -1792,11 +1788,7 @@ Process.prototype.doHideVar = function (varName, context) {
if (name.expression.selector === 'reportGetVar') {
name = name.expression.blockSpec;
} else {
if (name.expression.isCustomBlock) {
this.doChangeCustomBlockVisibility(name.expression, true);
} else {
this.doChangePrimitiveVisibility(name.expression, true);
}
this.blockReceiver().changeBlockVisibility(name.expression, true);
return;
}
}
@ -1839,64 +1831,6 @@ Process.prototype.doRemoveTemporaries = function () {
}
};
// Process hiding and showing blocks in the palette
Process.prototype.doChangeBlockVisibility = function (aBlock, hideIt) {
if (aBlock.isCustomBlock) {
this.doChangeCustomBlockVisibility(aBlock, hideIt);
} else if (aBlock.selector === 'reportGetVar') {
this.doChangeVarBlockVisibility(aBlock.blockSpec, hideIt);
} else {
this.doChangePrimitiveVisibility(aBlock, hideIt);
}
};
Process.prototype.doChangePrimitiveVisibility = function (aBlock, hideIt) {
var ide = this.homeContext.receiver.parentThatIsA(IDE_Morph),
dict,
cat;
if (!ide || (aBlock.selector === 'evaluateCustomBlock')) {
return;
}
if (hideIt) {
StageMorph.prototype.hiddenPrimitives[aBlock.selector] = true;
} else {
delete StageMorph.prototype.hiddenPrimitives[aBlock.selector];
}
dict = {
doWarp: 'control',
reifyScript: 'operators',
reifyReporter: 'operators',
reifyPredicate: 'operators',
doDeclareVariables: 'variables'
};
cat = dict[aBlock.selector] || aBlock.category;
if (cat === 'lists') {cat = 'variables'; }
ide.flushBlocksCache(cat);
ide.refreshPalette();
};
Process.prototype.doChangeCustomBlockVisibility = function (aBlock, hideIt) {
var ide = this.homeContext.receiver.parentThatIsA(IDE_Morph),
method = aBlock.isGlobal ? aBlock.definition
: this.blockReceiver().getLocalMethod(aBlock.semanticSpec);
if (!ide || !method || (aBlock.selector !== 'evaluateCustomBlock')) {
return;
}
method.isHelper = !!hideIt; // force type to be Boolean
ide.flushBlocksCache(aBlock.category);
ide.refreshPalette();
};
Process.prototype.doChangeVarBlockVisibility = function (name, hideIt) {
var rcvr = this.blockReceiver(),
ide = rcvr.parentThatIsA(IDE_Morph);
rcvr.variables.find(name).vars[name].isHidden = !!hideIt;
ide.flushBlocksCache('variables');
ide.refreshPalette();
};
// Process sprite inheritance primitives
Process.prototype.doDeleteAttr = function (attrName) {