mirror of
https://github.com/scratchfoundation/scratch-blocks.git
synced 2025-07-02 23:20:25 -04:00
Add flag to not recycle flyout blocks when switching languages
Fixes #1570
This commit is contained in:
parent
013e1ccf28
commit
ceacff64be
3 changed files with 21 additions and 1 deletions
|
@ -264,6 +264,14 @@ Blockly.Flyout.prototype.dragAngleRange_ = 70;
|
||||||
*/
|
*/
|
||||||
Blockly.Flyout.prototype.scrollAnimationFraction = 0.3;
|
Blockly.Flyout.prototype.scrollAnimationFraction = 0.3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to recycle blocks when refreshing the flyout. Nothing can be
|
||||||
|
* recycled when the locale changes.
|
||||||
|
* @type {boolean}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
Blockly.Flyout.prototype.recyclingEnabled_ = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the flyout's DOM. Only needs to be called once. The flyout can
|
* Creates the flyout's DOM. Only needs to be called once. The flyout can
|
||||||
* either exist as its own svg element or be a g element nested inside a
|
* either exist as its own svg element or be a g element nested inside a
|
||||||
|
@ -681,6 +689,14 @@ Blockly.Flyout.prototype.setScrollPos = function(pos) {
|
||||||
this.scrollbar_.set(pos * this.workspace_.scale);
|
this.scrollbar_.set(pos * this.workspace_.scale);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set whether the flyout can recycle blocks. A value of true allows blocks to be recycled.
|
||||||
|
* @param {boolean} recycle True if recycling is possible.
|
||||||
|
*/
|
||||||
|
Blockly.Flyout.prototype.setRecyclingEnabled = function(recycle) {
|
||||||
|
this.recyclingEnabled_ = recycle;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete blocks and background buttons from a previous showing of the flyout.
|
* Delete blocks and background buttons from a previous showing of the flyout.
|
||||||
* @private
|
* @private
|
||||||
|
@ -690,7 +706,7 @@ Blockly.Flyout.prototype.clearOldBlocks_ = function() {
|
||||||
var oldBlocks = this.workspace_.getTopBlocks(false);
|
var oldBlocks = this.workspace_.getTopBlocks(false);
|
||||||
for (var i = 0, block; block = oldBlocks[i]; i++) {
|
for (var i = 0, block; block = oldBlocks[i]; i++) {
|
||||||
if (block.workspace == this.workspace_) {
|
if (block.workspace == this.workspace_) {
|
||||||
if (block.isRecyclable()) {
|
if (this.recyclingEnabled_ && block.isRecyclable()) {
|
||||||
this.recycleBlock_(block);
|
this.recycleBlock_(block);
|
||||||
} else {
|
} else {
|
||||||
block.dispose(false, false);
|
block.dispose(false, false);
|
||||||
|
|
|
@ -306,9 +306,11 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function setLocale(locale) {
|
function setLocale(locale) {
|
||||||
|
workspace.getFlyout().setRecyclingEnabled(false);
|
||||||
var xml = Blockly.Xml.workspaceToDom(workspace);
|
var xml = Blockly.Xml.workspaceToDom(workspace);
|
||||||
Blockly.ScratchMsgs.setLocale(locale);
|
Blockly.ScratchMsgs.setLocale(locale);
|
||||||
Blockly.Xml.clearWorkspaceAndLoadFromXml(xml, workspace);
|
Blockly.Xml.clearWorkspaceAndLoadFromXml(xml, workspace);
|
||||||
|
workspace.getFlyout().setRecyclingEnabled(true);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -349,9 +349,11 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function setLocale(locale) {
|
function setLocale(locale) {
|
||||||
|
workspace.getFlyout().setRecyclingEnabled(false);
|
||||||
var xml = Blockly.Xml.workspaceToDom(workspace);
|
var xml = Blockly.Xml.workspaceToDom(workspace);
|
||||||
Blockly.ScratchMsgs.setLocale(locale);
|
Blockly.ScratchMsgs.setLocale(locale);
|
||||||
Blockly.Xml.clearWorkspaceAndLoadFromXml(xml, workspace);
|
Blockly.Xml.clearWorkspaceAndLoadFromXml(xml, workspace);
|
||||||
|
workspace.getFlyout().setRecyclingEnabled(true);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue