Dropdown menu categories ()

* add getter for category

* set dropdown's data-category to parent block's category

* remove unused parameter
This commit is contained in:
Airhogs777 2016-10-03 06:17:45 -06:00 committed by Tim Mickel
parent bac07dc65a
commit d00c2942e4
7 changed files with 33 additions and 5 deletions

View file

@ -132,6 +132,12 @@ Blockly.Block = function(workspace, prototypeName, opt_id) {
* @private
*/
this.outputShape_ = null;
/**
* @type {?string}
* @private
*/
this.category_ = null;
/**
* @type {!goog.math.Coordinate}
@ -1472,7 +1478,15 @@ Blockly.Block.prototype.getOutputShape = function() {
* @param {?string} category The block's category (see constants.js).
*/
Blockly.Block.prototype.setCategory = function(category) {
this.category = category;
this.category_ = category;
};
/**
* Get this block's category (for styling purposes)
* @return {?string} category The block's category (see constants.js).
*/
Blockly.Block.prototype.getCategory = function() {
return this.category_;
};
/**

View file

@ -631,8 +631,8 @@ Blockly.BlockSvg.prototype.renderClassify_ = function(metrics) {
this.svgGroup_.setAttribute('data-shapes', shapes.join(' '));
if (this.category) {
this.svgGroup_.setAttribute('data-category', this.category);
if (this.getCategory()) {
this.svgGroup_.setAttribute('data-category', this.getCategory());
}
};

View file

@ -1020,8 +1020,8 @@ Blockly.BlockSvg.prototype.renderClassify_ = function() {
this.svgGroup_.setAttribute('data-shapes', shapes.join(' '));
if (this.category) {
this.svgGroup_.setAttribute('data-category', this.category);
if (this.getCategory()) {
this.svgGroup_.setAttribute('data-category', this.getCategory());
}
};

View file

@ -163,6 +163,14 @@ Blockly.DropDownDiv.setColour = function(backgroundColour, borderColour) {
Blockly.DropDownDiv.DIV_.style.borderColor = borderColour;
};
/**
* Set the category for the drop-down.
* @param {string} category The new category for the drop-down.
*/
Blockly.DropDownDiv.setCategory = function(category) {
Blockly.DropDownDiv.DIV_.setAttribute('data-category', category);
};
/**
* Shortcut to show and place the drop-down with positioning determined
* by a particular block. The primary position will be below the block,

View file

@ -170,6 +170,7 @@ Blockly.FieldAngle.prototype.showEditor_ = function() {
Blockly.DropDownDiv.setColour(this.sourceBlock_.parentBlock_.getColour(),
this.sourceBlock_.getColourTertiary());
Blockly.DropDownDiv.setCategory(this.sourceBlock_.parentBlock_.getCategory());
Blockly.DropDownDiv.showPositionedByBlock(this, this.sourceBlock_);
this.clickWrapper_ =

View file

@ -192,6 +192,10 @@ Blockly.FieldDropdown.prototype.showEditor_ = function() {
this.sourceBlock_.parentBlock_.getColour() : this.sourceBlock_.getColour();
Blockly.DropDownDiv.setColour(primaryColour, this.sourceBlock_.getColourTertiary());
var category = (this.sourceBlock_.isShadow()) ?
this.sourceBlock_.parentBlock_.getCategory() : this.sourceBlock_.getCategory();
Blockly.DropDownDiv.setCategory(category);
// Calculate positioning based on the field position.
var scale = this.sourceBlock_.workspace.scale;

View file

@ -234,6 +234,7 @@ Blockly.FieldIconMenu.prototype.showEditor_ = function() {
contentDiv.style.width = Blockly.FieldIconMenu.DROPDOWN_WIDTH + 'px';
Blockly.DropDownDiv.setColour(this.sourceBlock_.getColour(), this.sourceBlock_.getColourTertiary());
Blockly.DropDownDiv.setCategory(this.sourceBlock_.parentBlock_.getCategory());
// Update source block colour to look selected
this.savedPrimary_ = this.sourceBlock_.getColour();