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,
|
fontHeight, TableFrameMorph, SpriteMorph, Context, ListWatcherMorph,
|
||||||
CellMorph, DialogBoxMorph, BlockInputFragmentMorph, PrototypeHatBlockMorph,
|
CellMorph, DialogBoxMorph, BlockInputFragmentMorph, PrototypeHatBlockMorph,
|
||||||
Costume, IDE_Morph, BlockDialogMorph, BlockEditorMorph, localize, isNil,
|
Costume, IDE_Morph, BlockDialogMorph, BlockEditorMorph, localize, isNil,
|
||||||
isSnapObject, copy, PushButtonMorph, SpriteIconMorph, Process, AlignmentMorph*/
|
isSnapObject, copy, PushButtonMorph, SpriteIconMorph, Process, AlignmentMorph,
|
||||||
|
CustomCommandBlockMorph*/
|
||||||
|
|
||||||
// Global stuff ////////////////////////////////////////////////////////
|
// Global stuff ////////////////////////////////////////////////////////
|
||||||
|
|
||||||
modules.blocks = '2017-January-03';
|
modules.blocks = '2017-January-04';
|
||||||
|
|
||||||
var SyntaxElementMorph;
|
var SyntaxElementMorph;
|
||||||
var BlockMorph;
|
var BlockMorph;
|
||||||
|
@ -710,7 +711,7 @@ SyntaxElementMorph.prototype.definesScriptVariable = function (name) {
|
||||||
|| (this.blockSpec && this.blockSpec.match('%upvar')))
|
|| (this.blockSpec && this.blockSpec.match('%upvar')))
|
||||||
&& (detect(this.inputs()[0].allInputs(), function (input) {
|
&& (detect(this.inputs()[0].allInputs(), function (input) {
|
||||||
return (input.selector === 'reportGetVar'
|
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.addLine();
|
||||||
menu.addItem(
|
menu.addItem(
|
||||||
'rename all in this scope...',
|
'rename all...',
|
||||||
'refactorThisVar'
|
'refactorThisVar',
|
||||||
|
'rename all blocks that\naccess this variable'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -2399,28 +2401,33 @@ BlockMorph.prototype.userMenu = function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.selector === 'reportGetVar') {
|
if (this.selector === 'reportGetVar') {
|
||||||
blck = this.fullCopy();
|
if (!(this.isInheritedVariable())) {
|
||||||
blck.addShadow();
|
blck = this.fullCopy();
|
||||||
menu.addItem(
|
blck.addShadow();
|
||||||
'rename just here...',
|
menu.addItem(
|
||||||
function () {
|
'rename...',
|
||||||
if (this.isTemplate) {
|
function () {
|
||||||
myself.refactorThisVar(true); // just the template
|
if (this.isTemplate) {
|
||||||
} else {
|
myself.refactorThisVar(true); // just the template
|
||||||
new DialogBoxMorph(
|
} else {
|
||||||
myself,
|
new DialogBoxMorph(
|
||||||
myself.userSetSpec,
|
myself,
|
||||||
myself
|
myself.userSetSpec,
|
||||||
).prompt(
|
myself
|
||||||
"Variable name",
|
).prompt(
|
||||||
myself.blockSpec,
|
"Variable name",
|
||||||
world,
|
myself.blockSpec,
|
||||||
blck.fullImage(), // pic
|
world,
|
||||||
InputSlotMorph.prototype.getVarNamesDict.call(myself)
|
blck.fullImage(), // pic
|
||||||
);
|
InputSlotMorph.prototype.getVarNamesDict.call(
|
||||||
}
|
myself
|
||||||
}
|
)
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'rename only\nthis reporter'
|
||||||
|
);
|
||||||
|
}
|
||||||
if (this.isTemplate) {
|
if (this.isTemplate) {
|
||||||
return menu;
|
return menu;
|
||||||
}
|
}
|
||||||
|
@ -2589,6 +2596,19 @@ BlockMorph.prototype.hidePrimitive = function () {
|
||||||
ide.refreshPalette();
|
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 () {
|
BlockMorph.prototype.isTransientVariable = function () {
|
||||||
// private - only for variable getter template inside the palette
|
// private - only for variable getter template inside the palette
|
||||||
var varFrame = this.receiver().variables.silentFind(this.blockSpec);
|
var varFrame = this.receiver().variables.silentFind(this.blockSpec);
|
||||||
|
@ -3080,8 +3100,10 @@ BlockMorph.prototype.refactorThisVar = function (justTheTemplate) {
|
||||||
ide = this.parentThatIsA(IDE_Morph),
|
ide = this.parentThatIsA(IDE_Morph),
|
||||||
stage = ide.stage,
|
stage = ide.stage,
|
||||||
oldWatcher = receiver.findVariableWatcher(oldName),
|
oldWatcher = receiver.findVariableWatcher(oldName),
|
||||||
|
cpy = this.fullCopy(),
|
||||||
oldValue, newWatcher;
|
oldValue, newWatcher;
|
||||||
|
|
||||||
|
cpy.addShadow();
|
||||||
new DialogBoxMorph(
|
new DialogBoxMorph(
|
||||||
this,
|
this,
|
||||||
function (newName) {
|
function (newName) {
|
||||||
|
@ -3178,7 +3200,7 @@ BlockMorph.prototype.refactorThisVar = function (justTheTemplate) {
|
||||||
'Variable name',
|
'Variable name',
|
||||||
oldName,
|
oldName,
|
||||||
this.world(),
|
this.world(),
|
||||||
this.fullImage(), // pic
|
cpy.fullImage(), // pic
|
||||||
InputSlotMorph.prototype.getVarNamesDict.call(this)
|
InputSlotMorph.prototype.getVarNamesDict.call(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -3188,7 +3210,7 @@ BlockMorph.prototype.refactorThisVar = function (justTheTemplate) {
|
||||||
'A variable with this name already exists ' +
|
'A variable with this name already exists ' +
|
||||||
(where || 'in this context') + '.'
|
(where || 'in this context') + '.'
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// BlockMorph drawing
|
// BlockMorph drawing
|
||||||
|
|
|
@ -3242,6 +3242,10 @@ http://snap.berkeley.edu/run#cloud:Username=jens&ProjectName=rotation
|
||||||
* Hierarchical menus, thanks, Brian!
|
* Hierarchical menus, thanks, Brian!
|
||||||
* Tweaks to hierarchical menus
|
* Tweaks to hierarchical menus
|
||||||
|
|
||||||
|
170104
|
||||||
|
------
|
||||||
|
* Variable refactoring, yay! Thanks, Bernat!!
|
||||||
|
|
||||||
|
|
||||||
== v4.10 === (in development)
|
== v4.10 === (in development)
|
||||||
|
|
||||||
|
@ -3250,13 +3254,14 @@ Features:
|
||||||
* undo / redo for blocks, unlimited, but has some issues
|
* undo / redo for blocks, unlimited, but has some issues
|
||||||
* search field for projects, thanks, Bernat!!
|
* search field for projects, thanks, Bernat!!
|
||||||
* basic typography support for custom block labels, 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 switch #dl: for downloading raw shared projects
|
||||||
* new url option switch: &noExitWarning
|
* new url option switch: &noExitWarning
|
||||||
* svg support for images from the web (svg files have been supported for a long time)
|
* svg support for images from the web (svg files have been supported for a long time)
|
||||||
* use media dialog for browsing and importing sounds
|
* 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!
|
* 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!
|
* hierarchical menus, also for custom blocks, thanks, Brian!
|
||||||
|
* variable refactoring, thanks, Bernat!
|
||||||
|
|
||||||
Fixes:
|
Fixes:
|
||||||
* Music (play note) to work again in new and recent browser versions (Chrome 55)
|
* 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,
|
BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, localize,
|
||||||
TableMorph, TableFrameMorph, normalizeCanvas, BooleanSlotMorph*/
|
TableMorph, TableFrameMorph, normalizeCanvas, BooleanSlotMorph*/
|
||||||
|
|
||||||
modules.objects = '2017-January-03';
|
modules.objects = '2017-January-04';
|
||||||
|
|
||||||
var SpriteMorph;
|
var SpriteMorph;
|
||||||
var StageMorph;
|
var StageMorph;
|
||||||
|
|
Ładowanie…
Reference in New Issue