kopia lustrzana https://github.com/backface/turtlestitch
dynamic extension dropdown menu support
rodzic
990911b295
commit
3ba7e62e7a
|
@ -15,6 +15,7 @@
|
|||
* tweaked strings library
|
||||
* extensions: added color library dropdown menu
|
||||
* blocks, threads, extensions: separated extension primitives from extension dropdown menus
|
||||
* blocks, byob: dynamic extension dropdown menu support
|
||||
|
||||
### 2021-06-17
|
||||
* extensions: added APL extension primitives
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
<script src="src/gui.js?version=2021-06-14"></script>
|
||||
<script src="src/paint.js?version=2020-05-17"></script>
|
||||
<script src="src/lists.js?version=2021-03-15"></script>
|
||||
<script src="src/byob.js?version=2021-06-11"></script>
|
||||
<script src="src/byob.js?version=2021-06-18"></script>
|
||||
<script src="src/tables.js?version=2021-03-05"></script>
|
||||
<script src="src/sketch.js?version=2020-07-13"></script>
|
||||
<script src="src/video.js?version=2019-06-27"></script>
|
||||
|
|
|
@ -9082,6 +9082,7 @@ InputSlotMorph.prototype.menuFromDict = function (
|
|||
{
|
||||
var key, dial, flag,
|
||||
myself = this,
|
||||
selector,
|
||||
block = this.parentThatIsA(BlockMorph),
|
||||
ide = this.parentThatIsA(IDE_Morph),
|
||||
menu = new MenuMorph(
|
||||
|
@ -9110,7 +9111,18 @@ InputSlotMorph.prototype.menuFromDict = function (
|
|||
}
|
||||
choices = choices.call(this);
|
||||
} else if (isString(choices)) {
|
||||
choices = this[choices]();
|
||||
if (choices.indexOf('ext_') === 0) {
|
||||
selector = choices.slice(4);
|
||||
choices = SnapExtensions.menus.get(selector);
|
||||
if (choices) {
|
||||
choices = choices.call(this);
|
||||
} else {
|
||||
menu.addItem('cannot find extension menu "' + selector + '"');
|
||||
return menu;
|
||||
}
|
||||
} else {
|
||||
choices = this[choices]();
|
||||
}
|
||||
if (!choices) { // menu has already happened
|
||||
return;
|
||||
}
|
||||
|
|
41
src/byob.js
41
src/byob.js
|
@ -102,11 +102,11 @@ nop, radians, BoxMorph, ArrowMorph, PushButtonMorph, contains, InputSlotMorph,
|
|||
ToggleButtonMorph, IDE_Morph, MenuMorph, ToggleElementMorph, fontHeight, isNil,
|
||||
StageMorph, SyntaxElementMorph, CommentMorph, localize, CSlotMorph, Variable,
|
||||
MorphicPreferences, SymbolMorph, CursorMorph, VariableFrame, BooleanSlotMorph,
|
||||
WatcherMorph, XML_Serializer, SnapTranslator*/
|
||||
WatcherMorph, XML_Serializer, SnapTranslator, SnapExtensions*/
|
||||
|
||||
// Global stuff ////////////////////////////////////////////////////////
|
||||
|
||||
modules.byob = '2021-June-11';
|
||||
modules.byob = '2021-June-18';
|
||||
|
||||
// Declarations
|
||||
|
||||
|
@ -331,7 +331,7 @@ CustomBlockDefinition.prototype.dropDownMenuOf = function (inputName) {
|
|||
'directionDialMenu'
|
||||
],
|
||||
fname
|
||||
)) {
|
||||
) || fname.indexOf('ext_') === 0) {
|
||||
return fname;
|
||||
}
|
||||
}
|
||||
|
@ -2749,6 +2749,13 @@ BlockLabelFragment.prototype.hasSpecialMenu = function () {
|
|||
);
|
||||
};
|
||||
|
||||
BlockLabelFragment.prototype.hasExtensionMenu = function () {
|
||||
return contains(
|
||||
Array.from(SnapExtensions.menus.keys()).map(str => '§_ext_' + str),
|
||||
this.options
|
||||
);
|
||||
};
|
||||
|
||||
// arity
|
||||
|
||||
BlockLabelFragment.prototype.isSingleInput = function () {
|
||||
|
@ -3741,6 +3748,13 @@ InputSlotDialogMorph.prototype.addSlotsMenu = function () {
|
|||
localize('special'),
|
||||
this.specialSlotsMenu()
|
||||
);
|
||||
if (this.world().currentKey === 16) { // shift-key down
|
||||
menu.addMenu(
|
||||
(this.fragment.hasExtensionMenu() ? on : off) +
|
||||
localize('extension'),
|
||||
this.extensionOptionsMenu()
|
||||
);
|
||||
}
|
||||
return menu;
|
||||
}
|
||||
return this.specialSlotsMenu();
|
||||
|
@ -3808,6 +3822,27 @@ InputSlotDialogMorph.prototype.specialOptionsMenu = function () {
|
|||
return menu;
|
||||
};
|
||||
|
||||
InputSlotDialogMorph.prototype.extensionOptionsMenu = function () {
|
||||
var menu = new MenuMorph(this.setSlotOptions, null, this),
|
||||
myself = this,
|
||||
selectors = Array.from(SnapExtensions.menus.keys()),
|
||||
on = '\u26AB ',
|
||||
off = '\u26AA ';
|
||||
|
||||
function addSpecialOptions(label, selector) {
|
||||
menu.addItem(
|
||||
(myself.fragment.options === selector ?
|
||||
on : off) + localize(label),
|
||||
selector
|
||||
);
|
||||
}
|
||||
|
||||
selectors.forEach(sel => {
|
||||
addSpecialOptions(sel.slice(4), '§_ext_' + sel);
|
||||
});
|
||||
return menu;
|
||||
};
|
||||
|
||||
// InputSlotDialogMorph hiding and showing:
|
||||
|
||||
/*
|
||||
|
|
Ładowanie…
Reference in New Issue