viewSelector: Allow to start navigating results using arrow keys

We currently require users to tab away from the search entry before
search results can be navigated using arrow keys. For convenience,
support using arrow keys directly from the entry.

https://bugzilla.gnome.org/show_bug.cgi?id=663901
This commit is contained in:
Florian Müllner 2012-03-10 03:40:46 +01:00
parent 700f706428
commit 384c7e2c17
2 changed files with 28 additions and 4 deletions

View File

@ -266,6 +266,7 @@ const SearchResults = new Lang.Class({
button.activate = Lang.bind(this, function() {
this._openSearchSystem.activateResult(provider.id);
});
button.actor = button;
this._searchProvidersBox.add(button);
},
@ -450,13 +451,21 @@ const SearchResults = new Lang.Class({
},
navigateFocus: function(direction) {
if (direction == Gtk.DirectionType.TAB_FORWARD && this._defaultResult) {
let rtl = this.actor.get_text_direction() == Clutter.TextDirection.RTL;
if (direction == Gtk.DirectionType.TAB_BACKWARD ||
direction == (rtl ? Gtk.DirectionType.RIGHT
: Gtk.DirectionType.LEFT) ||
direction == Gtk.DirectionType.UP) {
this.actor.navigate_focus(null, direction, false);
return;
}
let from = this._defaultResult ? this._defaultResult.actor : null;
this.actor.navigate_focus(from, direction, false);
if (this._defaultResult) {
// The default result appears focused, so navigate directly to the
// next result.
this.actor.navigate_focus(null, direction, false);
this.actor.navigate_focus(global.stage.key_focus, direction, false);
} else {
this.actor.navigate_focus(null, direction, false);
}
}
});

View File

@ -292,6 +292,15 @@ const SearchTab = new Lang.Class({
return true;
}
} else if (this.active) {
let arrowNext, nextDirection;
if (entry.get_text_direction() == Clutter.TextDirection.RTL) {
arrowNext = Clutter.Left;
nextDirection = Gtk.DirectionType.LEFT;
} else {
arrowNext = Clutter.Right;
nextDirection = Gtk.DirectionType.RIGHT;
}
if (symbol == Clutter.Tab) {
this._searchResults.navigateFocus(Gtk.DirectionType.TAB_FORWARD);
return true;
@ -300,6 +309,12 @@ const SearchTab = new Lang.Class({
this._searchResults.navigateFocus(Gtk.DirectionType.TAB_BACKWARD);
this._focusTrap.can_focus = true;
return true;
} else if (symbol == Clutter.Down) {
this._searchResults.navigateFocus(Gtk.DirectionType.DOWN);
return true;
} else if (symbol == arrowNext && this._text.position == -1) {
this._searchResults.navigateFocus(nextDirection);
return true;
}
}
return false;