separated global and local variables in the palette, marked local ones with location pin

upd4.2
Jens Mönig 2018-01-22 14:33:47 +01:00
rodzic 4aa1fac41e
commit 7e74a345e5
4 zmienionych plików z 98 dodań i 22 usunięć

Wyświetl plik

@ -1603,8 +1603,8 @@ SyntaxElementMorph.prototype.fixLayout = function (silently) {
lines = [],
space = this.isPrototype ?
1 : Math.floor(fontHeight(this.fontSize) / 3),
ico = this.isCustomBlock && !this.isGlobal ?
this.methodIconExtent().x + space : 0,
ico = this instanceof BlockMorph && this.hasLocationPin() ?
this.methodIconExtent().x + space : 0,
bottomCorrection,
initialExtent = this.extent();
@ -1838,8 +1838,8 @@ SyntaxElementMorph.prototype.fixHighlight = function () {
SyntaxElementMorph.prototype.methodIconExtent = function () {
// answer the span of the icon for the "local method" indicator
var ico = this.fontSize * 1.2;
return this.isCustomBlock && !this.isGlobal ?
new Point(ico * 0.66, ico) : new Point(0, 0);
return this.hasLocationPin() ? new Point(ico * 0.66, ico)
: new Point(0, 0);
};
// SyntaxElementMorph evaluating:
@ -3558,6 +3558,10 @@ BlockMorph.prototype.eraseHoles = function (context) {
};
BlockMorph.prototype.hasLocationPin = function () {
return (this.isCustomBlock && !this.isGlobal) || this.isLocalVarTemplate;
};
// BlockMorph highlighting
BlockMorph.prototype.addHighlight = function (oldHighlight) {
@ -3849,6 +3853,11 @@ BlockMorph.prototype.fullCopy = function () {
};
BlockMorph.prototype.reactToTemplateCopy = function () {
if (this.isLocalVarTemplate) {
this.isLocalVarTemplate = null;
this.drawNew();
this.fixLayout();
}
this.forceNormalColoring();
};
@ -4627,8 +4636,8 @@ CommandBlockMorph.prototype.drawNew = function () {
*/
}
// draw method icon if applicable
if (this.isCustomBlock && !this.isGlobal) {
// draw location pin icon if applicable
if (this.hasLocationPin()) {
this.drawMethodIcon(context);
}
@ -5182,6 +5191,7 @@ ReporterBlockMorph.prototype.init = function (isPredicate, silently) {
this.isPredicate = isPredicate || false;
this.setExtent(new Point(200, 80), silently);
this.cachedSlotSpec = null; // don't serialize
this.isLocalVarTemplate = null; // don't serialize
};
// ReporterBlockMorph drag & drop:
@ -5403,10 +5413,11 @@ ReporterBlockMorph.prototype.drawNew = function () {
this.drawRounded(context);
}
// draw method icon if applicable
if (this.isCustomBlock && !this.isGlobal) {
// draw location pin icon if applicable
if (this.hasLocationPin()) {
this.drawMethodIcon(context);
}
// erase CommandSlots
this.eraseHoles(context);
};

Wyświetl plik

@ -3854,12 +3854,13 @@ Fixes:
* Blocks: made the OF-block auto-unringify when dropped on ring-slots
* Blocks: disabled firing the Custom-Block-Dialog when accidentall clicking on a custom block definition script
180121
180122
------
* Morphic: fixed occasional stuck cursors, thanks, Bernat!
* Paint: fixed a flood-fill alpha issue, thanks, Bernat!I
* Blocks, GUI: minor fixes, contributed by the community
* various Translation updates, contributed by the community
* Blocks, Objects, Threads: separated global and local variables in the palette, marked local ones with location pin
v4.1.1 New Features:
@ -3869,8 +3870,9 @@ v4.1.1 New Features:
* added "width" and "height" selectors to Pixels library
Notable Changes:
* global and local variables are now separat in the palette, each sorted alphabetically, local vars marked with location pin (only in palette)
* keyboard events are now always thread safe (the same as in Scratch nowadays)
* the OF-block auto-unringified when being dropped on ring-slots, such as in CALL
* the OF-block auto-unringifies when being dropped on ring-slots, such as in CALL
* accidentally clicking on a custom block definition no longer fires up the Block Dialog
Notable Fixes:

Wyświetl plik

@ -1751,11 +1751,12 @@ SpriteMorph.prototype.blockForSelector = function (selector, setDefaults) {
return block;
};
SpriteMorph.prototype.variableBlock = function (varName) {
SpriteMorph.prototype.variableBlock = function (varName, isLocalTemplate) {
var block = new ReporterBlockMorph(false);
block.selector = 'reportGetVar';
block.color = this.blockColor.variables;
block.category = 'variables';
block.isLocalVarTemplate = isLocalTemplate;
block.setSpec(varName);
block.isDraggable = true;
return block;
@ -1778,8 +1779,8 @@ SpriteMorph.prototype.blockTemplates = function (category) {
return newBlock;
}
function variableBlock(varName) {
var newBlock = SpriteMorph.prototype.variableBlock(varName);
function variableBlock(varName, isLocal) {
var newBlock = SpriteMorph.prototype.variableBlock(varName, isLocal);
newBlock.isDraggable = false;
newBlock.isTemplate = true;
if (contains(inheritedVars, varName)) {
@ -2195,7 +2196,7 @@ SpriteMorph.prototype.blockTemplates = function (category) {
blocks.push('-');
varNames = this.variables.allNames();
varNames = this.reachableGlobalVariableNames(true);
if (varNames.length > 0) {
varNames.forEach(function (name) {
blocks.push(variableWatcherToggle(name));
@ -2204,6 +2205,15 @@ SpriteMorph.prototype.blockTemplates = function (category) {
blocks.push('-');
}
varNames = this.allLocalVariableNames(true);
if (varNames.length > 0) {
varNames.forEach(function (name) {
blocks.push(variableWatcherToggle(name));
blocks.push(variableBlock(name, true));
});
blocks.push('-');
}
blocks.push(block('doSetVar'));
blocks.push(block('doChangeVar'));
blocks.push(block('doShowVar'));
@ -5735,6 +5745,41 @@ SpriteMorph.prototype.hasSpriteVariable = function (varName) {
return contains(this.variables.names(), varName);
};
SpriteMorph.prototype.allLocalVariableNames = function (sorted) {
var exceptGlobals = this.globalVariables(),
globalNames = exceptGlobals.names(),
data;
function alphabetically(x, y) {
return x.toLowerCase() < y.toLowerCase() ? -1 : 1;
}
data = this.variables.allNames(exceptGlobals).filter(function (each) {
return !contains(globalNames, each);
});
if (sorted) {
data.sort(alphabetically);
}
return data;
};
SpriteMorph.prototype.reachableGlobalVariableNames = function (sorted) {
var locals = this.allLocalVariableNames(),
data;
function alphabetically(x, y) {
return x.toLowerCase() < y.toLowerCase() ? -1 : 1;
}
data = this.globalVariables().names().filter(function (each) {
return !contains(locals, each);
});
if (sorted) {
data.sort(alphabetically);
}
return data;
};
// SpriteMorph inheritance - custom blocks
SpriteMorph.prototype.getMethod = function (spec) {
@ -6927,13 +6972,14 @@ StageMorph.prototype.blockTemplates = function (category) {
return newBlock;
}
function variableBlock(varName) {
var newBlock = SpriteMorph.prototype.variableBlock(varName);
function variableBlock(varName, isLocal) {
var newBlock = SpriteMorph.prototype.variableBlock(varName, isLocal);
newBlock.isDraggable = false;
newBlock.isTemplate = true;
return newBlock;
}
function watcherToggle(selector) {
if (myself.hiddenPrimitives[selector]) {
return null;
@ -7267,7 +7313,7 @@ StageMorph.prototype.blockTemplates = function (category) {
blocks.push('-');
varNames = this.variables.allNames();
varNames = this.reachableGlobalVariableNames(true);
if (varNames.length > 0) {
varNames.forEach(function (name) {
blocks.push(variableWatcherToggle(name));
@ -7276,6 +7322,15 @@ StageMorph.prototype.blockTemplates = function (category) {
blocks.push('-');
}
varNames = this.allLocalVariableNames(true);
if (varNames.length > 0) {
varNames.forEach(function (name) {
blocks.push(variableWatcherToggle(name));
blocks.push(variableBlock(name, true));
});
blocks.push('-');
}
blocks.push(block('doSetVar'));
blocks.push(block('doChangeVar'));
blocks.push(block('doShowVar'));
@ -7698,6 +7753,12 @@ StageMorph.prototype.inheritedVariableNames = function () {
return [];
};
StageMorph.prototype.allLocalVariableNames
= SpriteMorph.prototype.allLocalVariableNames;
StageMorph.prototype.reachableGlobalVariableNames
= SpriteMorph.prototype.reachableGlobalVariableNames;
// StageMorph inheritance - custom blocks
StageMorph.prototype.getMethod

Wyświetl plik

@ -61,7 +61,7 @@ StageMorph, SpriteMorph, StagePrompterMorph, Note, modules, isString, copy,
isNil, WatcherMorph, List, ListWatcherMorph, alert, console, TableMorph,
TableFrameMorph, ColorSlotMorph, isSnapObject*/
modules.threads = '2018-January-21';
modules.threads = '2018-January-22';
var ThreadManager;
var Process;
@ -4100,7 +4100,8 @@ VariableFrame.prototype.names = function () {
return names;
};
VariableFrame.prototype.allNamesDict = function () {
VariableFrame.prototype.allNamesDict = function (upTo) {
// "upTo" is an optional parent frame at which to stop, e.g. globals
var dict = {}, current = this;
function addKeysToDict(srcDict, trgtDict) {
@ -4112,19 +4113,20 @@ VariableFrame.prototype.allNamesDict = function () {
}
}
while (current) {
while (current && (current !== upTo)) {
addKeysToDict(current.vars, dict);
current = current.parentFrame;
}
return dict;
};
VariableFrame.prototype.allNames = function () {
VariableFrame.prototype.allNames = function (upTo) {
/*
only show the names of the lexical scope, hybrid scoping is
reserved to the daring ;-)
"upTo" is an optional parent frame at which to stop, e.g. globals
*/
var answer = [], each, dict = this.allNamesDict();
var answer = [], each, dict = this.allNamesDict(upTo);
for (each in dict) {
if (Object.prototype.hasOwnProperty.call(dict, each)) {