diff options
| author | jmoenig <jens@moenig.org> | 2013-04-23 16:55:11 +0200 |
|---|---|---|
| committer | jmoenig <jens@moenig.org> | 2013-04-23 16:55:11 +0200 |
| commit | d098dbb4ba80b5fd10deba3a0085f68a95e05b79 (patch) | |
| tree | 35c6f7b681c95a48577508c17e96ac06810c48da /objects.js | |
| parent | 020f95992d6e452751199ec18ab066fe2cf9d78c (diff) | |
| download | snap-d098dbb4ba80b5fd10deba3a0085f68a95e05b79.tar.gz snap-d098dbb4ba80b5fd10deba3a0085f68a95e05b79.zip | |
Fixed #44
Circularity no longer breaks watchers
Diffstat (limited to 'objects.js')
| -rw-r--r-- | objects.js | 39 |
1 files changed, 33 insertions, 6 deletions
@@ -120,7 +120,7 @@ PrototypeHatBlockMorph*/ // Global stuff //////////////////////////////////////////////////////// -modules.objects = '2013-April-19'; +modules.objects = '2013-April-23'; var SpriteMorph; var StageMorph; @@ -4805,16 +4805,17 @@ CellMorph.uber = BoxMorph.prototype; // CellMorph instance creation: -function CellMorph(contents, color, idx) { - this.init(contents, color, idx); +function CellMorph(contents, color, idx, parentCell) { + this.init(contents, color, idx, parentCell); } -CellMorph.prototype.init = function (contents, color, idx) { +CellMorph.prototype.init = function (contents, color, idx, parentCell) { this.contents = (contents === 0 ? 0 : contents === false ? false : contents || ''); this.isEditable = isNil(idx) ? false : true; this.idx = idx || null; // for list watchers + this.parentCell = parentCell || null; // for list circularity detection CellMorph.uber.init.call( this, SyntaxElementMorph.prototype.corner, @@ -4842,6 +4843,17 @@ CellMorph.prototype.normal = function () { this.changed(); }; +// CellMorph circularity testing: + + +CellMorph.prototype.isCircular = function (list) { + if (!this.parentCell) {return false; } + if (list instanceof List) { + return this.contents === list || this.parentCell.isCircular(list); + } + return this.parentCell.isCircular(this.contents); +}; + // CellMorph layout: CellMorph.prototype.fixLayout = function () { @@ -4914,8 +4926,23 @@ CellMorph.prototype.drawNew = function () { this.contentsMorph.silentSetHeight(img.height); this.contentsMorph.image = img; } else if (this.contents instanceof List) { - this.contentsMorph = new ListWatcherMorph(this.contents); - this.contentsMorph.isDraggable = false; + if (this.isCircular()) { + this.contentsMorph = new TextMorph( + '(...)', + fontSize, + null, + false, // bold + true, // italic + 'center' + ); + this.contentsMorph.setColor(new Color(255, 255, 255)); + } else { + this.contentsMorph = new ListWatcherMorph( + this.contents, + this + ); + this.contentsMorph.isDraggable = false; + } } else { this.contentsMorph = new TextMorph( !isNil(this.contents) ? this.contents.toString() : '', |
