mirror of
https://github.com/scratchfoundation/scratch-blocks.git
synced 2025-06-16 23:30:20 -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;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* 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);
|
||||
};
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @private
|
||||
|
@ -690,7 +706,7 @@ Blockly.Flyout.prototype.clearOldBlocks_ = function() {
|
|||
var oldBlocks = this.workspace_.getTopBlocks(false);
|
||||
for (var i = 0, block; block = oldBlocks[i]; i++) {
|
||||
if (block.workspace == this.workspace_) {
|
||||
if (block.isRecyclable()) {
|
||||
if (this.recyclingEnabled_ && block.isRecyclable()) {
|
||||
this.recycleBlock_(block);
|
||||
} else {
|
||||
block.dispose(false, false);
|
||||
|
|
|
@ -306,9 +306,11 @@
|
|||
}
|
||||
|
||||
function setLocale(locale) {
|
||||
workspace.getFlyout().setRecyclingEnabled(false);
|
||||
var xml = Blockly.Xml.workspaceToDom(workspace);
|
||||
Blockly.ScratchMsgs.setLocale(locale);
|
||||
Blockly.Xml.clearWorkspaceAndLoadFromXml(xml, workspace);
|
||||
workspace.getFlyout().setRecyclingEnabled(true);
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
|
@ -349,9 +349,11 @@
|
|||
}
|
||||
|
||||
function setLocale(locale) {
|
||||
workspace.getFlyout().setRecyclingEnabled(false);
|
||||
var xml = Blockly.Xml.workspaceToDom(workspace);
|
||||
Blockly.ScratchMsgs.setLocale(locale);
|
||||
Blockly.Xml.clearWorkspaceAndLoadFromXml(xml, workspace);
|
||||
workspace.getFlyout().setRecyclingEnabled(true);
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue