Skip to content

Commit

Permalink
Merge pull request #336 from entrylabs/issue/#2512
Browse files Browse the repository at this point in the history
check variable & list name length
  • Loading branch information
chanlee committed Jun 8, 2016
2 parents cd1c784 + d2473a3 commit 21bcdff
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
8 changes: 8 additions & 0 deletions dist/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -13766,6 +13766,7 @@ Entry.VariableContainer.prototype.addVariable = function(b) {
var a = this.variableAddPanel;
b = a.view.name.value.trim();
b && 0 !== b.length || (b = Lang.Workspace.variable);
b.length > this._maxNameLength && (b = this._truncName(b, "variable"));
b = this.checkAllVariableName(b, "variables_") ? Entry.getOrderedName(b, this.variables_, "name_") : b;
var c = a.info;
b = {name:b, isCloud:c.isCloud, object:c.object, variableType:"variable"};
Expand Down Expand Up @@ -13945,6 +13946,7 @@ Entry.VariableContainer.prototype.addList = function(b) {
b = a.view.name.value.trim();
b && 0 !== b.length || (b = Lang.Workspace.list);
var c = a.info;
b.length > this._maxNameLength && (b = this._truncName(b, "list"));
b = this.checkAllVariableName(b, "lists_") ? Entry.getOrderedName(b, this.lists_, "name_") : b;
b = {name:b, isCloud:c.isCloud, object:c.object, variableType:"list"};
a.view.addClass("entryRemove");
Expand Down Expand Up @@ -14619,6 +14621,12 @@ Entry.VariableContainer.prototype.removeRef = function(b, a) {
Entry.VariableContainer.prototype._getBlockMenu = function() {
return Entry.playground.mainWorkspace.getBlockMenu();
};
Entry.VariableContainer.prototype._truncName = function(b, a) {
b = b.substring(0, this._maxNameLength);
Entry.toast.warning(Lang.Workspace[a + "_name_auto_edited_title"], Lang.Workspace[a + "_name_auto_edited_content"]);
return b;
};
Entry.VariableContainer.prototype._maxNameLength = 10;
Entry.block.run = {skeleton:"basic", color:"#3BBD70", contents:["this is", "basic block"], func:function() {
}};
Entry.block.mutant = {skeleton:"basic", event:"start", color:"#3BBD70", template:"test mutant block", params:[], func:function() {
Expand Down
10 changes: 5 additions & 5 deletions dist/entry.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions src/variable_container.js
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,7 @@ Entry.VariableContainer.prototype.checkAllVariableName = function(name,variable)
}
return false;
};

Entry.VariableContainer.prototype.addVariable = function(variable) {
if (!variable) {
var variableContainer = this;
Expand All @@ -780,6 +781,9 @@ Entry.VariableContainer.prototype.addVariable = function(variable) {
if (!name || name.length === 0)
name = Lang.Workspace.variable;

if (name.length > this._maxNameLength)
name = this._truncName(name, 'variable');

name = this.checkAllVariableName(name,'variables_') ? Entry.getOrderedName(name, this.variables_, 'name_') : name;
var info = panel.info;
variable = {
Expand Down Expand Up @@ -1163,6 +1167,10 @@ Entry.VariableContainer.prototype.addList = function(list) {
name = Lang.Workspace.list;

var info = panel.info;

if (name.length > this._maxNameLength)
name = this._truncName(name, 'list');

name = this.checkAllVariableName(name, 'lists_') ? Entry.getOrderedName(name, this.lists_, 'name_') : name;
list = {
name: name,
Expand Down Expand Up @@ -2278,3 +2286,17 @@ Entry.VariableContainer.prototype.removeRef = function(type, block) {
Entry.VariableContainer.prototype._getBlockMenu = function() {
return Entry.playground.mainWorkspace.getBlockMenu();
};

Entry.VariableContainer.prototype._truncName = function(name, type) {
name = name.substring(0, this._maxNameLength);
var title, content;

title = Lang.Workspace[type + '_name_auto_edited_title'];
content = Lang.Workspace[type + '_name_auto_edited_content']

Entry.toast.warning(title, content);

return name;
};

Entry.VariableContainer.prototype._maxNameLength = 10;

0 comments on commit 21bcdff

Please sign in to comment.