shadow inherited scripts on dragging & dropping blocks and comments

upd4.1
Jens Mönig 2017-06-22 23:00:16 +02:00
rodzic 6820fe8156
commit 14459456c1
3 zmienionych plików z 61 dodań i 3 usunięć

Wyświetl plik

@ -150,7 +150,7 @@ CustomCommandBlockMorph*/
// Global stuff //////////////////////////////////////////////////////// // Global stuff ////////////////////////////////////////////////////////
modules.blocks = '2017-June-20'; modules.blocks = '2017-June-22';
var SyntaxElementMorph; var SyntaxElementMorph;
var BlockMorph; var BlockMorph;
@ -3736,6 +3736,23 @@ BlockMorph.prototype.mouseClickLeft = function () {
} }
}; };
BlockMorph.prototype.selectForEdit = function () {
var rcvr = this.scriptTarget(),
selected;
if (rcvr.inheritsAttribute('scripts')) {
// copy on write:
this.selectionID = true;
rcvr.shadowAttribute('scripts');
selected = detect(rcvr.scripts.allChildren(), function (m) {
return m.selectionID;
});
delete this.selectionID;
delete selected.selectionID;
return selected;
}
return this;
};
BlockMorph.prototype.focus = function () { BlockMorph.prototype.focus = function () {
var scripts = this.parentThatIsA(ScriptsMorph), var scripts = this.parentThatIsA(ScriptsMorph),
world = this.world(), world = this.world(),
@ -6602,6 +6619,17 @@ ScriptsMorph.prototype.mouseClickLeft = function (pos) {
if (this.focus) {this.focus.stopEditing(); } if (this.focus) {this.focus.stopEditing(); }
}; };
ScriptsMorph.prototype.selectForEdit = function () {
var rcvr = this.scriptTarget();
if (rcvr.inheritsAttribute('scripts')) {
// copy on write:
this.feedbackMorph.destroy();
rcvr.shadowAttribute('scripts');
return rcvr.scripts;
}
return this;
};
// ScriptsMorph keyboard support // ScriptsMorph keyboard support
ScriptsMorph.prototype.edit = function (pos) { ScriptsMorph.prototype.edit = function (pos) {
@ -12805,6 +12833,9 @@ CommentMorph.prototype.fullCopy = function () {
var cpy = new CommentMorph(this.contents.text); var cpy = new CommentMorph(this.contents.text);
cpy.isCollapsed = this.isCollapsed; cpy.isCollapsed = this.isCollapsed;
cpy.setTextWidth(this.textWidth()); cpy.setTextWidth(this.textWidth());
if (this.selectionID) { // for copy on write
cpy.selectionID = true;
}
return cpy; return cpy;
}; };
@ -12963,6 +12994,24 @@ CommentMorph.prototype.prepareToBeGrabbed = function (hand) {
} }
}; };
CommentMorph.prototype.selectForEdit = function () {
var scripts = this.parentThatIsA(ScriptsMorph),
rcvr = scripts ? scripts.scriptTarget() : null,
selected;
if (rcvr && rcvr.inheritsAttribute('scripts')) {
// copy on write:
this.selectionID = true;
rcvr.shadowAttribute('scripts');
selected = detect(rcvr.scripts.allChildren(), function (m) {
return m.selectionID;
});
delete this.selectionID;
delete selected.selectionID;
return selected;
}
return this;
};
CommentMorph.prototype.snap = function (hand) { CommentMorph.prototype.snap = function (hand) {
// passing the hand is optional (for when blocks are dragged & dropped) // passing the hand is optional (for when blocks are dragged & dropped)
var scripts = this.parent, var scripts = this.parent,

Wyświetl plik

@ -3454,6 +3454,11 @@ Fixes:
------ ------
* objects: stop all scripts for a sprite when shadowing or inheriting its scripts * objects: stop all scripts for a sprite when shadowing or inheriting its scripts
170622
------
* Morphic: support for copy-on-write worlds (“selectForEdit”)
* Blocks, Objects: shadow inherited scripts on dragging & dropping blocks and comments
Features: Features:
* polymorphic sprite-local custom blocks * polymorphic sprite-local custom blocks

Wyświetl plik

@ -82,7 +82,7 @@ SpeechBubbleMorph, RingMorph, isNil, FileReader, TableDialogMorph,
BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, localize, BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, localize,
TableMorph, TableFrameMorph, normalizeCanvas, BooleanSlotMorph, HandleMorph*/ TableMorph, TableFrameMorph, normalizeCanvas, BooleanSlotMorph, HandleMorph*/
modules.objects = '2017-June-21'; modules.objects = '2017-June-22';
var SpriteMorph; var SpriteMorph;
var StageMorph; var StageMorph;
@ -5186,7 +5186,8 @@ SpriteMorph.prototype.shadowedAttributes = function () {
SpriteMorph.prototype.shadowAttribute = function (aName) { SpriteMorph.prototype.shadowAttribute = function (aName) {
var ide, wardrobe, var ide, wardrobe,
myself = this; myself = this,
pos;
if (!this.inheritsAttribute(aName)) { if (!this.inheritsAttribute(aName)) {
return; return;
} }
@ -5206,11 +5207,14 @@ SpriteMorph.prototype.shadowAttribute = function (aName) {
this.costumes = wardrobe; this.costumes = wardrobe;
} else if (aName === 'scripts') { } else if (aName === 'scripts') {
ide.stage.threads.stopAllForReceiver(this); ide.stage.threads.stopAllForReceiver(this);
pos = this.scripts.position();
this.scripts = this.exemplar.scripts.fullCopy(); this.scripts = this.exemplar.scripts.fullCopy();
if (ide && (contains(ide.currentSprite.allExemplars(), this))) { if (ide && (contains(ide.currentSprite.allExemplars(), this))) {
ide.createSpriteEditor(); ide.createSpriteEditor();
ide.fixLayout('selectSprite'); ide.fixLayout('selectSprite');
this.scripts.fixMultiArgs(); this.scripts.fixMultiArgs();
this.scripts.setPosition(pos);
ide.spriteEditor.adjustScrollBars();
} }
this.specimens().forEach(function (obj) { this.specimens().forEach(function (obj) {
if (obj.inheritsAttribute('scripts')) { if (obj.inheritsAttribute('scripts')) {