popupMenu: Fix algorithm for separator visibility to work with sections

Before, separators naively checked whether their siblings were visible
using actor visibility. However, if section actors are visible but have
no visible children, this will fail. Special-case separators when doing
visiblity checks.

https://bugzilla.gnome.org/show_bug.cgi?id=707801
This commit is contained in:
Jasper St. Pierre 2013-08-28 10:50:07 -04:00
parent fd9401cc62
commit 660f0fec16

View File

@ -35,6 +35,13 @@ function _ensureStyle(actor) {
actor.ensure_style(); actor.ensure_style();
} }
function isPopupMenuItemVisible(child) {
if (child._delegate instanceof PopupMenuSection)
if (child._delegate.isEmpty())
return false;
return child.visible;
}
const PopupBaseMenuItem = new Lang.Class({ const PopupBaseMenuItem = new Lang.Class({
Name: 'PopupBaseMenuItem', Name: 'PopupBaseMenuItem',
@ -437,7 +444,7 @@ const PopupMenuBase = new Lang.Class({
let hasVisibleChildren = this.box.get_children().some(function(child) { let hasVisibleChildren = this.box.get_children().some(function(child) {
if (child._delegate instanceof PopupSeparatorMenuItem) if (child._delegate instanceof PopupSeparatorMenuItem)
return false; return false;
return child.visible; return isPopupMenuItemVisible(child);
}); });
return !hasVisibleChildren; return !hasVisibleChildren;
@ -518,7 +525,7 @@ const PopupMenuBase = new Lang.Class({
let childBeforeIndex = index - 1; let childBeforeIndex = index - 1;
while (childBeforeIndex >= 0 && !children[childBeforeIndex].visible) while (childBeforeIndex >= 0 && !isPopupMenuItemVisible(children[childBeforeIndex]))
childBeforeIndex--; childBeforeIndex--;
if (childBeforeIndex < 0 if (childBeforeIndex < 0
@ -529,7 +536,7 @@ const PopupMenuBase = new Lang.Class({
let childAfterIndex = index + 1; let childAfterIndex = index + 1;
while (childAfterIndex < children.length && !children[childAfterIndex].visible) while (childAfterIndex < children.length && !isPopupMenuItemVisible(children[childAfterIndex]))
childAfterIndex++; childAfterIndex++;
if (childAfterIndex >= children.length if (childAfterIndex >= children.length