kopia lustrzana https://github.com/backface/turtlestitch
prevent inherited variables from being refactored
and from causing an error because they can’t be. Also, changed wording of variable renaming menu items and added a shadow to the variable block symbol in the dialog box (so it looks the same as the one that’s already in use elsewhere)pull/29/head
rodzic
5117cd4a40
commit
cae286d346
82
blocks.js
82
blocks.js
|
@ -145,11 +145,12 @@ radians, useBlurredShadows, SpeechBubbleMorph, modules, StageMorph,
|
|||
fontHeight, TableFrameMorph, SpriteMorph, Context, ListWatcherMorph,
|
||||
CellMorph, DialogBoxMorph, BlockInputFragmentMorph, PrototypeHatBlockMorph,
|
||||
Costume, IDE_Morph, BlockDialogMorph, BlockEditorMorph, localize, isNil,
|
||||
isSnapObject, copy, PushButtonMorph, SpriteIconMorph, Process, AlignmentMorph*/
|
||||
isSnapObject, copy, PushButtonMorph, SpriteIconMorph, Process, AlignmentMorph,
|
||||
CustomCommandBlockMorph*/
|
||||
|
||||
// Global stuff ////////////////////////////////////////////////////////
|
||||
|
||||
modules.blocks = '2017-January-03';
|
||||
modules.blocks = '2017-January-04';
|
||||
|
||||
var SyntaxElementMorph;
|
||||
var BlockMorph;
|
||||
|
@ -710,7 +711,7 @@ SyntaxElementMorph.prototype.definesScriptVariable = function (name) {
|
|||
|| (this.blockSpec && this.blockSpec.match('%upvar')))
|
||||
&& (detect(this.inputs()[0].allInputs(), function (input) {
|
||||
return (input.selector === 'reportGetVar'
|
||||
&& input.blockSpec === name)
|
||||
&& input.blockSpec === name);
|
||||
})));
|
||||
};
|
||||
|
||||
|
@ -2387,11 +2388,12 @@ BlockMorph.prototype.userMenu = function () {
|
|||
);
|
||||
}
|
||||
}
|
||||
if (this.selector === 'reportGetVar') {
|
||||
if (this.selector === 'reportGetVar' && !this.isInheritedVariable()) {
|
||||
menu.addLine();
|
||||
menu.addItem(
|
||||
'rename all in this scope...',
|
||||
'refactorThisVar'
|
||||
'rename all...',
|
||||
'refactorThisVar',
|
||||
'rename all blocks that\naccess this variable'
|
||||
);
|
||||
}
|
||||
} else {
|
||||
|
@ -2399,28 +2401,33 @@ BlockMorph.prototype.userMenu = function () {
|
|||
}
|
||||
|
||||
if (this.selector === 'reportGetVar') {
|
||||
blck = this.fullCopy();
|
||||
blck.addShadow();
|
||||
menu.addItem(
|
||||
'rename just here...',
|
||||
function () {
|
||||
if (this.isTemplate) {
|
||||
myself.refactorThisVar(true); // just the template
|
||||
} else {
|
||||
new DialogBoxMorph(
|
||||
myself,
|
||||
myself.userSetSpec,
|
||||
myself
|
||||
).prompt(
|
||||
"Variable name",
|
||||
myself.blockSpec,
|
||||
world,
|
||||
blck.fullImage(), // pic
|
||||
InputSlotMorph.prototype.getVarNamesDict.call(myself)
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
if (!(this.isInheritedVariable())) {
|
||||
blck = this.fullCopy();
|
||||
blck.addShadow();
|
||||
menu.addItem(
|
||||
'rename...',
|
||||
function () {
|
||||
if (this.isTemplate) {
|
||||
myself.refactorThisVar(true); // just the template
|
||||
} else {
|
||||
new DialogBoxMorph(
|
||||
myself,
|
||||
myself.userSetSpec,
|
||||
myself
|
||||
).prompt(
|
||||
"Variable name",
|
||||
myself.blockSpec,
|
||||
world,
|
||||
blck.fullImage(), // pic
|
||||
InputSlotMorph.prototype.getVarNamesDict.call(
|
||||
myself
|
||||
)
|
||||
);
|
||||
}
|
||||
},
|
||||
'rename only\nthis reporter'
|
||||
);
|
||||
}
|
||||
if (this.isTemplate) {
|
||||
return menu;
|
||||
}
|
||||
|
@ -2589,6 +2596,19 @@ BlockMorph.prototype.hidePrimitive = function () {
|
|||
ide.refreshPalette();
|
||||
};
|
||||
|
||||
BlockMorph.prototype.isInheritedVariable = function () {
|
||||
// private - only for variable getter template inside the palette
|
||||
if (this.isTemplate &&
|
||||
(this.selector === 'reportGetVar') &&
|
||||
(this.parent instanceof FrameMorph)) {
|
||||
return contains(
|
||||
this.receiver().inheritedVariableNames(),
|
||||
this.blockSpec
|
||||
);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
BlockMorph.prototype.isTransientVariable = function () {
|
||||
// private - only for variable getter template inside the palette
|
||||
var varFrame = this.receiver().variables.silentFind(this.blockSpec);
|
||||
|
@ -3080,8 +3100,10 @@ BlockMorph.prototype.refactorThisVar = function (justTheTemplate) {
|
|||
ide = this.parentThatIsA(IDE_Morph),
|
||||
stage = ide.stage,
|
||||
oldWatcher = receiver.findVariableWatcher(oldName),
|
||||
cpy = this.fullCopy(),
|
||||
oldValue, newWatcher;
|
||||
|
||||
cpy.addShadow();
|
||||
new DialogBoxMorph(
|
||||
this,
|
||||
function (newName) {
|
||||
|
@ -3178,7 +3200,7 @@ BlockMorph.prototype.refactorThisVar = function (justTheTemplate) {
|
|||
'Variable name',
|
||||
oldName,
|
||||
this.world(),
|
||||
this.fullImage(), // pic
|
||||
cpy.fullImage(), // pic
|
||||
InputSlotMorph.prototype.getVarNamesDict.call(this)
|
||||
);
|
||||
|
||||
|
@ -3188,7 +3210,7 @@ BlockMorph.prototype.refactorThisVar = function (justTheTemplate) {
|
|||
'A variable with this name already exists ' +
|
||||
(where || 'in this context') + '.'
|
||||
);
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
// BlockMorph drawing
|
||||
|
|
|
@ -3242,6 +3242,10 @@ http://snap.berkeley.edu/run#cloud:Username=jens&ProjectName=rotation
|
|||
* Hierarchical menus, thanks, Brian!
|
||||
* Tweaks to hierarchical menus
|
||||
|
||||
170104
|
||||
------
|
||||
* Variable refactoring, yay! Thanks, Bernat!!
|
||||
|
||||
|
||||
== v4.10 === (in development)
|
||||
|
||||
|
@ -3250,13 +3254,14 @@ Features:
|
|||
* undo / redo for blocks, unlimited, but has some issues
|
||||
* search field for projects, thanks, Bernat!!
|
||||
* basic typography support for custom block labels, thanks, Bernat!!
|
||||
* Treat JS-function reporters the same as variable getters wrt rings
|
||||
* treat JS-function reporters the same as variable getters wrt rings
|
||||
* new url switch #dl: for downloading raw shared projects
|
||||
* new url option switch: &noExitWarning
|
||||
* svg support for images from the web (svg files have been supported for a long time)
|
||||
* use media dialog for browsing and importing sounds
|
||||
* highly experimental infix-expression-to-reporter parser. Thanks, Bernat, for the brilliant idea to add it to the search-blocks field!
|
||||
* hierarchical menus, also for custom blocks, thanks, Brian!
|
||||
* variable refactoring, thanks, Bernat!
|
||||
|
||||
Fixes:
|
||||
* Music (play note) to work again in new and recent browser versions (Chrome 55)
|
||||
|
|
|
@ -82,7 +82,7 @@ SpeechBubbleMorph, RingMorph, isNil, FileReader, TableDialogMorph,
|
|||
BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, localize,
|
||||
TableMorph, TableFrameMorph, normalizeCanvas, BooleanSlotMorph*/
|
||||
|
||||
modules.objects = '2017-January-03';
|
||||
modules.objects = '2017-January-04';
|
||||
|
||||
var SpriteMorph;
|
||||
var StageMorph;
|
||||
|
|
Ładowanie…
Reference in New Issue