[gnome-shell/wip/paging-release2: 8/22] appDisplay: Makes key navigation works with pagination



commit 0b3e48c4ba36050bf94746811961f95b69ab3e07
Author: Carlos Soriano <carlos soriano89 gmail com>
Date:   Fri Aug 23 20:06:47 2013 +0200

    appDisplay: Makes key navigation works with pagination
    
    We have to rewrite the ensureIconVisibility function
    to change pages when we reach an item inside another
    page than the current
    
    https://bugzilla.gnome.org/show_bug.cgi?id=706081

 js/ui/appDisplay.js |   15 +++++++++++++--
 js/ui/iconGrid.js   |   19 +++++++++++++++++++
 2 files changed, 32 insertions(+), 2 deletions(-)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index cc8119b..c0daa2e 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -261,11 +261,17 @@ const AllView = new Lang.Class({
     },
 
     addApp: function(app) {
-        this._addItem(app);
+        let appIcon = this._addItem(app);
+        if (appIcon)
+            appIcon.actor.connect('key-focus-in',
+                                  Lang.bind(this, this._ensureIconVisible));
     },
 
     addFolder: function(dir) {
-        this._addItem(dir);
+        let folderIcon = this._addItem(dir);
+        if (folderIcon)
+            folderIcon.actor.connect('key-focus-in',
+                                     Lang.bind(this, this._ensureIconVisible));
     },
 
     addFolderPopup: function(popup) {
@@ -278,6 +284,11 @@ const AllView = new Lang.Class({
             }));
     },
 
+    _ensureIconVisible: function(icon) {
+        let itemPage = this._grid.getItemPage(icon);
+        this.goToPage(itemPage);
+    },
+
     updateAdjustment: function(availHeight) {
         this._verticalAdjustment.page_size = availHeight;
         this._verticalAdjustment.upper = this._stack.height;
diff --git a/js/ui/iconGrid.js b/js/ui/iconGrid.js
index 3db1d43..78c27e4 100644
--- a/js/ui/iconGrid.js
+++ b/js/ui/iconGrid.js
@@ -542,6 +542,25 @@ const PaginatedIconGrid = new Lang.Class({
         let firstPageItem = pageNumber * this._childrenPerPage
         let childBox = this._getVisibleChildren()[firstPageItem].get_allocation_box();
         return childBox.y1;
+    },
+
+    getItemPage: function(item) {
+        let found = false;
+        let children = this._getVisibleChildren();
+        pageNumber = 0;
+        let index = 0;
+        while(!found && index < children.length) {
+            if(item == children[index])
+                found = true;
+            if(index % this._childrenPerPage == 0 && index != 0)
+                pageNumber++;
+            index++;
+        }
+        if(!found) {
+            throw new Error('Invalid item position requested');
+            return 0;
+        }
+        return pageNumber;
     }
 });
 Signals.addSignalMethods(PaginatedIconGrid.prototype);


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