[gnome-shell/wip/re-search: 447/457] searchDisplay: Set can_focus on provider icon only if its results have focus



commit faa306f9e18024b431fc48a777842029b83a4fd9
Author: Tanner Doshier <doshitan gmail com>
Date:   Wed Aug 8 11:10:00 2012 -0500

    searchDisplay: Set can_focus on provider icon only if its results have focus
    
    This way, the search results take priority, but while the user is in the
    search section, they can navigate to that provider icon to launch a search.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=681797

 js/ui/searchDisplay.js |   35 ++++++++++++++++++++++++++++++++++-
 1 files changed, 34 insertions(+), 1 deletions(-)
---
diff --git a/js/ui/searchDisplay.js b/js/ui/searchDisplay.js
index 36a793e..1ba4dcb 100644
--- a/js/ui/searchDisplay.js
+++ b/js/ui/searchDisplay.js
@@ -4,6 +4,7 @@ const Clutter = imports.gi.Clutter;
 const Lang = imports.lang;
 const Gtk = imports.gi.Gtk;
 const Meta = imports.gi.Meta;
+const Signals = imports.signals;
 const St = imports.gi.St;
 const Atk = imports.gi.Atk;
 
@@ -145,6 +146,8 @@ const ListSearchResults = new Lang.Class({
         for (let i = 0; i < metas.length; i++) {
             let display = new ListSearchResult(this.provider, metas[i], this._terms);
             this.addItem(display.actor);
+
+            display.actor.connect('key-focus-in', Lang.bind(this, this._onFocusedProviderChanged));
         }
     },
 
@@ -169,8 +172,13 @@ const ListSearchResults = new Lang.Class({
 
     getItemAtIndex: function(index) {
         return this.actor.get_child_at_index(index);
+    },
+
+    _onFocusedProviderChanged: function() {
+        this.emit('focused-provider-changed');
     }
 });
+Signals.addSignalMethods(ListSearchResults.prototype);
 
 
 const GridSearchResult = new Lang.Class({
@@ -316,6 +324,8 @@ const GridSearchResults = new Lang.Class({
         for (let i = 0; i < metas.length; i++) {
             let display = new GridSearchResult(this.provider, metas[i], this._terms);
             this._grid.addItem(display.actor);
+
+            display.content.connect('key-focus-in', Lang.bind(this, this._onFocusedProviderChanged));
         }
     },
 
@@ -329,8 +339,14 @@ const GridSearchResults = new Lang.Class({
             return this._grid.getItemAtIndex(0)._delegate;
         else
             return null;
+    },
+
+    _onFocusedProviderChanged: function() {
+        this.emit('focused-provider-changed');
     }
 });
+Signals.addSignalMethods(GridSearchResults.prototype);
+
 
 const SearchDisplay = new Lang.Class({
     Name: 'SearchDisplay',
@@ -414,6 +430,8 @@ const SearchDisplay = new Lang.Class({
             resultDisplay = new GridSearchResults(provider);
         else
             resultDisplay = new ListSearchResults(provider);
+
+        resultDisplay.connect('focused-provider-changed', Lang.bind(this, this._updateProviderIconCanFocus));
         resultDisplayBin.set_child(resultDisplay.actor);
 
         this._providerMeta.push({ provider: provider,
@@ -439,6 +457,7 @@ const SearchDisplay = new Lang.Class({
             let meta = this._providerMeta[i];
             meta.resultDisplay.clear();
             meta.actor.hide();
+            if (meta.icon) meta.icon.actor.can_focus = false;
         }
     },
 
@@ -446,6 +465,7 @@ const SearchDisplay = new Lang.Class({
         let meta = this._metaForProvider(provider);
         meta.resultDisplay.clear();
         meta.actor.hide();
+        if (meta.icon) meta.icon.actor.can_focus = false;
     },
 
     reset: function() {
@@ -468,6 +488,11 @@ const SearchDisplay = new Lang.Class({
         return this._providerMeta[this._providers.indexOf(provider)];
     },
 
+    _metaForProvidersExcept: function(provider) {
+        let skip = this._providers.indexOf(provider);
+        return this._providerMeta.filter(function(meta, index) { return index != skip }, this);
+    },
+
     _maybeSetInitialSelection: function() {
         let newDefaultResult = null;
 
@@ -561,6 +586,15 @@ const SearchDisplay = new Lang.Class({
             this._defaultResult.setSelected(highlight);
     },
 
+    _updateProviderIconCanFocus: function(resultDisplay) {
+        let meta = this._metaForProvider(resultDisplay.provider);
+        if (meta.icon)
+            meta.icon.actor.can_focus = true;
+
+        let others = this._metaForProvidersExcept(resultDisplay.provider);
+        others.forEach(function(meta) { if (meta.icon) meta.icon.actor.can_focus = false; });
+    },
+
     navigateFocus: function(direction) {
         let rtl = this.actor.get_text_direction() == Clutter.TextDirection.RTL;
         if (direction == Gtk.DirectionType.TAB_BACKWARD ||
@@ -593,7 +627,6 @@ const ProviderIcon = new Lang.Class({
 
         this.actor = new St.Button({ style_class: 'search-section-icon-bin',
                                      reactive: true,
-                                     can_focus: true,
                                      track_hover: true });
         this.actor.connect('clicked', Lang.bind(this, this._onIconClicked));
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]