popupMenu: Handle key-press events on sourceActor

The behavior of opening/closing/navigating a menu from its source
actor is generic enough to not limit it to PanelMenu.Buttons, so
move the code into PopupMenu itself.

https://bugzilla.gnome.org/show_bug.cgi?id=735614
This commit is contained in:
Florian Müllner 2014-08-28 17:04:23 +02:00
parent 9de05994db
commit 1d58ea25ab
2 changed files with 28 additions and 21 deletions

View File

@ -101,7 +101,6 @@ const Button = new Lang.Class({
accessible_role: Atk.Role.MENU }); accessible_role: Atk.Role.MENU });
this.actor.connect('event', Lang.bind(this, this._onEvent)); this.actor.connect('event', Lang.bind(this, this._onEvent));
this.actor.connect('key-press-event', Lang.bind(this, this._onSourceKeyPress));
this.actor.connect('notify::visible', Lang.bind(this, this._onVisibilityChanged)); this.actor.connect('notify::visible', Lang.bind(this, this._onVisibilityChanged));
if (dontCreateMenu) if (dontCreateMenu)
@ -140,26 +139,6 @@ const Button = new Lang.Class({
return Clutter.EVENT_PROPAGATE; return Clutter.EVENT_PROPAGATE;
}, },
_onSourceKeyPress: function(actor, event) {
if (!this.menu)
return Clutter.EVENT_PROPAGATE;
let symbol = event.get_key_symbol();
if (symbol == Clutter.KEY_space || symbol == Clutter.KEY_Return) {
this.menu.toggle();
return Clutter.EVENT_STOP;
} else if (symbol == Clutter.KEY_Escape && this.menu.isOpen) {
this.menu.close();
return Clutter.EVENT_STOP;
} else if (symbol == Clutter.KEY_Down) {
if (!this.menu.isOpen)
this.menu.toggle();
this.menu.actor.navigate_focus(this.actor, Gtk.DirectionType.DOWN, false);
return Clutter.EVENT_STOP;
} else
return Clutter.EVENT_PROPAGATE;
},
_onVisibilityChanged: function() { _onVisibilityChanged: function() {
if (!this.menu) if (!this.menu)
return; return;

View File

@ -731,6 +731,10 @@ const PopupMenu = new Lang.Class({
global.focus_manager.add_group(this.actor); global.focus_manager.add_group(this.actor);
this.actor.reactive = true; this.actor.reactive = true;
if (this.sourceActor)
this._keyPressId = this.sourceActor.connect('key-press-event',
Lang.bind(this, this._onKeyPress));
this._openedSubMenu = null; this._openedSubMenu = null;
}, },
@ -741,6 +745,24 @@ const PopupMenu = new Lang.Class({
this._openedSubMenu = submenu; this._openedSubMenu = submenu;
}, },
_onKeyPress: function(actor, event) {
let symbol = event.get_key_symbol();
if (symbol == Clutter.KEY_space || symbol == Clutter.KEY_Return) {
this.toggle();
return Clutter.EVENT_STOP;
} else if (symbol == Clutter.KEY_Escape && this.isOpen) {
this.close();
return Clutter.EVENT_STOP;
} else if (symbol == Clutter.KEY_Down) {
if (!this.isOpen)
this.toggle();
this.actor.navigate_focus(actor, Gtk.DirectionType.DOWN, false);
return Clutter.EVENT_STOP;
} else
return Clutter.EVENT_PROPAGATE;
},
setArrowOrigin: function(origin) { setArrowOrigin: function(origin) {
this._boxPointer.setArrowOrigin(origin); this._boxPointer.setArrowOrigin(origin);
}, },
@ -781,6 +803,12 @@ const PopupMenu = new Lang.Class({
this.isOpen = false; this.isOpen = false;
this.emit('open-state-changed', false); this.emit('open-state-changed', false);
},
destroy: function() {
if (this._keyPressId)
this.sourceActor.disconnect(this._keyPressId);
this.parent();
} }
}); });