From 70f42b3395ad23b19f88dfc8d945e40bcfb343c1 Mon Sep 17 00:00:00 2001 From: Sam El-Husseini Date: Tue, 21 Jan 2020 13:29:03 -0800 Subject: [PATCH] Fix parsing and passing of workspace options around Blockly (#3616) --- core/mutator.js | 19 +++++++++---------- core/options.js | 2 +- core/toolbox.js | 13 +++++++------ core/trashcan.js | 10 +++++----- core/workspace_svg.js | 12 ++++++------ 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/core/mutator.js b/core/mutator.js index dcab958e4..0d2e31f7b 100644 --- a/core/mutator.js +++ b/core/mutator.js @@ -166,18 +166,17 @@ Blockly.Mutator.prototype.createEditor_ = function() { ({ // If you want to enable disabling, also remove the // event filter from workspaceChanged_ . - disable: false, - languageTree: quarkXml, - parentWorkspace: this.block_.workspace, - pathToMedia: this.block_.workspace.options.pathToMedia, - RTL: this.block_.RTL, - toolboxPosition: this.block_.RTL ? Blockly.TOOLBOX_AT_RIGHT : + 'disable': false, + 'parentWorkspace': this.block_.workspace, + 'media': this.block_.workspace.options.pathToMedia, + 'rtl': this.block_.RTL, + 'toolboxPosition': this.block_.RTL ? Blockly.TOOLBOX_AT_RIGHT : Blockly.TOOLBOX_AT_LEFT, - horizontalLayout: false, - getMetrics: this.getFlyoutMetrics_.bind(this), - setMetrics: null, - renderer: this.block_.workspace.options.renderer + 'horizontalLayout': false, + 'renderer': this.block_.workspace.options.renderer })); + workspaceOptions.languageTree = quarkXml; + workspaceOptions.getMetrics = this.getFlyoutMetrics_.bind(this); this.workspace_ = new Blockly.WorkspaceSvg(workspaceOptions); this.workspace_.isMutator = true; this.workspace_.addChangeListener(Blockly.Events.disableOrphans); diff --git a/core/options.js b/core/options.js index 80550b463..cf0d8dba2 100644 --- a/core/options.js +++ b/core/options.js @@ -155,7 +155,7 @@ Blockly.Options = function(options) { * workspace. * @type {Blockly.Workspace} */ - this.parentWorkspace = null; + this.parentWorkspace = options['parentWorkspace']; }; /** diff --git a/core/toolbox.js b/core/toolbox.js index 71dfd7b38..5cfbef845 100644 --- a/core/toolbox.js +++ b/core/toolbox.js @@ -182,13 +182,14 @@ Blockly.Toolbox.prototype.init = function() { var workspaceOptions = new Blockly.Options( /** @type {!Blockly.BlocklyOptions} */ ({ - parentWorkspace: workspace, - RTL: workspace.RTL, - oneBasedIndex: workspace.options.oneBasedIndex, - horizontalLayout: workspace.horizontalLayout, - toolboxPosition: workspace.options.toolboxPosition, - renderer: workspace.options.renderer + 'parentWorkspace': workspace, + 'rtl': workspace.RTL, + 'oneBasedIndex': workspace.options.oneBasedIndex, + 'horizontalLayout': workspace.horizontalLayout, + 'toolboxPosition': workspace.options.toolboxPosition, + 'renderer': workspace.options.renderer })); + if (workspace.horizontalLayout) { if (!Blockly.HorizontalFlyout) { throw Error('Missing require for Blockly.HorizontalFlyout'); diff --git a/core/trashcan.js b/core/trashcan.js index bccae73e3..fde748787 100644 --- a/core/trashcan.js +++ b/core/trashcan.js @@ -63,11 +63,11 @@ Blockly.Trashcan = function(workspace) { var flyoutWorkspaceOptions = new Blockly.Options( /** @type {!Blockly.BlocklyOptions} */ ({ - scrollbars: true, - parentWorkspace: this.workspace_, - RTL: this.workspace_.RTL, - oneBasedIndex: this.workspace_.options.oneBasedIndex, - renderer: this.workspace_.options.renderer + 'scrollbars': true, + 'parentWorkspace': this.workspace_, + 'rtl': this.workspace_.RTL, + 'oneBasedIndex': this.workspace_.options.oneBasedIndex, + 'renderer': this.workspace_.options.renderer })); // Create vertical or horizontal flyout. if (this.workspace_.horizontalLayout) { diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 8b53e1112..e0eb6b7e6 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -895,12 +895,12 @@ Blockly.WorkspaceSvg.prototype.addFlyout = function(tagName) { var workspaceOptions = new Blockly.Options( /** @type {!Blockly.BlocklyOptions} */ ({ - parentWorkspace: this, - RTL: this.RTL, - oneBasedIndex: this.options.oneBasedIndex, - horizontalLayout: this.horizontalLayout, - toolboxPosition: this.options.toolboxPosition, - renderer: this.options.renderer + 'parentWorkspace': this, + 'rtl': this.RTL, + 'oneBasedIndex': this.options.oneBasedIndex, + 'horizontalLayout': this.horizontalLayout, + 'toolboxPosition': this.options.toolboxPosition, + 'renderer': this.options.renderer })); if (this.horizontalLayout) { if (!Blockly.HorizontalFlyout) {