keyboard: Use common code to create regular and extension key buttons

The code is almost the same, so pull this out to a generic _makeKey(), and
use it from both places.

https://bugzilla.gnome.org/show_bug.cgi?id=733633
This commit is contained in:
Carlos Garnacho 2014-07-22 12:38:44 +02:00
parent 38d05a8285
commit 69d5cef3b2

View File

@ -52,8 +52,7 @@ const Key = new Lang.Class({
_init : function(key) { _init : function(key) {
this._key = key; this._key = key;
this.actor = this._makeKey(key, GLib.markup_escape_text(key.label, -1));
this.actor = this._makeKey();
this._extended_keys = this._key.get_extended_keys(); this._extended_keys = this._key.get_extended_keys();
this._extended_keyboard = null; this._extended_keyboard = null;
@ -76,20 +75,19 @@ const Key = new Lang.Class({
} }
}, },
_makeKey: function () { _makeKey: function (key, label) {
let label = GLib.markup_escape_text(this._key.label, -1);
let button = new St.Button ({ label: label, let button = new St.Button ({ label: label,
style_class: 'keyboard-key' }); style_class: 'keyboard-key' });
button.key_width = this._key.width; button.key_width = this._key.width;
button.connect('button-press-event', Lang.bind(this, button.connect('button-press-event', Lang.bind(this,
function () { function () {
this._key.press(); key.press();
return Clutter.EVENT_PROPAGATE; return Clutter.EVENT_PROPAGATE;
})); }));
button.connect('button-release-event', Lang.bind(this, button.connect('button-release-event', Lang.bind(this,
function () { function () {
this._key.release(); key.release();
return Clutter.EVENT_PROPAGATE; return Clutter.EVENT_PROPAGATE;
})); }));
@ -112,18 +110,9 @@ const Key = new Lang.Class({
for (let i = 0; i < this._extended_keys.length; ++i) { for (let i = 0; i < this._extended_keys.length; ++i) {
let extended_key = this._extended_keys[i]; let extended_key = this._extended_keys[i];
let label = this._getUnichar(extended_key); let label = this._getUnichar(extended_key);
let key = new St.Button({ label: label, style_class: 'keyboard-key' }); let key = this._makeKey(extended_key, label);
key.extended_key = extended_key; key.extended_key = extended_key;
key.connect('button-press-event', Lang.bind(this,
function () {
extended_key.press();
return Clutter.EVENT_PROPAGATE;
}));
key.connect('button-release-event', Lang.bind(this,
function () {
extended_key.release();
return Clutter.EVENT_PROPAGATE;
}));
this._extended_keyboard.add(key); this._extended_keyboard.add(key);
} }
this._boxPointer.bin.add_actor(this._extended_keyboard); this._boxPointer.bin.add_actor(this._extended_keyboard);