@@ -44,17 +44,32 @@ public class BlockMenus implements DragClient {
44
44
private static const spriteAttributes: Array = [ 'x position' , 'y position' , 'direction' , 'costume #' , 'costume name' , 'size' , 'volume' ];
45
45
private static const stageAttributes: Array = [ 'backdrop #' , 'backdrop name' , 'volume' ];
46
46
47
- public static function BlockMenuHandler (evt :MouseEvent , block :Block , blockArg :BlockArg = null , menuName :String = null ):void {
47
+ public static function BlockMenuHandler (evt :MouseEvent , block :Block , blockArg :BlockArg = null , menuName :String = null , menuItems : Array = null ):void {
48
48
var menuHandler: BlockMenus = new BlockMenus(block, blockArg);
49
49
var op: String = block. op;
50
- if (menuName == null ) { // menu gesture on a block (vs. an arg)
51
- if (op == Specs. GET_LIST ) menuName = 'list' ;
52
- if (op == Specs. GET_VAR ) menuName = 'var' ;
53
- if ((op == Specs. PROCEDURE_DEF ) || (op == Specs. CALL )) menuName = 'procMenu' ;
54
- if ((op == 'broadcast:' ) || (op == 'doBroadcastAndWait' ) || (op == 'whenIReceive' )) menuName = 'broadcastInfoMenu' ;
55
- if ((basicMathOps. indexOf (op)) > - 1 ) { menuHandler. changeOpMenu(evt, basicMathOps); return ; }
56
- if ((comparisonOps. indexOf (op)) > - 1 ) { menuHandler. changeOpMenu(evt, comparisonOps); return ; }
57
- if (menuName == null ) { menuHandler. genericBlockMenu(evt); return ; }
50
+ if (menuName == null ) {
51
+ if (menuItems == null ) {
52
+ // menu gesture on a block (vs. an arg)
53
+ if (op == Specs. GET_LIST ) menuName = 'list' ;
54
+ if (op == Specs. GET_VAR ) menuName = 'var' ;
55
+ if ((op == Specs. PROCEDURE_DEF ) || (op == Specs. CALL )) menuName = 'procMenu' ;
56
+ if ((op == 'broadcast:' ) || (op == 'doBroadcastAndWait' ) || (op == 'whenIReceive' )) menuName = 'broadcastInfoMenu' ;
57
+ if ((basicMathOps. indexOf (op)) > - 1 ) {
58
+ menuHandler. changeOpMenu(evt, basicMathOps);
59
+ return ;
60
+ }
61
+ if ((comparisonOps. indexOf (op)) > - 1 ) {
62
+ menuHandler. changeOpMenu(evt, comparisonOps);
63
+ return ;
64
+ }
65
+ if (menuName == null ) {
66
+ menuHandler. genericBlockMenu(evt);
67
+ return ;
68
+ }
69
+ } else {
70
+ menuHandler. customMenu(evt,menuItems);
71
+ return ;
72
+ }
58
73
}
59
74
if (op. indexOf ('.' ) > - 1 ) {
60
75
menuHandler. extensionMenu(evt, menuName);
@@ -160,6 +175,7 @@ public class BlockMenus implements DragClient {
160
175
function isGeneric(s: String ): Boolean {
161
176
return [ 'duplicate' , 'delete' , 'add comment' ] . indexOf (s) > - 1 ;
162
177
}
178
+
163
179
switch (menuName) {
164
180
case 'attribute' :
165
181
return spriteAttributes. indexOf (item ) > - 1 || stageAttributes. indexOf (item ) > - 1 ;
@@ -367,6 +383,7 @@ public class BlockMenus implements DragClient {
367
383
if (s is Function ) s()
368
384
else setBlockArg(s);
369
385
}
386
+
370
387
var m: Menu = new Menu (setSoundArg, 'sound' );
371
388
if (app. viewedObj() == null ) return ;
372
389
for (var i: int = 0 ; i < app. viewedObj(). sounds. length ; i++ ) {
@@ -400,6 +417,7 @@ public class BlockMenus implements DragClient {
400
417
}
401
418
Scratch. app. setSaveNeeded();
402
419
}
420
+
403
421
var spriteNames: Array = [];
404
422
var m: Menu = new Menu (setSpriteArg, 'sprite' );
405
423
if (includeMouse) m. addItem ('mouse-pointer' , 'mouse-pointer' );
@@ -431,6 +449,7 @@ public class BlockMenus implements DragClient {
431
449
block. type = block. isTerminal ? 'f' : ' ' ;
432
450
Scratch. app. setSaveNeeded();
433
451
}
452
+
434
453
var m: Menu = new Menu (setStopType, 'stop' );
435
454
if (! block. nextBlock) {
436
455
m. addItem ('all' );
@@ -464,6 +483,7 @@ public class BlockMenus implements DragClient {
464
483
if ('video motion' == s) app. libraryPart. showVideoButton();
465
484
setBlockArg(s);
466
485
}
486
+
467
487
var m: Menu = new Menu (setTriggerType, 'triggerSensor' );
468
488
m. addItem ('loudness' );
469
489
m. addItem ('timer' );
@@ -519,6 +539,7 @@ public class BlockMenus implements DragClient {
519
539
if (selection is Function ) { selection (); return ; }
520
540
block. changeOperator(selection );
521
541
}
542
+
522
543
if (! block) return ;
523
544
var m: Menu = new Menu (opMenu, 'changeOp' );
524
545
addGenericBlockItems(m);
@@ -647,6 +668,7 @@ public class BlockMenus implements DragClient {
647
668
setBlockVarOrListName(newName);
648
669
app. updatePalette();
649
670
}
671
+
650
672
var d : DialogBox = new DialogBox(doVarRename);
651
673
d . addTitle(Translator. map ('Rename' ) + ' ' + blockVarOrListName());
652
674
d . addField('New name' , 120 );
@@ -664,6 +686,7 @@ public class BlockMenus implements DragClient {
664
686
app. updatePalette();
665
687
app. setSaveNeeded();
666
688
}
689
+
667
690
DialogBox. confirm(Translator. map ('Delete' ) + ' ' + blockVarOrListName() + '?' , app. stage , doDelete);
668
691
}
669
692
@@ -729,6 +752,7 @@ public class BlockMenus implements DragClient {
729
752
if (selection is Function ) selection ();
730
753
else setBlockArg(selection );
731
754
}
755
+
732
756
var msgNames: Array = app. runtime. collectBroadcasts();
733
757
if (msgNames. indexOf ('message1' ) <= - 1 ) msgNames. push ('message1' );
734
758
msgNames. sort ();
@@ -746,6 +770,7 @@ public class BlockMenus implements DragClient {
746
770
if (newName. length == 0 ) return ;
747
771
setBlockArg(newName);
748
772
}
773
+
749
774
var d : DialogBox = new DialogBox(changeBroadcast);
750
775
d . addTitle('New Message' );
751
776
d . addField('Message Name' , 120 );
@@ -763,6 +788,7 @@ public class BlockMenus implements DragClient {
763
788
if (selection == 'clear senders/receivers' ) sprites = [];
764
789
app. highlightSprites(sprites);
765
790
}
791
+
766
792
var m: Menu = new Menu (showBroadcasts, 'broadcastInfo' );
767
793
addGenericBlockItems(m);
768
794
if (! isInPalette(block)) {
@@ -773,4 +799,13 @@ public class BlockMenus implements DragClient {
773
799
showMenu(m);
774
800
}
775
801
802
+ // ***** Custom menu *****
803
+
804
+ private function customMenu (evt :MouseEvent ,menuItems :Array ):void {
805
+ var m: Menu = new Menu (setBlockArg);
806
+ for each (var s: String in menuItems) {
807
+ m. addItem (s);
808
+ }
809
+ showMenu(m);
810
+ }
776
811
}}
0 commit comments