kopia lustrzana https://github.com/backface/turtlestitch
refactored variable refactoring code
rodzic
bb8154a211
commit
0f006d3965
250
blocks.js
250
blocks.js
|
@ -150,7 +150,7 @@ CustomCommandBlockMorph*/
|
||||||
|
|
||||||
// Global stuff ////////////////////////////////////////////////////////
|
// Global stuff ////////////////////////////////////////////////////////
|
||||||
|
|
||||||
modules.blocks = '2017-January-04';
|
modules.blocks = '2017-January-05';
|
||||||
|
|
||||||
var SyntaxElementMorph;
|
var SyntaxElementMorph;
|
||||||
var BlockMorph;
|
var BlockMorph;
|
||||||
|
@ -3104,135 +3104,133 @@ BlockMorph.prototype.refactorThisVar = function (justTheTemplate) {
|
||||||
oldValue, newWatcher;
|
oldValue, newWatcher;
|
||||||
|
|
||||||
cpy.addShadow();
|
cpy.addShadow();
|
||||||
new DialogBoxMorph(
|
new DialogBoxMorph(this, renameVarTo, this).prompt(
|
||||||
this,
|
'Variable name',
|
||||||
function (newName) {
|
oldName,
|
||||||
var definer;
|
this.world(),
|
||||||
|
cpy.fullImage(), // pic
|
||||||
if (this.parent instanceof SyntaxElementMorph) {
|
InputSlotMorph.prototype.getVarNamesDict.call(this)
|
||||||
// script var
|
);
|
||||||
if (justTheTemplate) {
|
|
||||||
myself.userSetSpec(newName);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
definer = this.parentThatIsA(CommandBlockMorph);
|
|
||||||
if (definer.definesScriptVariable(newName)) {
|
|
||||||
varExistsError();
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
definer.refactorVarInStack(oldName, newName, true);
|
|
||||||
}
|
|
||||||
} else if (receiver.hasSpriteVariable(oldName)) {
|
|
||||||
// sprite local var
|
|
||||||
if (receiver.hasSpriteVariable(newName)) {
|
|
||||||
varExistsError();
|
|
||||||
return;
|
|
||||||
} else if (!isNil(ide.globalVariables.vars[newName])) {
|
|
||||||
varExistsError('as a global variable');
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
oldValue = receiver.variables.getVar(oldName);
|
|
||||||
receiver.deleteVariable(oldName);
|
|
||||||
receiver.addVariable(newName, false);
|
|
||||||
receiver.variables.setVar(newName, oldValue);
|
|
||||||
|
|
||||||
if (oldWatcher && oldWatcher.isVisible) {
|
function renameVarTo (newName) {
|
||||||
newWatcher = receiver.toggleVariableWatcher(
|
var definer;
|
||||||
newName,
|
|
||||||
false
|
if (this.parent instanceof SyntaxElementMorph) {
|
||||||
);
|
// script var
|
||||||
newWatcher.setPosition(oldWatcher.position());
|
if (justTheTemplate) {
|
||||||
}
|
myself.userSetSpec(newName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
definer = this.parentThatIsA(CommandBlockMorph);
|
||||||
|
if (definer.definesScriptVariable(newName)) {
|
||||||
|
varExistsError();
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
definer.refactorVarInStack(oldName, newName, true);
|
||||||
|
}
|
||||||
|
} else if (receiver.hasSpriteVariable(oldName)) {
|
||||||
|
// sprite local var
|
||||||
|
if (receiver.hasSpriteVariable(newName)) {
|
||||||
|
varExistsError();
|
||||||
|
return;
|
||||||
|
} else if (!isNil(ide.globalVariables.vars[newName])) {
|
||||||
|
varExistsError('as a global variable');
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
oldValue = receiver.variables.getVar(oldName);
|
||||||
|
receiver.deleteVariable(oldName);
|
||||||
|
receiver.addVariable(newName, false);
|
||||||
|
receiver.variables.setVar(newName, oldValue);
|
||||||
|
|
||||||
if (!justTheTemplate) {
|
if (oldWatcher && oldWatcher.isVisible) {
|
||||||
receiver.refactorVariableInstances(
|
newWatcher = receiver.toggleVariableWatcher(
|
||||||
oldName,
|
newName,
|
||||||
newName,
|
false
|
||||||
false
|
);
|
||||||
);
|
newWatcher.setPosition(oldWatcher.position());
|
||||||
receiver.customBlocks.forEach(function (eachBlock) {
|
|
||||||
eachBlock.body.expression.refactorVarInStack(
|
|
||||||
oldName,
|
|
||||||
newName
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// global var
|
|
||||||
if (!isNil(ide.globalVariables.vars[newName])) {
|
|
||||||
varExistsError();
|
|
||||||
return;
|
|
||||||
} else if (
|
|
||||||
detect(
|
|
||||||
stage.children,
|
|
||||||
function (any) {
|
|
||||||
return any instanceof SpriteMorph &&
|
|
||||||
any.hasSpriteVariable(newName);
|
|
||||||
})
|
|
||||||
) {
|
|
||||||
varExistsError('as a sprite local variable');
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
oldValue = ide.globalVariables.getVar(oldName);
|
|
||||||
stage.deleteVariable(oldName);
|
|
||||||
stage.addVariable(newName, true);
|
|
||||||
ide.globalVariables.setVar(newName, oldValue);
|
|
||||||
|
|
||||||
if (oldWatcher && oldWatcher.isVisible) {
|
|
||||||
newWatcher = receiver.toggleVariableWatcher(
|
|
||||||
newName,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
newWatcher.setPosition(oldWatcher.position());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!justTheTemplate) {
|
|
||||||
stage.refactorVariableInstances(
|
|
||||||
oldName,
|
|
||||||
newName,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
stage.globalBlocks.forEach(function (eachBlock) {
|
|
||||||
eachBlock.body.expression.refactorVarInStack(
|
|
||||||
oldName,
|
|
||||||
newName
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
stage.forAllChildren(function (child) {
|
|
||||||
if (child instanceof SpriteMorph) {
|
|
||||||
child.refactorVariableInstances(
|
|
||||||
oldName,
|
|
||||||
newName,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
child.customBlocks.forEach(
|
|
||||||
function (eachBlock) {
|
|
||||||
eachBlock.body.expression
|
|
||||||
.refactorVarInStack(
|
|
||||||
oldName,
|
|
||||||
newName
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ide.flushBlocksCache('variables');
|
if (!justTheTemplate) {
|
||||||
ide.refreshPalette();
|
receiver.refactorVariableInstances(
|
||||||
},
|
oldName,
|
||||||
this
|
newName,
|
||||||
).prompt(
|
false
|
||||||
'Variable name',
|
);
|
||||||
oldName,
|
receiver.customBlocks.forEach(function (eachBlock) {
|
||||||
this.world(),
|
eachBlock.body.expression.refactorVarInStack(
|
||||||
cpy.fullImage(), // pic
|
oldName,
|
||||||
InputSlotMorph.prototype.getVarNamesDict.call(this)
|
newName
|
||||||
);
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// global var
|
||||||
|
if (!isNil(ide.globalVariables.vars[newName])) {
|
||||||
|
varExistsError();
|
||||||
|
return;
|
||||||
|
} else if (
|
||||||
|
detect(
|
||||||
|
stage.children,
|
||||||
|
function (any) {
|
||||||
|
return any instanceof SpriteMorph &&
|
||||||
|
any.hasSpriteVariable(newName);
|
||||||
|
})
|
||||||
|
) {
|
||||||
|
varExistsError('as a sprite local variable');
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
oldValue = ide.globalVariables.getVar(oldName);
|
||||||
|
stage.deleteVariable(oldName);
|
||||||
|
stage.addVariable(newName, true);
|
||||||
|
ide.globalVariables.setVar(newName, oldValue);
|
||||||
|
|
||||||
|
if (oldWatcher && oldWatcher.isVisible) {
|
||||||
|
newWatcher = receiver.toggleVariableWatcher(
|
||||||
|
newName,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
newWatcher.setPosition(oldWatcher.position());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!justTheTemplate) {
|
||||||
|
stage.refactorVariableInstances(
|
||||||
|
oldName,
|
||||||
|
newName,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
stage.globalBlocks.forEach(function (eachBlock) {
|
||||||
|
eachBlock.body.expression.refactorVarInStack(
|
||||||
|
oldName,
|
||||||
|
newName
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
stage.forAllChildren(function (child) {
|
||||||
|
if (child instanceof SpriteMorph) {
|
||||||
|
child.refactorVariableInstances(
|
||||||
|
oldName,
|
||||||
|
newName,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
child.customBlocks.forEach(
|
||||||
|
function (eachBlock) {
|
||||||
|
eachBlock.body.expression
|
||||||
|
.refactorVarInStack(
|
||||||
|
oldName,
|
||||||
|
newName
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ide.flushBlocksCache('variables');
|
||||||
|
ide.refreshPalette();
|
||||||
|
}
|
||||||
|
|
||||||
function varExistsError (where) {
|
function varExistsError (where) {
|
||||||
ide.inform(
|
ide.inform(
|
||||||
'Variable exists',
|
'Variable exists',
|
||||||
|
|
|
@ -3247,6 +3247,10 @@ http://snap.berkeley.edu/run#cloud:Username=jens&ProjectName=rotation
|
||||||
* Variable refactoring, yay! Thanks, Bernat!!
|
* Variable refactoring, yay! Thanks, Bernat!!
|
||||||
* Threads: fixed #1602
|
* Threads: fixed #1602
|
||||||
|
|
||||||
|
170105
|
||||||
|
------
|
||||||
|
* Blocks: refactored variable refactoring code
|
||||||
|
|
||||||
|
|
||||||
== v4.10 === (in development)
|
== v4.10 === (in development)
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue