Grab focus in the summary notification

Because clicking on the summary item to have it display its notification
is a more deliberate action than hovering, we can now grab focus in that
notification. This makes chat notifications in the summary more convenient
to use because you don't need to click on the text entry there.

We pop down the notification when the user clicks anywhere outside of it,
triggers the overview, or the run dialog.

https://bugzilla.gnome.org/show_bug.cgi?id=617224
This commit is contained in:
Marina Zhurakhinskaya
2010-07-21 00:42:37 -04:00
parent b2185eb2b1
commit 46906eef43
2 changed files with 146 additions and 55 deletions

View File

@ -577,10 +577,9 @@ Notification.prototype = {
_init: function(id, source) {
MessageTray.Notification.prototype._init.call(this, id, source, source.title);
this.actor.connect('button-press-event', Lang.bind(this, this._onButtonPress));
this._responseEntry = new St.Entry({ style_class: 'chat-response' });
this._responseEntry.clutter_text.connect('key-focus-in', Lang.bind(this, this._onEntryFocused));
this._responseEntry.clutter_text.connect('key-focus-in', Lang.bind(this, this.grabFocus));
this._responseEntry.clutter_text.connect('activate', Lang.bind(this, this._onEntryActivated));
this.setActionArea(this._responseEntry);
@ -621,60 +620,20 @@ Notification.prototype = {
}
},
_onButtonPress: function(notification, event) {
if (!this._active)
return false;
let source = event.get_source ();
if (source && notification.contains(source))
return false;
// @source is outside @notification, which has to mean that
// we have a pointer grab, and the user clicked outside the
// notification, so we should deactivate.
this._deactivate();
return true;
},
_onEntryFocused: function() {
if (this._active)
return;
if (!Main.pushModal(this.actor))
return;
Clutter.grab_pointer(this.actor);
this._active = true;
Main.messageTray.lock();
grabFocus: function() {
// Need to call the base class function first so that
// it saves where the key focus was before.
MessageTray.Notification.prototype.grabFocus.call(this);
global.stage.set_key_focus(this._responseEntry.clutter_text);
},
_onEntryActivated: function() {
let text = this._responseEntry.get_text();
if (text == '') {
this._deactivate();
if (text == '')
return;
}
this._responseEntry.set_text('');
this._append(text, 'chat-sent');
this.source.respond(text);
},
_deactivate: function() {
if (this._active) {
Clutter.ungrab_pointer(this.actor);
Main.popModal(this.actor);
global.stage.set_key_focus(null);
// We have to do this after calling popModal(), because
// that will return the keyboard focus to
// this._responseEntry (because that's where it was when
// pushModal() was called), which will cause
// _onEntryFocused() to be called again, but we don't want
// it to do anything.
this._active = false;
Main.messageTray.unlock();
}
}
};