Skip to content

Commit

Permalink
Merge pull request #495 from entrylabs/issue/func_cancel
Browse files Browse the repository at this point in the history
Issue/func cancel
  • Loading branch information
chanlee authored Oct 21, 2016
2 parents 285238f + becb0a5 commit 82adf62
Show file tree
Hide file tree
Showing 7 changed files with 799 additions and 739 deletions.
150 changes: 76 additions & 74 deletions dist/entry.js

Large diffs are not rendered by default.

1,254 changes: 627 additions & 627 deletions dist/entry.min.js

Large diffs are not rendered by default.

63 changes: 51 additions & 12 deletions src/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Entry.Func = function(func) {
]);
this.block = null;
this.blockMenuBlock = null;
this._backupContent = null;
this.hashMap = {};

this.paramMap = {};
Expand Down Expand Up @@ -89,6 +90,7 @@ Entry.Func.edit = function(func) {
this.targetFunc = func;
this.initEditView(func.content);
this.bindFuncChangeEvent();
this._backupContent = func.content.stringify();
this.updateMenu();
};

Expand All @@ -100,8 +102,9 @@ Entry.Func.initEditView = function(content) {
workspace.changeOverlayBoardCode(content);
content.recreateView();
workspace.changeOverlayBoardCode(content);
content.view.board.alignThreads();
this._workspaceStateEvent = workspace.changeEvent.attach(this, this.endEdit);
content.view.reDraw();
content.view.board.alignThreads();
};

Entry.Func.endEdit = function(message) {
Expand All @@ -111,9 +114,15 @@ Entry.Func.endEdit = function(message) {
switch(message){
case "save":
this.save();
break;
case "cancelEdit":
this.cancelEdit();
break;
}
this._backupContent = null;
Entry.playground.mainWorkspace.setMode(Entry.Workspace.MODE_BOARD);
delete this.targetFunc;
this.updateMenu();
}

Entry.Func.save = function() {
Expand Down Expand Up @@ -167,19 +176,22 @@ Entry.Func.syncFuncName = function(dstFName) {
};

Entry.Func.cancelEdit = function() {
if (!this.targetFunc)
return;
Entry.Func.isEdit = false;
if (!this.targetFunc) return;

if (!this.targetFunc.block) {
this._targetFuncBlock.destroy();
delete Entry.variableContainer.functions_[this.targetFunc.id];
delete Entry.variableContainer.selected;
} else {
if (this._backupContent &&
this._backupContent !== this.targetFunc.content.stringify()) {
this.targetFunc.content.load(this._backupContent);
Entry.generateFunctionSchema(this.targetFunc.id);
Entry.Func.generateWsBlock(this.targetFunc);
}
}
delete this.targetFunc;
this.updateMenu();
Entry.variableContainer.updateList();
var workspace = Entry.playground.mainWorkspace;
workspace.setMode(Entry.Workspace.MODE_BOARD);
Entry.Func.isEdit = false;
};

Entry.Func.getMenuXml = function() {
Expand Down Expand Up @@ -425,10 +437,37 @@ Entry.Func.generateWsBlock = function(targetFunc) {
"img": "block_icon/function_03.png",
"size": 12
});
Entry.Mutator.mutate(
"func_" + targetFunc.id,
{params: schemaParams, template: schemaTemplate}
);

var funcName = "func_" + targetFunc.id;
var originSchema = Entry.block[funcName];

var shouldFuncMutate = false;

if (originSchema.template !== schemaTemplate)
shouldFuncMutate = true;
else if (originSchema.params.length === schemaParams.length) {
for (var i=0; i<originSchema.params.length-1; i++) {
var originParam = originSchema.params[i];
var newParam = schemaParams[i];
if (originParam.type === newParam.type &&
originParam.accept === newParam.accept)
continue;
else {
shouldFuncMutate = true;
break;
}
}
}

if (shouldFuncMutate) {
Entry.Mutator.mutate(
funcName,
{
params: schemaParams,
template: schemaTemplate
}
);
}

for (var key in hashMap) {
var state = hashMap[key];
Expand Down
9 changes: 7 additions & 2 deletions src/workspace/block_menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Entry.BlockMenu = function(dom, align, categoryData, scroll) {
this._bannedClass = [];
this._categories = [];
this.suffix = 'blockMenu';
this._isSelectingMenu = false;

if (typeof dom === "string") dom = $('#' + dom);
else dom = $(dom);
Expand Down Expand Up @@ -179,7 +180,7 @@ Entry.BlockMenu = function(dom, align, categoryData, scroll) {
if (!code) return;
this._clearSplitters();

if (code.view && !unReDraw)
if (code.view && !unReDraw && !this._isSelectingMenu)
code.view.reDraw();

var threads = code.getThreads();
Expand Down Expand Up @@ -428,6 +429,7 @@ Entry.BlockMenu = function(dom, align, categoryData, scroll) {
this.align();
return;
}
this._isSelectingMenu = true;
switch (name) {
case 'variable':
Entry.playground.checkVariables();
Expand All @@ -443,7 +445,8 @@ Entry.BlockMenu = function(dom, align, categoryData, scroll) {
var board = this.workspace.board,
boardView = board.view;

if (oldView) oldView.removeClass(className);
if (oldView)
oldView.removeClass(className);

if (elem == oldView && !doNotFold) {
boardView.addClass('folding');
Expand All @@ -470,6 +473,8 @@ Entry.BlockMenu = function(dom, align, categoryData, scroll) {
});
}

this._isSelectingMenu = false;

if (this.visible) {
var code = this._categoryCodes[name];

Expand Down
21 changes: 7 additions & 14 deletions src/workspace/block_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ Entry.BlockView.pngMap = {};
var secondLineHeight = 0;
for (var i = 0; i < this._contents.length; i++) {
var c = this._contents[i];

if (c instanceof Entry.FieldLineBreak) {
this._alignStatement(animate, statementIndex);
c.align(statementIndex);
Expand Down Expand Up @@ -995,8 +994,9 @@ Entry.BlockView.pngMap = {};
};

p._updateContents = function() {
for (var i=0; i<this._contents.length; i++)
this._contents[i].renderStart();
this._contents.forEach(function(c) {
c.renderStart();
}.bind(this));
this.alignContent(false);
};

Expand Down Expand Up @@ -1031,18 +1031,11 @@ Entry.BlockView.pngMap = {};
};

p.reDraw = function() {
if (!this.visible) return;
if (!(this.visible && this.display))
return;

var block = this.block;
requestAnimFrame(this._updateContents.bind(this));
var params = block.params;
if (params) {
for (var i=0; i<params.length; i++) {
var param = params[i];
if (param instanceof Entry.Block && param.view) {
param.view.reDraw();
}
}
}
this._updateContents();
var statements = block.statements;
if (statements) {
for (var i=0; i<statements.length; i++) {
Expand Down
21 changes: 16 additions & 5 deletions src/workspace/field/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ Entry.Utils.inherit(Entry.Field, Entry.FieldBlock);
};

p.renderStart = function(board, mode) {
this.svgGroup = this._blockView.contentSvgGroup.elem("g");
if (!this.svgGroup)
this.svgGroup =
this._blockView.contentSvgGroup.elem("g");
this.view = this;
this._nextGroup = this.svgGroup;
this.box.set({
Expand All @@ -60,7 +62,10 @@ Entry.Utils.inherit(Entry.Field, Entry.FieldBlock);
block.setThread(this);
block.createView(board, mode);
block.getThread().view.setParent(this);
} else if (block && block.view) {
block.view.reDraw();
}

this.updateValueBlock(block);

if (this._blockView.getBoard().constructor !== Entry.Board)
Expand All @@ -80,7 +85,7 @@ Entry.Utils.inherit(Entry.Field, Entry.FieldBlock);

var block = this._valueBlock;

if (block) {
if (block && (block && block.view)) {
y = block.view.height * -0.5;
}
var transform = "translate(" + x + "," + y + ")";
Expand All @@ -102,8 +107,7 @@ Entry.Utils.inherit(Entry.Field, Entry.FieldBlock);

p.calcWH = function() {
var block = this._valueBlock;

if (block) {
if (block && (block && block.view)) {
var blockView = block.view;
this.box.set({
width: blockView.width,
Expand Down Expand Up @@ -159,7 +163,14 @@ Entry.Utils.inherit(Entry.Field, Entry.FieldBlock);
p.getValueBlock = function() {return this._valueBlock;};

p.updateValueBlock = function(block) {
if (!(block instanceof Entry.Block)) block = undefined;
if (!(block instanceof Entry.Block))
block = undefined;

if (block && block === this._valueBlock) {
this.calcWH();
return;
}

this._destroyObservers();

var view = this._setValueBlock(block).view;
Expand Down
20 changes: 15 additions & 5 deletions src/workspace/field/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ Entry.Utils.inherit(Entry.Field, Entry.FieldOutput);
};

p.renderStart = function(board, mode) {
this.svgGroup = this._blockView.contentSvgGroup.elem("g");
if (!this.svgGroup)
this.svgGroup =
this._blockView.contentSvgGroup.elem("g");

this.view = this;
this._nextGroup = this.svgGroup;
this.box.set({
Expand All @@ -59,7 +62,10 @@ Entry.Utils.inherit(Entry.Field, Entry.FieldOutput);
if (block && !block.view) {
block.setThread(this);
block.createView(board, mode);
} else if (block && block.view) {
block.view.reDraw();
}

this._updateValueBlock(block);

if (this._blockView.getBoard().constructor == Entry.BlockMenu &&
Expand Down Expand Up @@ -137,7 +143,14 @@ Entry.Utils.inherit(Entry.Field, Entry.FieldOutput);
};

p._updateValueBlock = function(block) {
if (!(block instanceof Entry.Block)) block = undefined;
if (!(block instanceof Entry.Block))
block = undefined;

if (block && block === this._valueBlock) {
this.calcWH();
return;
}

if (this._sizeObserver) this._sizeObserver.destroy();
if (this._posObserver) this._posObserver.destroy();

Expand All @@ -151,9 +164,6 @@ Entry.Utils.inherit(Entry.Field, Entry.FieldOutput);
this.calcWH();
}
this._blockView.alignContent();
var board = this._blockView.getBoard();// performance issue
if (board.constructor === Entry.Board)
board.generateCodeMagnetMap();
};

p.getPrevBlock = function(block) {
Expand Down

0 comments on commit 82adf62

Please sign in to comment.