Skip to content

Assign variable UUID to field_variable dropdown.#1096

Merged
marisaleung merged 1 commit intoRaspberryPiFoundation:developfrom
marisaleung:develop
May 15, 2017
Merged

Assign variable UUID to field_variable dropdown.#1096
marisaleung merged 1 commit intoRaspberryPiFoundation:developfrom
marisaleung:develop

Conversation

@marisaleung
Copy link
Copy Markdown
Contributor

@marisaleung marisaleung commented May 10, 2017

  • Added static ID's for "Rename variable" and "Delete variable".
  • Set the internal representation of a variable to its UUID
  • Adjusted "FieldVariable.prototype.onItemSelected()" to use the UUID to extract the variable name.

This change is Reviewable

goog.require('goog.asserts');
goog.require('goog.string');

var RENAME_VARIABLE_ID = 'RENAME_VARIABLE';
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More seriously, these should probably be constants in Blockly.Constants, and they should definitely have 'ID' in the text.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference, this is my fault and you should listen to Rachel.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hahahaha I love this X).

Done (listened to Rachel.)

@@ -177,10 +164,14 @@ Blockly.FieldVariable.dropdownCreate = function() {
*/
Blockly.FieldVariable.prototype.onItemSelected = function(menu, menuItem) {
var itemText = menuItem.getValue();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

itemText feels overloaded now. On line 166 (on the right) it's the ID, not the text. But on line 172 it's the text.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I'm setting it to id for now.
In the next CL I will change field_variable's setValue() to take in an id since all items are now ids. Then we can get rid of itemText.

@marisaleung marisaleung force-pushed the develop branch 3 times, most recently from d984d6b to b438c69 Compare May 11, 2017 00:29
Copy link
Copy Markdown
Collaborator

@rachel-fenichel rachel-fenichel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few small changes but generally looks good.

* variable...' and if selected, should trigger the prompt to rename a variable.
* @const {string}
*/
Blockly.RENAME_VARIABLE_ID = 'RENAME_VARIABLE';
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this 'RENAME_VARIABLE_ID', and 'DELETE_VARIABLE_ID'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

* @param {Blockly.VariableModel} var1 First variable to compare.
* @param {Blockly.VariableModel} var2 Second variable to compare.
*/
Blockly.VariableModel.prototype.compareByName = function(var1, var2) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can put this on Blockly.VariableModel instead of Blockly.VariableModel.prototype.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

// Call any validation function, and allow it to override.
itemText = this.callValidator(itemText);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you decide that validators don't make sense in the context of a variable dropdown?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the call does nothing. And the text comes directly from the variable itself so I can't imagine an instance in which a validator would be needed/useful.

@marisaleung marisaleung force-pushed the develop branch 3 times, most recently from 4d4109e to b7932f9 Compare May 11, 2017 18:02
@RoboErikG
Copy link
Copy Markdown
Contributor

Review status: 0 of 4 files reviewed at latest revision, 3 unresolved discussions.


core/variable_model.js, line 84 at r2 (raw file):

 */
Blockly.VariableModel.compareByName = function(var1, var2) {
  if (var1.name < var2.name) {

This lost the case insensitive part. Check with Rachel if you're safe to use goog.string.caseInsensitiveCompare(var1.name, var2.name) and if not first convert both names to lowercase before comparing.


Comments from Reviewable

@marisaleung
Copy link
Copy Markdown
Contributor Author

Review status: 0 of 4 files reviewed at latest revision, 3 unresolved discussions.


core/variable_model.js, line 84 at r2 (raw file):

Previously, RoboErikG wrote…

This lost the case insensitive part. Check with Rachel if you're safe to use goog.string.caseInsensitiveCompare(var1.name, var2.name) and if not first convert both names to lowercase before comparing.

Done.


Comments from Reviewable

@RoboErikG
Copy link
Copy Markdown
Contributor

:lgtm: if Rachel's happy.


Review status: 0 of 4 files reviewed at latest revision, 3 unresolved discussions.


Comments from Reviewable

@rachel-fenichel
Copy link
Copy Markdown
Collaborator

Review status: 0 of 4 files reviewed at latest revision, 4 unresolved discussions.


core/field_variable.js, line 135 at r3 (raw file):

    var variableModelList = workspace.getVariablesOfType('');
    for (var i = 0; i < variableModelList.length; i++){
      if (createSelectedVariable && variableModelList[i].name == name) {

This comparison should be case-insensitive.


Comments from Reviewable

@marisaleung
Copy link
Copy Markdown
Contributor Author

From Rachel:

lgtm

@marisaleung
Copy link
Copy Markdown
Contributor Author

Review status: 0 of 4 files reviewed at latest revision, 4 unresolved discussions.


core/field_variable.js, line 135 at r3 (raw file):

Previously, rachel-fenichel (Rachel Fenichel) wrote…

This comparison should be case-insensitive.

Done.


Comments from Reviewable

@marisaleung marisaleung merged commit 8d5edb3 into RaspberryPiFoundation:develop May 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants