Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Text Dropdowns" (ScratchBlocks part) #13

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 63 additions & 15 deletions core/field_textdropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,29 @@ Blockly.FieldTextDropdown.fromJson = function(element) {
return field;
};

/**
* Horizontal distance that a checkmark overhangs the dropdown.
*/
Blockly.FieldTextDropdown.CHECKMARK_OVERHANG = Blockly.FieldDropdown.CHECKMARK_OVERHANG;

/**
* Mouse cursor style when over the hotspot that initiates the editor.
*/
Blockly.FieldTextDropdown.prototype.CURSOR = Blockly.FieldTextInput.prototype.CURSOR;

/**
* Closure menu item currently selected.
* @type {?goog.ui.MenuItem}
*/
Blockly.FieldTextDropdown.prototype.selectedItem = Blockly.FieldDropdown.prototype.selectedItem;

/**
* Language-neutral currently selected string or image object.
* @type {string|!Object}
* @private
*/
Blockly.FieldTextDropdown.prototype.value_ = Blockly.FieldDropdown.prototype.value_;

/**
* Install this text drop-down field on a block.
*/
Expand Down Expand Up @@ -106,18 +129,6 @@ Blockly.FieldTextDropdown.prototype.init = function() {
this.disableColourChange_ = true;
};

/**
* Close the input widget if this input is being deleted.
*/
Blockly.FieldTextDropdown.prototype.dispose = function() {
if (this.mouseUpWrapper_) {
Blockly.unbindEvent_(this.mouseUpWrapper_);
this.mouseUpWrapper_ = null;
Blockly.Touch.clearTouchIdentifier();
}
Blockly.FieldTextDropdown.superClass_.dispose.call(this);
};

/**
* If the drop-down isn't open, show the text editor.
*/
Expand All @@ -133,14 +144,44 @@ Blockly.FieldTextDropdown.prototype.showEditor_ = function() {
}
};

/**
* Callback when the drop-down menu is hidden.
*/
Blockly.FieldTextDropdown.prototype.onHide = Blockly.FieldDropdown.prototype.onHide;

/**
* Handle the selection of an item in the dropdown menu.
* @param {!goog.ui.Menu} menu The Menu component clicked.
* @param {!goog.ui.MenuItem} menuItem The MenuItem selected within menu.
*/
Blockly.FieldTextDropdown.prototype.onItemSelected = Blockly.FieldDropdown.prototype.onItemSelected;

/**
* Return a list of the options for this dropdown.
* See: Blockly.FieldDropDown.prototype.getOptions_.
* @return {!Array.<!Array.<string>>} Array of option tuples:
* (human-readable text, language-neutral name).
* @private
*/
Blockly.FieldTextDropdown.prototype.getOptions_ = Blockly.FieldDropdown.prototype.getOptions_;
Blockly.FieldTextDropdown.prototype.getOptions = Blockly.FieldDropdown.prototype.getOptions;

/**
* Get the language-neutral value from this dropdown menu.
* @return {string} Current text.
*/
Blockly.FieldTextDropdown.prototype.getValue = Blockly.FieldDropdown.prototype.getValue;

/**
* Set the language-neutral value for this dropdown menu.
* @param {string} newValue New value to set.
*/
Blockly.FieldTextDropdown.prototype.setValue = Blockly.FieldDropdown.prototype.setValue;

/**
* @return {boolean} True if the option list is generated by a function.
* Otherwise false.
*/
Blockly.FieldTextDropdown.prototype.isOptionListDynamic = Blockly.FieldDropdown.prototype.isOptionListDynamic;

/**
* Position a drop-down arrow at the appropriate location at render-time.
Expand All @@ -157,8 +198,15 @@ Blockly.FieldTextDropdown.prototype.positionArrow = Blockly.FieldDropdown.protot
Blockly.FieldTextDropdown.prototype.showDropdown_ = Blockly.FieldDropdown.prototype.showEditor_;

/**
* Callback when the drop-down menu is hidden.
* Close the input widget if this input is being deleted.
*/
Blockly.FieldTextDropdown.prototype.onHide = Blockly.FieldDropdown.prototype.onHide;
Blockly.FieldTextDropdown.prototype.dispose = function() {
if (this.mouseUpWrapper_) {
Blockly.unbindEvent_(this.mouseUpWrapper_);
this.mouseUpWrapper_ = null;
Blockly.Touch.clearTouchIdentifier();
}
Blockly.FieldTextDropdown.superClass_.dispose.call(this);
};

Blockly.Field.register('field_textdropdown', Blockly.FieldTextDropdown);