Commit dff95fc7 authored by Neil Fraser's avatar Neil Fraser

Allow for mutators with no quarks.

parent 96e130d1
This diff is collapsed.
...@@ -93,9 +93,13 @@ Blockly.Mutator.prototype.createEditor_ = function() { ...@@ -93,9 +93,13 @@ Blockly.Mutator.prototype.createEditor_ = function() {
{'x': Blockly.Bubble.BORDER_WIDTH, 'y': Blockly.Bubble.BORDER_WIDTH}, {'x': Blockly.Bubble.BORDER_WIDTH, 'y': Blockly.Bubble.BORDER_WIDTH},
null); null);
// Convert the list of names into a list of XML objects for the flyout. // Convert the list of names into a list of XML objects for the flyout.
var quarkXml = goog.dom.createDom('xml'); if (this.quarkNames_.length) {
for (var i = 0, quarkName; quarkName = this.quarkNames_[i]; i++) { var quarkXml = goog.dom.createDom('xml');
quarkXml.appendChild(goog.dom.createDom('block', {'type': quarkName})); for (var i = 0, quarkName; quarkName = this.quarkNames_[i]; i++) {
quarkXml.appendChild(goog.dom.createDom('block', {'type': quarkName}));
}
} else {
var quarkXml = null;
} }
var mutator = this; var mutator = this;
var workspaceOptions = { var workspaceOptions = {
...@@ -138,15 +142,17 @@ Blockly.Mutator.prototype.updateEditable = function() { ...@@ -138,15 +142,17 @@ Blockly.Mutator.prototype.updateEditable = function() {
Blockly.Mutator.prototype.resizeBubble_ = function() { Blockly.Mutator.prototype.resizeBubble_ = function() {
var doubleBorderWidth = 2 * Blockly.Bubble.BORDER_WIDTH; var doubleBorderWidth = 2 * Blockly.Bubble.BORDER_WIDTH;
var workspaceSize = this.workspace_.getCanvas().getBBox(); var workspaceSize = this.workspace_.getCanvas().getBBox();
var flyoutMetrics = this.workspace_.flyout_.getMetrics_();
var width; var width;
if (this.block_.RTL) { if (this.block_.RTL) {
width = -workspaceSize.x; width = -workspaceSize.x;
} else { } else {
width = workspaceSize.width + workspaceSize.x; width = workspaceSize.width + workspaceSize.x;
} }
var height = Math.max(workspaceSize.height + doubleBorderWidth * 3, var height = workspaceSize.height + doubleBorderWidth * 3;
flyoutMetrics.contentHeight + 20); if (this.workspace_.flyout_) {
var flyoutMetrics = this.workspace_.flyout_.getMetrics_();
height = Math.max(height, flyoutMetrics.contentHeight + 20);
}
width += doubleBorderWidth * 3; width += doubleBorderWidth * 3;
// Only resize if the size difference is significant. Eliminates shuddering. // Only resize if the size difference is significant. Eliminates shuddering.
if (Math.abs(this.workspaceWidth_ - width) > doubleBorderWidth || if (Math.abs(this.workspaceWidth_ - width) > doubleBorderWidth ||
...@@ -184,9 +190,11 @@ Blockly.Mutator.prototype.setVisible = function(visible) { ...@@ -184,9 +190,11 @@ Blockly.Mutator.prototype.setVisible = function(visible) {
this.createEditor_(), this.block_.svgPath_, this.createEditor_(), this.block_.svgPath_,
this.iconX_, this.iconY_, null, null); this.iconX_, this.iconY_, null, null);
var thisObj = this; var thisObj = this;
this.workspace_.flyout_.init(this.workspace_); var tree = this.workspace_.options.languageTree;
this.workspace_.flyout_.show( if (tree) {
this.workspace_.options.languageTree.childNodes); this.workspace_.flyout_.init(this.workspace_);
this.workspace_.flyout_.show(tree.childNodes);
}
this.rootBlock_ = this.block_.decompose(this.workspace_); this.rootBlock_ = this.block_.decompose(this.workspace_);
var blocks = this.rootBlock_.getDescendants(); var blocks = this.rootBlock_.getDescendants();
...@@ -196,8 +204,13 @@ Blockly.Mutator.prototype.setVisible = function(visible) { ...@@ -196,8 +204,13 @@ Blockly.Mutator.prototype.setVisible = function(visible) {
// The root block should not be dragable or deletable. // The root block should not be dragable or deletable.
this.rootBlock_.setMovable(false); this.rootBlock_.setMovable(false);
this.rootBlock_.setDeletable(false); this.rootBlock_.setDeletable(false);
var margin = this.workspace_.flyout_.CORNER_RADIUS * 2; if (this.workspace_.flyout_) {
var x = this.workspace_.flyout_.width_ + margin; var margin = this.workspace_.flyout_.CORNER_RADIUS * 2;
var x = this.workspace_.flyout_.width_ + margin;
} else {
var margin = 16;
var x = margin;
}
if (this.block_.RTL) { if (this.block_.RTL) {
x = -x; x = -x;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment