view editor.js @ 120:d5dc9507d612

Basic support for selecting objects in the editor.
author Mike Pavone <pavone@retrodev.com>
date Wed, 17 Apr 2013 23:56:55 -0700
parents 77f7cd65e121
children 2b25d0ce2946
line wrap: on
line source



object.prototype.toHTML = function(node, up) {
	this.up = up;
	var astNode = this;
	var el = newEl('div', {
		className: 'object',
		onclick: function(event) {
			main_module.objectClick(this, astNode, event);
		}
	});
	this.domNode = el;
	node.appendChild(el);
	for (var i in this.messages) {
		this.messages[i].toHTML(el, this);
	}
};

lambda.prototype.toHTML = function(node, up) {
	this.up = up
	var astNode = this;
	var el = newEl('div', {
		className: 'lambda',
		onclick: function(event) {
			main_module.lambdaClick(this, astNode, event);
		}
	});
	this.domNode = el;
	var args = newEl('div', {
		className: 'args'
	});
	for (var i in this.args) {
		this.args[i].toHTML(args, this);
	}
	var body = newEl('div', {
		className: 'lambdabody'
	});
	for (var i in this.expressions) {
		this.expressions[i].toHTML(body, this);
	}
	el.appendChild(args);
	el.appendChild(body);
	node.appendChild(el);
};

assignment.prototype.toHTML = function(node, up) {
	this.up = up;
	var astNode = this;
	var base = newEl('div', {
		className: 'assignment',
		onclick: function(event) {
			main_module.assignClick(this, astNode, event);
		}
	});
	var varName = newEl('span', {
		textContent: this.symbol.name,
		className: 'varname'
	});
	this.domNode = base;
	base.appendChild(varName);
	node.appendChild(base);
	this.expression.toHTML(base, this);
};

op.prototype.toHTML = function(node, up) {
	this.up = up;
	var astNode = this;
	var base = newEl('span', {
		className: 'op',
		onclick: function(event) {
			main_module.opClick(this, astNode, event);
		}
	});
	this.domNode = base;
	this.left.toHTML(base, this);
	base.appendChild(newEl('span', {
		textContent: this.op,
		className: 'opname'
	}));
	if (this.op == '&&' || this.op == '||') {
		this.right.expressions[0].toHTML(base, this);
	} else {
		this.right.toHTML(base, this);
	}
	node.appendChild(base);
};

intlit.prototype.toHTML = function(node, up) {
	this.up = up;
	var astNode = this;
	this.domNode = newEl('span', {
		className: 'integer',
		textContent: this.val,
		onclick: function(event) {
			main_module.scalarClick(this, astNode, event);
		}
	});
	node.appendChild(this.domNode);
};

floatlit.prototype.toHTML = function(node, up) {
	this.up = up;
	var astNode = this;
	this.domNode = newEl('span', {
		className: 'float',
		textContent: this.val,
		onclick: function(event) {
			main_module.scalarClick(this, astNode, event);
		}
	});
	node.appendChild(this.domNode);
};

strlit.prototype.toHTML = function(node, up) {
	this.up = up;
	var astNode = this;
	this.domNode = newEl('span', {
		className: 'string',
		contentEditable: 'true',
		textContent: this.val,
		onclick: function(event) {
			main_module.scalarClick(this, astNode, event);
		}
	});
	node.appendChild(this.domNode);
};

listlit.prototype.toHTML = function(node, up) {
	this.up = up;
	this.domNode = newEl('span', {
		className: 'list',
	});
	for (var i = 0; i < this.val.length; i++) {
		this.val[i].toHTML(this.domNode, this);
	}
	node.appendChild(this.domNode);
};

arraylit.prototype.toHTML = function(node, up) {
	this.up = up;
	this.domNode = newEl('span', {
		className: 'array',
	});
	for (var i = 0; i < this.val.length; i++) {
		this.val[i].toHTML(this.domNode, this);
	}
	node.appendChild(this.domNode);
};

funcall.prototype.toHTML = function(node, up) {
	this.up = up;
	var astNode = this;
	var base = newEl('div', {
		className: 'funcall',
		onclick: function(event) {
			main_module.funClick(this, astNode, event);
		}
	});
	this.domNode = base;
	if (this.receiver) {
		this.receiver.toHTML(base, this);
	}
	var parts = this.name.split(':');
	for (var i in parts ) {
		if(parts[i]) {
			base.appendChild(newEl('span', {
				textContent: parts[i] + (this.receiver && parts.length == 1 ? '' : ':'),
				className: 'funpart'
				}));
			if (this.args[i]) {
				this.args[i].toHTML(base, this);
			}
		}
	}
	for (; i < this.args.length; i++) {
		this.args[i].toHTML(base, this);
	}
	node.appendChild(base);
};

symbol.prototype.toHTML = function(node, up) {
	this.up = up;
	var astNode = this;
	this.domNode = newEl('span', {
		className: 'symbol',
		textContent: this.name,
		onclick: function(event) {
			main_module.symbolClick(this, astNode, event);
		}
	})
	node.appendChild(this.domNode);
}

function getEl(from, idx)
{
	return from[idx];
}

function setEl(to, idx, val)
{
	to[idx] = val;
	return to;
}