mirror of
https://github.com/scratchfoundation/scratch-blocks.git
synced 2025-08-28 22:10:31 -04:00
Merge pull request #1178 from picklesrus/develop-clear-and-load-batch
Add an xml utility to clear the workspace and then load xml into the …
This commit is contained in:
commit
54bf2d6b62
2 changed files with 44 additions and 1 deletions
|
@ -150,6 +150,14 @@ Blockly.WorkspaceSvg.prototype.isMutator = false;
|
|||
*/
|
||||
Blockly.WorkspaceSvg.prototype.resizesEnabled_ = true;
|
||||
|
||||
/**
|
||||
* Whether this workspace has toolbox/flyout refreshes enabled.
|
||||
* Disable during batch operations for a performance improvement.
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
Blockly.WorkspaceSvg.prototype.toolboxRefreshEnabled_ = true;
|
||||
|
||||
/**
|
||||
* Current horizontal scrolling offset in pixel units.
|
||||
* @type {number}
|
||||
|
@ -1004,7 +1012,10 @@ Blockly.WorkspaceSvg.prototype.paste = function(xmlBlock) {
|
|||
* @private
|
||||
*/
|
||||
Blockly.WorkspaceSvg.prototype.refreshToolboxSelection_ = function() {
|
||||
if (this.toolbox_ && this.toolbox_.flyout_ && !this.currentGesture_) {
|
||||
// Updating the toolbox can be expensive. Don't do it when when it is
|
||||
// disabled.
|
||||
if (this.toolbox_ && this.toolbox_.flyout_ && !this.currentGesture_ &&
|
||||
this.toolboxRefreshEnabled_) {
|
||||
this.toolbox_.refreshSelection();
|
||||
}
|
||||
};
|
||||
|
@ -1866,6 +1877,22 @@ Blockly.WorkspaceSvg.prototype.setResizesEnabled = function(enabled) {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Update whether this workspace has toolbox refreshes enabled.
|
||||
* If enabled, the toolbox will refresh when appropriate.
|
||||
* If disabled, workspace will not refresh until re-enabled.
|
||||
* Use to avoid refreshing during a batch operation, for performance.
|
||||
* @param {boolean} enabled Whether refreshes should be enabled.
|
||||
*/
|
||||
Blockly.WorkspaceSvg.prototype.setToolboxRefreshEnabled = function(enabled) {
|
||||
var reenabled = (!this.toolboxRefreshEnabled_ && enabled);
|
||||
this.toolboxRefreshEnabled_ = enabled;
|
||||
if (reenabled) {
|
||||
// Newly enabled. Trigger a refresh.
|
||||
this.refreshToolboxSelection_();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Dispose of all blocks in workspace, with an optimization to prevent resizes.
|
||||
|
|
16
core/xml.js
16
core/xml.js
|
@ -301,6 +301,22 @@ Blockly.Xml.textToDom = function(text) {
|
|||
return dom.firstChild;
|
||||
};
|
||||
|
||||
/**
|
||||
* Clear the given workspace then decode an XML DOM and
|
||||
* create blocks on the workspace.
|
||||
* @param {!Element} xml XML DOM.
|
||||
* @param {!Blockly.Workspace} workspace The workspace.
|
||||
* @return {Array.<string>} An array containing new block ids.
|
||||
*/
|
||||
Blockly.Xml.clearWorkspaceAndLoadFromXml = function(xml, workspace) {
|
||||
workspace.setResizesEnabled(false);
|
||||
workspace.setToolboxRefreshEnabled(false);
|
||||
workspace.clear();
|
||||
var blockIds = Blockly.Xml.domToWorkspace(xml, workspace);
|
||||
workspace.setResizesEnabled(true);
|
||||
workspace.setToolboxRefreshEnabled(true);
|
||||
return blockIds;
|
||||
};
|
||||
/**
|
||||
* Decode an XML DOM and create blocks on the workspace.
|
||||
* @param {!Element} xml XML DOM.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue