popup-menu: Allow updating combobox items with scroll wheel

Rather than opening the combobox menu, allow using the scroll wheel
to cycle through the visible items.

https://bugzilla.gnome.org/show_bug.cgi?id=657973
This commit is contained in:
Florian Müllner 2011-09-01 19:33:31 +02:00
parent 8c9eb6702d
commit 86aa4fe0a9

View File

@ -1507,6 +1507,10 @@ PopupComboMenu.prototype = {
}
this._getMenuItems()[position].actor.visible = visible;
},
getItemVisible: function(position) {
return this._getMenuItems()[position].actor.visible;
}
};
@ -1533,6 +1537,8 @@ PopupComboBoxMenuItem.prototype = {
if (params.style_class)
this._menu.actor.add_style_class_name(params.style_class);
this.actor.connect('scroll-event', Lang.bind(this, this._onScrollEvent));
this._activeItemPos = -1;
this._items = [];
},
@ -1551,6 +1557,33 @@ PopupComboBoxMenuItem.prototype = {
return null;
},
_onScrollEvent: function(actor, event) {
if (this._activeItemPos == -1)
return;
let position = this._activeItemPos;
let direction = event.get_scroll_direction();
if (direction == Clutter.ScrollDirection.DOWN) {
while (position < this._items.length - 1) {
position++;
if (this._menu.getItemVisible(position))
break;
}
} else if (direction == Clutter.ScrollDirection.UP) {
while (position > 0) {
position--;
if (this._menu.getItemVisible(position))
break;
}
}
if (position == this._activeItemPos)
return;
this.setActiveItem(position);
this.emit('active-item-changed', position);
},
activate: function(event) {
let topMenu = this._getTopMenu();
if (!topMenu)