Skip to content

Commit

Permalink
Merge pull request #167 from entrylabs/issue/list33
Browse files Browse the repository at this point in the history
added function name sync feature on main workspace when it's name is changed on function edit for Issue/list33
  • Loading branch information
chanlee committed Feb 5, 2016
2 parents 6a541db + ecc981c commit bcd3cdf
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 3 deletions.
43 changes: 43 additions & 0 deletions dist/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -11264,6 +11264,11 @@ Entry.Func.FIELD_BLOCK = '<xml><block type="function_field_label"></block><block
Entry.Func.fieldBlocks = Entry.nodeListToArray(Blockly.Xml.textToDom(Entry.Func.FIELD_BLOCK).childNodes);
Entry.Func.CREATE_BLOCK = '<xml><block type="function_create" deletable="false" x="28" y="28"></block></xml>';
Entry.Func.edit = function(a) {
this.srcFName = "";
for (var b = $(a.content.innerHTML).find("field"), c = 0;c < b.length;c++) {
"NAME" === $(b[c]).attr("name") && (this.srcFName += $(b[c]).text(), this.srcFName += " ");
}
this.srcFName = this.srcFName.trim();
this.cancelEdit();
this.workspace && (this.workspace.visible = !0);
this.initEditView();
Expand Down Expand Up @@ -11320,11 +11325,49 @@ Entry.Func.initEditView = function() {
this.parentView.appendChild(this.svg);
};
Entry.Func.save = function() {
var a = "";
this.targetFunc.content = Blockly.Xml.workspaceToDom(this.workspace);
this.targetFunc.generateBlock(!0);
Entry.variableContainer.saveFunction(this.targetFunc);
for (var b = $(this.targetFunc.content.innerHTML).find("field"), c = 0;c < b.length;c++) {
"NAME" === $(b[c]).attr("name") && (a += $(b[c]).text(), a += " ");
}
a = a.trim();
this.syncFuncName(a);
this.cancelEdit();
};
Entry.Func.syncFuncName = function(a) {
var b = 0, c = [], c = a.split(" "), d = "";
a = [];
a = Blockly.mainWorkspace.getAllBlocks();
for (var e = 0;e < a.length;e++) {
var f = a[e];
if ("function_general" === f.type) {
for (var g = [], g = f.inputList, h = 0;h < g.length;h++) {
f = g[h], 0 < f.fieldRow.length && f.fieldRow[0] instanceof Blockly.FieldLabel && void 0 != f.fieldRow[0].text_ && (d += f.fieldRow[0].text_, d += " ");
}
d = d.trim();
if (d === this.srcFName && this.srcFName.split(" ").length == c.length) {
for (d = 0;d < g.length;d++) {
if (f = g[d], 0 < f.fieldRow.length && f.fieldRow[0] instanceof Blockly.FieldLabel && void 0 != f.fieldRow[0].text_) {
if (void 0 === c[b]) {
g.splice(d, 1);
break;
} else {
f.fieldRow[0].text_ = c[b];
}
b++;
}
}
}
d = "";
b = 0;
}
}
b = Blockly.Xml.workspaceToDom(Blockly.mainWorkspace);
Blockly.mainWorkspace.clear();
Blockly.Xml.domToWorkspace(Blockly.mainWorkspace, b);
};
Entry.Func.cancelEdit = function() {
this.svg && this.targetFunc && (this.workspace.visible = !1, this.parentView.removeChild(this.svg), Entry.Func.isEdit = !1, Blockly.mainWorkspace.blockMenu.targetWorkspace = Blockly.mainWorkspace, this.targetFunc.block || (delete Entry.variableContainer.functions_[this.targetFunc.id], delete Entry.variableContainer.selected), delete this.targetFunc, this.updateMenu(), this.doWhenCancel(), Entry.variableContainer.updateList());
};
Expand Down
7 changes: 5 additions & 2 deletions dist/entry.min.js

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

70 changes: 69 additions & 1 deletion src/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,17 @@ Entry.Func.CREATE_BLOCK =
'</block></xml>';

Entry.Func.edit = function(func) {
this.cancelEdit();
this.srcFName = "";
var fieldElement = $(func.content.innerHTML).find('field');

for(var i = 0; i < fieldElement.length; i++)
if($(fieldElement[i]).attr('name') === "NAME") {
this.srcFName+=$(fieldElement[i]).text();
this.srcFName+=' ';
}
this.srcFName = this.srcFName.trim();

this.cancelEdit();
if (this.workspace)
this.workspace.visible = true;
this.initEditView();
Expand Down Expand Up @@ -158,12 +168,69 @@ Entry.Func.initEditView = function() {
};

Entry.Func.save = function() {
var dstFName = "";
this.targetFunc.content = Blockly.Xml.workspaceToDom(this.workspace);
this.targetFunc.generateBlock(true);
Entry.variableContainer.saveFunction(this.targetFunc);
var fieldElement = $(this.targetFunc.content.innerHTML).find('field');

for(var i = 0; i < fieldElement.length; i++)
if($(fieldElement[i]).attr('name') === "NAME") {

dstFName+=$(fieldElement[i]).text();
dstFName+=' ';
}
dstFName = dstFName.trim();
this.syncFuncName(dstFName);

this.cancelEdit();
};

Entry.Func.syncFuncName = function(dstFName) {
var index = 0;
var dstFNameTokens = [];
dstFNameTokens = dstFName.split(' ');
var name ="";
var blocks = [];
blocks = Blockly.mainWorkspace.getAllBlocks();
for(var i = 0; i < blocks.length; i++) {
var block = blocks[i];
if(block.type === "function_general") {
var iList = [];
iList = block.inputList;
for(var j=0; j < iList.length; j++) {
var input = iList[j];
if(input.fieldRow.length > 0 && (input.fieldRow[0] instanceof Blockly.FieldLabel) && (input.fieldRow[0].text_ != undefined)) {
name+=input.fieldRow[0].text_;
name+=" ";
}
}
name = name.trim();
if(name === this.srcFName && (this.srcFName.split(' ').length == dstFNameTokens.length)) {
for(var k=0; k < iList.length; k++) {
var input = iList[k];
if(input.fieldRow.length > 0 && (input.fieldRow[0] instanceof Blockly.FieldLabel) && (input.fieldRow[0].text_ != undefined)) {
if(dstFNameTokens[index] === undefined) {
iList.splice(k,1);
break;
}
else {
input.fieldRow[0].text_ = dstFNameTokens[index];
}

index++;
}
}
}
name = '';
index = 0;
}
}
var updatedDom = Blockly.Xml.workspaceToDom(Blockly.mainWorkspace)
Blockly.mainWorkspace.clear();
Blockly.Xml.domToWorkspace(Blockly.mainWorkspace, updatedDom);
};

Entry.Func.cancelEdit = function() {
if (!this.svg || !this.targetFunc)
return;
Expand Down Expand Up @@ -540,3 +607,4 @@ Entry.Func.generateWsBlock = function(func, content, id) {
description: description
};
};

0 comments on commit bcd3cdf

Please sign in to comment.