summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjmoenig <jens@moenig.org>2013-04-23 16:55:11 +0200
committerjmoenig <jens@moenig.org>2013-04-23 16:55:11 +0200
commitd098dbb4ba80b5fd10deba3a0085f68a95e05b79 (patch)
tree35c6f7b681c95a48577508c17e96ac06810c48da
parent020f95992d6e452751199ec18ab066fe2cf9d78c (diff)
downloadsnap-yow-d098dbb4ba80b5fd10deba3a0085f68a95e05b79.tar.gz
snap-yow-d098dbb4ba80b5fd10deba3a0085f68a95e05b79.zip
Fixed #44
Circularity no longer breaks watchers
-rwxr-xr-xhistory.txt4
-rw-r--r--lists.js13
-rw-r--r--objects.js39
3 files changed, 45 insertions, 11 deletions
diff --git a/history.txt b/history.txt
index 2faa12b..76dbc16 100755
--- a/history.txt
+++ b/history.txt
@@ -1653,3 +1653,7 @@ ______
130422
------
* GUI: Double clicking support for cloud side of project dialog
+
+130423
+------
+* Lists, Objects: Circularity no longer breaks watchers
diff --git a/lists.js b/lists.js
index 7382840..ac85b25 100644
--- a/lists.js
+++ b/lists.js
@@ -61,7 +61,7 @@ PushButtonMorph, SyntaxElementMorph, Color, Point, WatcherMorph,
StringMorph, SpriteMorph, ScrollFrameMorph, CellMorph, ArrowMorph,
MenuMorph, snapEquals, Morph, isNil, localize*/
-modules.lists = '2013-April-12';
+modules.lists = '2013-April-23';
var List;
var ListWatcherMorph;
@@ -345,11 +345,11 @@ ListWatcherMorph.prototype.cellColor =
// ListWatcherMorph instance creation:
-function ListWatcherMorph(list) {
- this.init(list);
+function ListWatcherMorph(list, parentCell) {
+ this.init(list, parentCell);
}
-ListWatcherMorph.prototype.init = function (list) {
+ListWatcherMorph.prototype.init = function (list, parentCell) {
var myself = this;
this.list = list || new List();
@@ -357,6 +357,7 @@ ListWatcherMorph.prototype.init = function (list) {
this.range = 100;
this.lastUpdated = Date.now();
this.lastCell = null;
+ this.parentCell = parentCell || null; // for circularity detection
// elements declarations
this.label = new StringMorph(
@@ -434,6 +435,7 @@ ListWatcherMorph.prototype.update = function (anyway) {
starttime, maxtime = 1000;
this.frame.contents.children.forEach(function (m) {
+
if (m instanceof CellMorph
&& m.contentsMorph instanceof ListWatcherMorph) {
m.contentsMorph.update();
@@ -529,7 +531,8 @@ ListWatcherMorph.prototype.update = function (anyway) {
cell = new CellMorph(
this.list.at(idx),
this.cellColor,
- idx
+ idx,
+ this.parentCell
);
button = new PushButtonMorph(
this.list.remove,
diff --git a/objects.js b/objects.js
index dc47375..b8965b4 100644
--- a/objects.js
+++ b/objects.js
@@ -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() : '',