forked from scratchfoundation/scratch-flash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlockPalette.as
More file actions
81 lines (72 loc) · 2.6 KB
/
BlockPalette.as
File metadata and controls
81 lines (72 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* Scratch Project Editor and Player
* Copyright (C) 2014 Massachusetts Institute of Technology
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
// BlockPalette.as
// John Maloney, August 2009
//
// A BlockPalette holds the blocks for the selected category.
// The mouse handling code detects when a Block's parent is a BlocksPalette and
// creates a copy of that block when it is dragged out of the palette.
package ui {
import blocks.Block;
import uiwidgets.*;
import scratch.ScratchComment;
public class BlockPalette extends ScrollFrameContents {
public const isBlockPalette:Boolean = true;
public function BlockPalette():void {
super();
this.color = 0xE0E0E0;
}
public function handleDrop(obj:*):Boolean {
// Delete blocks and stacks dropped onto the palette.
var app:Scratch = root as Scratch;
var c:ScratchComment = obj as ScratchComment;
if (c) {
c.x = c.y = 20; // postion for undelete
c.deleteComment();
return true;
}
var b:Block = obj as Block;
if (b) {
if ((b.op == Specs.PROCEDURE_DEF) && hasCallers(b, app)) {
DialogBox.notify('Cannot Delete', 'To delete a block definition, first remove all uses of the block.', stage);
return false;
}
if (b.parent) b.parent.removeChild(b);
b.restoreOriginalPosition(); // restore position in case block is undeleted
Scratch.app.runtime.recordForUndelete(b, b.x, b.y, 0, Scratch.app.viewedObj());
app.scriptsPane.saveScripts();
app.updatePalette();
return true;
}
return false;
}
private function hasCallers(def:Block, app:Scratch):Boolean {
var callCount:int;
for each (var stack:Block in app.viewedObj().scripts) {
// for each block in stack
stack.allBlocksDo(function (b:Block):void {
if ((b.op == Specs.CALL) && (b.spec == def.spec)) callCount++;
});
}
return callCount > 0;
}
public static function strings():Array {
return ['Cannot Delete', 'To delete a block definition, first remove all uses of the block.'];
}
}}