responses to Michael's review

pull/29/head
brianharvey 2016-12-27 15:44:57 -08:00
rodzic 51aa5db3b0
commit fda6938f29
2 zmienionych plików z 40 dodań i 40 usunięć

Wyświetl plik

@ -7533,7 +7533,7 @@ InputSlotMorph.prototype.setContents = function (aStringOrFloat) {
InputSlotMorph.prototype.dropDownMenu = function (enableKeyboard) {
var choices = this.choices,
key,
menustack = [],
menuStack = [],
menu = new MenuMorph(
this.setContents,
null,
@ -7558,8 +7558,10 @@ InputSlotMorph.prototype.dropDownMenu = function (enableKeyboard) {
// menu.addItem(choices[key].blockInstance(), choices[key]);
} else if (key.charCodeAt(key.length - 1) == 0x25ba) {
// Submenu
// 0x25ba = Unicode "BLACK RIGHT-POINTING POINTER"
// (not to be confused with "black right-pointing TRIANGLE")
menu.addItem(key, choices[key]);
menustack.push(menu);
menuStack.push(menu);
menu = new MenuMorph(
this.setContents,
null,
@ -7567,23 +7569,24 @@ InputSlotMorph.prototype.dropDownMenu = function (enableKeyboard) {
this.fontSize
);
} else if (key.charCodeAt(0) == 0x25c4) {
var oldmenu=menustack[menustack.length-1],
// "BLACK LEFT-POINTING POINTER"
var oldmenu = menuStack[menuStack.length - 1],
items = oldmenu.items;
items[items.length - 1][6] = menu;
oldmenu.addChild(menu);
menu = menustack.pop();
menu = menuStack.pop();
} else {
menu.addItem(key, choices[key]);
}
}
}
while (menustack.length > 0) {
var oldmenu=menustack[menustack.length-1],
while (menuStack.length > 0) {
var oldmenu=menuStack[menuStack.length - 1],
items=oldmenu.items;
items[items.length-1][6] = menu;
oldmenu.addChild(menu);
menu = menustack.pop();
menu = menuStack.pop();
}
if (menu.items.length > 0) {

Wyświetl plik

@ -7683,6 +7683,10 @@ MenuMorph.prototype.unselectAllItems = function () {
};
MenuMorph.prototype.popup = function (world, pos, submenu) {
// submenu is True if this menu is a submenu,
// so that we don't make it the world's activeMenu nor
// destroy its parent menu.
this.drawNew();
this.setPosition(pos);
this.addShadow(new Point(2, 2), 80);
@ -7823,22 +7827,19 @@ MenuMorph.prototype.select = function (aMenuItem) {
MenuMorph.prototype.mouseLeave = function () {
if (this.parent instanceof MenuMorph) {
// this is a submenu so we vanish when lose focus
var mouses = this.world.hand.allMorphsAtPointer();
if (contains(mouses, this.parent)) {
var items = mouses.filter(function (morph)
{return morph instanceof MenuItemMorph});
if (items[0].doubleClickAction != this) {
this.destroy();
}
} else {
this.destroy();
}
}
}
MenuMorph.prototype.destroy = function () {
var myself = this;
var myself = this,
subitems = function(menu) {
return menu.children.filter(function (child) {
return (child instanceof MenuItemMorph) &&
(child.doubleClickAction instanceof MenuMorph);
} )
};
if (this.hasFocus) {
this.world.keyboardReceiver = null;
@ -7846,21 +7847,17 @@ var myself = this;
if ((this.parent instanceof MenuMorph) && this.world) {
// If I'm a submenu, un-highlight the item pointing to me.
var mouses = this.world.hand.allMorphsAtPointer(),
items = this.parent.children.filter(function (child) {
return (child instanceof MenuItemMorph) &&
(child.doubleClickAction instanceof MenuMorph) &&
!(contains(mouses, child)); });
items.forEach(function (item) {item.image = item.normalImage;
item.changed(); });
}
subitems(this.parent).forEach(function (item) {
item.image = item.normalImage;
item.changed();
} );
};
// Also kill my submenus if any.
var triggers = this.children.filter(function (each) {
return (each instanceof MenuItemMorph) &&
(each.doubleClickAction instanceof MenuMorph);
subitems(this).forEach(function (item) {
item.doubleClickAction.destroy();
});
triggers.forEach(function (item) {item.doubleClickAction.destroy();});
MenuMorph.uber.destroy.call(this);
};