summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjmoenig <jens@moenig.org>2013-04-02 18:18:19 +0200
committerjmoenig <jens@moenig.org>2013-04-02 18:18:19 +0200
commit895ab6ddeb93938a75e779d9b3c0344330472933 (patch)
tree75440a1ebd19e5e9e92296d98b51b0264c83f2c0
parent84fd877fa483d986a9651b7d5555455cce978cae (diff)
downloadsnap-yow-895ab6ddeb93938a75e779d9b3c0344330472933.tar.gz
snap-yow-895ab6ddeb93938a75e779d9b3c0344330472933.zip
Anchored Comments Enhancements
* the Block Editor now allows anchored comments, * duplicating a block / script / sprite now also duplicates anchored comments, * deleting a block / script now also deletes anchored comments
-rw-r--r--blocks.js38
-rw-r--r--byob.js13
-rw-r--r--gui.js3
-rwxr-xr-xhistory.txt5
4 files changed, 46 insertions, 13 deletions
diff --git a/blocks.js b/blocks.js
index f53a5bc..f157d50 100644
--- a/blocks.js
+++ b/blocks.js
@@ -153,7 +153,7 @@ DialogBoxMorph, BlockInputFragmentMorph, PrototypeHatBlockMorph*/
// Global stuff ////////////////////////////////////////////////////////
-modules.blocks = '2013-March-22';
+modules.blocks = '2013-April-02';
var SyntaxElementMorph;
var BlockMorph;
@@ -2344,7 +2344,11 @@ BlockMorph.prototype.fullCopy = function () {
ans.allChildren().filter(function (block) {
return !isNil(block.comment);
}).forEach(function (block) {
- block.comment = null;
+ var cmnt = block.comment.fullCopy();
+ block.comment = cmnt;
+ cmnt.block = block;
+ //block.comment = null;
+
});
return ans;
};
@@ -2477,6 +2481,13 @@ BlockMorph.prototype.allComments = function () {
});
};
+BlockMorph.prototype.destroy = function () {
+ this.allComments().forEach(function (comment) {
+ comment.destroy();
+ });
+ BlockMorph.uber.destroy.call(this);
+};
+
BlockMorph.prototype.stackHeight = function () {
var fb = this.fullBounds(),
commentsBottom = Math.max(this.allComments().map(
@@ -3950,7 +3961,6 @@ ScriptsMorph.prototype.init = function (owner) {
this.owner = owner || null;
this.feedbackColor = SyntaxElementMorph.prototype.feedbackColor;
this.feedbackMorph = new BoxMorph();
- this.allowsStickyComments = true;
ScriptsMorph.uber.init.call(this);
this.setColor(new Color(70, 70, 70));
@@ -3963,9 +3973,16 @@ ScriptsMorph.prototype.fullCopy = function () {
pos = this.position(),
child;
this.children.forEach(function (morph) {
- child = morph.fullCopy();
- child.setPosition(morph.position().subtract(pos));
- cpy.add(child);
+ if (!morph.block) { // omit anchored comments
+ child = morph.fullCopy();
+ child.setPosition(morph.position().subtract(pos));
+ cpy.add(child);
+ if (child instanceof BlockMorph) {
+ child.allComments().forEach(function (comment) {
+ comment.align(child);
+ });
+ }
+ }
});
cpy.adjustBounds();
return cpy;
@@ -4191,7 +4208,6 @@ ScriptsMorph.prototype.closestBlock = function (comment, hand) {
target,
all;
- if (!this.allowsStickyComments) {return null; }
all = [];
stacks.forEach(function (stack) {
all = all.concat(stack.allChildren().slice(0).reverse().filter(
@@ -4207,6 +4223,8 @@ ScriptsMorph.prototype.closestBlock = function (comment, hand) {
all,
function (block) {
return !block.comment
+ && !(block instanceof PrototypeHatBlockMorph)
+ && !block.isPrototype
&& block.bounds.containsPoint(handPos);
}
);
@@ -4218,6 +4236,8 @@ ScriptsMorph.prototype.closestBlock = function (comment, hand) {
all,
function (block) {
return !block.comment
+ && !(block instanceof PrototypeHatBlockMorph)
+ && !block.isPrototype
&& block.bounds.intersects(fb);
}
);
@@ -8314,7 +8334,7 @@ ReporterSlotMorph.prototype.evaluate = function () {
return this.nestedBlock();
};
-CommandSlotMorph.prototype.isEmptySlot = function () {
+ReporterSlotMorph.prototype.isEmptySlot = function () {
return this.nestedBlock() === null;
};
@@ -8988,7 +9008,7 @@ CommentMorph.prototype.align = function (topBlock, ignoreLayer) {
);
this.setLeft(rightMost + 5);
- if (!ignoreLayer) {
+ if (!ignoreLayer && scripts) {
scripts.addBack(this); // push to back and show
}
diff --git a/byob.js b/byob.js
index 29ab1b5..99e882c 100644
--- a/byob.js
+++ b/byob.js
@@ -105,7 +105,7 @@ CommentMorph, localize, CSlotMorph*/
// Global stuff ////////////////////////////////////////////////////////
-modules.byob = '2013-March-18';
+modules.byob = '2013-April-02';
// Declarations
@@ -1420,7 +1420,6 @@ BlockEditorMorph.prototype.init = function (definition, target) {
// create scripting area
scripts = new ScriptsMorph(target);
- scripts.allowsStickyComments = false;
scripts.isDraggable = false;
scripts.color = new Color(71, 71, 71);
scripts.texture = 'scriptsPaneTexture.gif';
@@ -1440,6 +1439,14 @@ BlockEditorMorph.prototype.init = function (definition, target) {
block = element.fullCopy();
block.setPosition(scripts.position().add(element.position()));
scripts.add(block);
+ if (block instanceof BlockMorph) {
+ block.allComments().forEach(function (comment) {
+ comment.align(block);
+ });
+ }
+ });
+ proto.allComments().forEach(function (comment) {
+ comment.align(proto);
});
scriptsFrame = new ScrollFrameMorph(scripts);
@@ -1559,7 +1566,7 @@ BlockEditorMorph.prototype.updateDefinition = function () {
if (morph instanceof PrototypeHatBlockMorph) {
head = morph;
} else if (morph instanceof BlockMorph ||
- morph instanceof CommentMorph) {
+ (morph instanceof CommentMorph && !morph.block)) {
element = morph.fullCopy();
element.parent = null;
element.setPosition(morph.position().subtract(pos));
diff --git a/gui.js b/gui.js
index 5642bde..d051dc1 100644
--- a/gui.js
+++ b/gui.js
@@ -4418,6 +4418,9 @@ SpriteIconMorph.prototype.copyStack = function (block) {
dup.setPosition(new Point(this.object.scripts.left() + 20, y + 20));
this.object.scripts.add(dup);
+ dup.allComments().forEach(function (comment) {
+ comment.align(dup);
+ });
this.object.scripts.adjustBounds();
// delete all custom blocks pointing to local definitions
diff --git a/history.txt b/history.txt
index b7f4b25..c380a29 100755
--- a/history.txt
+++ b/history.txt
@@ -1570,4 +1570,7 @@ ______
------
* Japanese translations update, thanks, Kazuhiro Abe!
* Content-type support for Cloud backend
-* sharing / unsharing projects support and GUI \ No newline at end of file
+* sharing / unsharing projects support and GUI
+* the Block Editor now allows anchored comments
+* duplicating a block / script / sprite now also duplicates anchored comments
+* deleting a block / script now also deletes anchored comments \ No newline at end of file