diff --git a/dist/entry.js b/dist/entry.js index 9110b1da2c..be9d8b0624 100644 --- a/dist/entry.js +++ b/dist/entry.js @@ -10833,9 +10833,10 @@ Entry.Scene.prototype.generateElement = function(b) { } Entry.Utils.disableContextmenu(c); $(c).on("contextmenu", function() { - Entry.ContextMenu.show([{text:Lang.Workspace.duplicate_scene, callback:function() { + var a = [{text:Lang.Workspace.duplicate_scene, enable:Entry.engine.isState("stop"), callback:function() { Entry.scene.cloneScene(b); - }}], "workspace-contextmenu"); + }}]; + Entry.ContextMenu.show(a, "workspace-contextmenu"); }); return b.view = c; }; @@ -13760,6 +13761,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"}; @@ -13868,6 +13870,7 @@ Entry.VariableContainer.prototype.addMessage = function(b) { this.messages_.unshift(b); Entry.playground.reloadPlayground(); this.updateList(); + b.listElement.nameField.focus(); return new Entry.State(this, this.removeMessage, b); }; Entry.VariableContainer.prototype.removeMessage = function(b) { @@ -13938,6 +13941,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"); @@ -14612,6 +14616,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() { @@ -16925,16 +16935,14 @@ Entry.Utils.inherit(Entry.Field, Entry.FieldDropdown); b._position = function() { var a = this.getAbsolutePosFromDocument(); a.y += this.box.height / 2; - var b = $(document).height(), d = this.optionGroup.height(), e = this.optionGroup.width(); - if (b < a.y + d) { - a.x += this.box.width + 1; - var b = this.getAbsolutePosFromBoard(), f = this._blockView.getBoard().svgDom.height(), f = f - (f - b.y); - f - 20 < d && this.optionGroup.height(f - f % 20); - a.y -= this.optionGroup.height(); + var b = $(document).height(), d = this.optionGroup.height(), e = this.optionGroup.width() + 20; + if (b < a.y + d + 30) { + var b = this._blockView.getBoard().svgDom.height(), f = this.getAbsolutePosFromBoard(); + this._blockView.y < b / 2 ? (a.x += this.box.width / 2 - e / 2, b -= f.y + 30, this.optionGroup.height(b)) : (a.x += this.box.width + 1, b -= b - f.y, b - 30 < d && this.optionGroup.height(b - b % 30), a.y -= this.optionGroup.height()); } else { a.x += this.box.width / 2 - e / 2; } - this.optionGroup.css({left:a.x, top:a.y, width:e + 20}); + this.optionGroup.css({left:a.x, top:a.y, width:e}); }; b.applyValue = function(a) { this.value != a && this.setValue(a); diff --git a/dist/entry.min.js b/dist/entry.min.js index d6431e0056..abfa5a64c5 100644 --- a/dist/entry.min.js +++ b/dist/entry.min.js @@ -1045,8 +1045,8 @@ h.trigger("mousedown"))});var d=Entry.createElement("ul");d.addClass("entryScene d.bindOnClick(function(a){Entry.engine.isState("run")||Entry.scene.addScene()}),this.view_.appendChild(d),this.addButton_=d)}}; Entry.Scene.prototype.generateElement=function(b){var a=this,c=Entry.createElement("li",b.id);c.addClass("entrySceneElementWorkspace");c.addClass("entrySceneButtonWorkspace");c.addClass("minValue");$(c).on("mousedown",function(a){Entry.engine.isState("run")?a.preventDefault():Entry.scene.selectScene(b)});var d=Entry.createElement("input");d.addClass("entrySceneFieldWorkspace");d.value=b.name;Entry.sceneEditable||(d.disabled="disabled");var e=Entry.createElement("span");e.addClass("entrySceneLeftWorkspace"); c.appendChild(e);var f=Entry.createElement("span");f.addClass("entrySceneInputCover");f.style.width=Entry.computeInputWidth(b.name);c.appendChild(f);b.inputWrapper=f;d.onkeyup=function(c){c=c.keyCode;Entry.isArrowOrBackspace(c)||(b.name=this.value,f.style.width=Entry.computeInputWidth(b.name),a.resize(),13==c&&this.blur(),9this._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"};a.view.addClass("entryRemove");this.resetVariableAddPanel("variable")}b=new Entry.Variable(b);Entry.stateManager&& +Entry.stateManager.addCommand("add variable",this,this.removeVariable,b);b.generateView(this.variables_.length);this.createVariableView(b);this.variables_.unshift(b);Entry.playground.reloadPlayground();this.updateList();return new Entry.State(this,this.removeVariable,b)}; Entry.VariableContainer.prototype.removeVariable=function(b){var a=this.variables_.indexOf(b),c=b.toJSON();this.selected==b&&this.select(null);b.remove();this.variables_.splice(a,1);Entry.stateManager&&Entry.stateManager.addCommand("remove variable",this,this.addVariable,c);Entry.playground.reloadPlayground();this.updateList();return new Entry.State(this,this.addVariable,c)}; Entry.VariableContainer.prototype.changeVariableName=function(b,a){b.name_!=a&&(Entry.isExist(a,"name_",this.variables_)?(b.listElement.nameField.value=b.name_,Entry.toast.alert(Lang.Workspace.variable_rename_failed,Lang.Workspace.variable_dup)):10this._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");this.resetVariableAddPanel("list")}b=new Entry.Variable(b);Entry.stateManager&&Entry.stateManager.addCommand("add list", +this,this.removeList,b);b.generateView(this.lists_.length);this.createListView(b);this.lists_.unshift(b);Entry.playground.reloadPlayground();this.updateList();return new Entry.State(this,this.removelist,b)}; Entry.VariableContainer.prototype.createListView=function(b){var a=this,c=Entry.createElement("li"),d=Entry.createElement("div");d.addClass("entryVariableListElementWrapperWorkspace");c.appendChild(d);c.addClass("entryVariableListElementWorkspace");b.object_?c.addClass("entryListLocalElementWorkspace"):b.isCloud_?c.addClass("entryListCloudElementWorkspace"):c.addClass("entryListGlobalElementWorkspace");c.bindOnClick(function(c){a.select(b)});var e=Entry.createElement("button");e.addClass("entryVariableListElementDeleteWorkspace"); e.bindOnClick(function(c){c.stopPropagation();a.removeList(b);a.selectedList=null;a.listSettingView.addClass("entryRemove")});var f=Entry.createElement("button");f.addClass("entryVariableListElementEditWorkspace");f.bindOnClick(function(c){c.stopPropagation();h.removeAttribute("disabled");g.removeClass("entryRemove");this.addClass("entryRemove");a.updateSelectedVariable(b);h.focus()});c.editButton=f;var g=Entry.createElement("button");g.addClass("entryVariableListElementEditWorkspace");g.addClass("entryRemove"); g.bindOnClick(function(c){c.stopPropagation();h.blur();h.setAttribute("disabled","disabled");f.removeClass("entryRemove");this.addClass("entryRemove");a.select(b);a.updateSelectedVariable(null,"list")});c.editSaveButton=g;var h=Entry.createElement("input");h.setAttribute("disabled","disabled");h.addClass("entryVariableListElementNameWorkspace");h.value=b.name_;h.bindOnClick(function(a){a.stopPropagation()});h.onblur=function(c){(c=this.value.trim())&&0!==c.length?a.changeListName(b,this.value):(Entry.toast.alert(Lang.Msgs.warn, @@ -1334,7 +1334,7 @@ Entry.VariableContainer.prototype.updateCloudVariables=function(){var b=Entry.pr Entry.VariableContainer.prototype.addRef=function(b,a){if(this.view_&&Entry.playground.mainWorkspace.getMode()===Entry.Workspace.MODE_BOARD){var c={object:a.getCode().object,block:a};a.funcBlock&&(c.funcBlock=a.funcBlock,delete a.funcBlock);this[b].push(c);if("_functionRefs"==b)for(var d=a.type.substr(5),e=Entry.variableContainer.functions_[d].content.getBlockList(),f=0;f this._maxNameLength) + name = this._truncName(name, 'variable'); + name = this.checkAllVariableName(name,'variables_') ? Entry.getOrderedName(name, this.variables_, 'name_') : name; var info = panel.info; variable = { @@ -1023,6 +1027,7 @@ Entry.VariableContainer.prototype.addMessage = function(message) { this.messages_.unshift(message); Entry.playground.reloadPlayground(); this.updateList(); + message.listElement.nameField.focus(); return new Entry.State(this, this.removeMessage, message); @@ -1162,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, @@ -2277,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; diff --git a/src/workspace/field/dropdown.js b/src/workspace/field/dropdown.js index b33f14c48a..5cc6b6034b 100644 --- a/src/workspace/field/dropdown.js +++ b/src/workspace/field/dropdown.js @@ -193,27 +193,36 @@ Entry.Utils.inherit(Entry.Field, Entry.FieldDropdown); var documentHeight = $(document).height(); var optionGroupHeight = this.optionGroup.height(); - var optionGroupWidth = this.optionGroup.width(); + var optionGroupWidth = this.optionGroup.width() + 20; //not enough space below - if (documentHeight < pos.y + optionGroupHeight) { - pos.x += this.box.width + 1; - - var relPos = this.getAbsolutePosFromBoard(); + if (documentHeight < pos.y + optionGroupHeight + 30) { var domHeight = this._blockView.getBoard().svgDom.height(); - domHeight -= domHeight - relPos.y; + var relPos = this.getAbsolutePosFromBoard(); + //above the half of dom + if (this._blockView.y < domHeight/2) { + pos.x += this.box.width/2 - optionGroupWidth/2; - if (domHeight - 20 < optionGroupHeight) { - domHeight -= domHeight % 20; + domHeight -= relPos.y + 30; this.optionGroup.height(domHeight) - } + } else { + pos.x += this.box.width + 1; - pos.y -= this.optionGroup.height(); + domHeight -= domHeight - relPos.y; + + if (domHeight - 30 < optionGroupHeight) { + domHeight -= domHeight % 30; + this.optionGroup.height(domHeight) + } + + pos.y -= this.optionGroup.height(); + + } } else pos.x += this.box.width/2 - optionGroupWidth/2; this.optionGroup.css({ left: pos.x, top: pos.y, - width: optionGroupWidth + 20 + width: optionGroupWidth }); };