[gnome-documents] embed: use a simpler logic for showing/hiding the Load More button



commit 62b8fd70149f5408041767966ed19c428f2bd1e1
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Mon Oct 31 11:24:54 2011 -0400

    embed: use a simpler logic for showing/hiding the Load More button
    
    Connect to both 'changed' and 'value-changed' from GtkAdjustment, and
    use a logic similar to the one of GtkRange to decide when to hide or
    show the load more button.
    Also, disconnect from the adjustment signals while we switch to a
    preview inside the embed.

 src/embed.js    |   72 +++++++++++++++++++++++++++++++++++-------------------
 src/loadMore.js |    3 ++
 2 files changed, 50 insertions(+), 25 deletions(-)
---
diff --git a/src/embed.js b/src/embed.js
index 8ecaebf..a688054 100644
--- a/src/embed.js
+++ b/src/embed.js
@@ -47,10 +47,13 @@ function ViewEmbed() {
 
 ViewEmbed.prototype  = {
     _init: function() {
+        this._adjustmentValueId = 0;
+        this._adjustmentChangedId = 0;
         this._loaderCancellable = null;
         this._loaderTimeout = 0;
         this._motionTimeoutId = 0;
         this._queryErrorId = 0;
+        this._scrollbarVisibleId = 0;
         this._viewSettingsId = 0;
 
         this._scrolledWinView = null;
@@ -271,42 +274,48 @@ ViewEmbed.prototype  = {
 
             this._initView();
 
-            this._scrolledWinView.vadjustment.connect('value-changed',
-                                                      Lang.bind(this, this._onAdjustmentChange));
-            this._onAdjustmentChange(this._scrolledWinView.vadjustment);
-
             grid.show_all();
             this._viewPage = this._notebook.append_page(grid, null);
         }
 
+        this._adjustmentValueId =
+            this._scrolledWinView.vadjustment.connect('value-changed',
+                                                      Lang.bind(this, this._onScrolledWinChange));
+        this._adjustmentChangedId =
+            this._scrolledWinView.vadjustment.connect('changed',
+                                                      Lang.bind(this, this._onScrolledWinChange));
+        this._scrollbarVisibleId =
+            this._scrolledWinView.get_vscrollbar().connect('notify::visible',
+                                                           Lang.bind(this, this._onScrolledWinChange));
+        this._onScrolledWinChange();
+
         this._notebook.set_current_page(this._viewPage);
     },
 
-    _onAdjustmentChange: function(adjustment) {
-        let end = (adjustment.value == (adjustment.upper - adjustment.get_page_size()));
+    _onScrolledWinChange: function() {
+        let vScrollbar = this._scrolledWinView.get_vscrollbar();
+        let adjustment = this._scrolledWinView.vadjustment;
 
-        // special case this values which happen at construction
-        if (adjustment.value == 0 &&
-            adjustment.upper == 1 &&
-            adjustment.get_page_size() == 1)
-            end = false;
+        // if there's no vscrollbar, or if it's not visible, hide the button
+        if (!vScrollbar ||
+            !vScrollbar.get_visible()) {
+            this._loadMore.setBlock(true);
+            return;
+        }
 
-        if (end) {
-            if (!this._adjChangedId) {
-                this._loadMore.setBlock(false);
+        let value = adjustment.value;
+        let upper = adjustment.upper;
+        let page_size = adjustment.page_size;
 
-                //wait for a changed event
-                this._adjChangedId = adjustment.connect('changed', Lang.bind(this,
-                    function(adjustment) {
-                        adjustment.disconnect(this._adjChangedId);
-                        this._adjChangedId = 0;
+        let end = false;
 
-                        this._loadMore.setBlock(true);
-                    }));
-            }
-        } else {
-            this._loadMore.setBlock(true);
-        }
+        // special case this values which happen at construction
+        if ((value == 0) && (upper == 1) && (page_size == 1))
+            end = false;
+        else
+            end = !(adjustment.value < (adjustment.upper - adjustment.page_size));
+
+        this._loadMore.setBlock(!end);
     },
 
     _onQueryError: function(manager, message, exception) {
@@ -331,6 +340,19 @@ ViewEmbed.prototype  = {
 
         Global.searchFilterController.setSearchVisible(false);
 
+        if (this._adjustmentValueId != 0) {
+            this._scrolledWinView.vadjustment.disconnect(this._adjustmentValueId);
+            this._adjustmentValueId = 0;
+        }
+        if (this._adjustmentChangedId != 0) {
+            this._scrolledWinView.vadjustment.disconnect(this._adjustmentChangedId);
+            this._adjustmentChangedId = 0;
+        }
+        if (this._scrollbarVisibleId != 0) {
+            this._scrolledWinView.get_vscrollbar().disconnect(this._scrollbarVisibleId);
+            this._scrollbarVisibleId = 0;
+        }
+
         if (!this._scrolledWinPreview) {
             this._scrolledWinPreview = new Gtk.ScrolledWindow({ hexpand: true,
                                                                 vexpand: true,
diff --git a/src/loadMore.js b/src/loadMore.js
index 0fc285e..48c7464 100644
--- a/src/loadMore.js
+++ b/src/loadMore.js
@@ -74,6 +74,9 @@ LoadMoreButton.prototype = {
     },
 
     setBlock: function(block) {
+        if (this._block == block)
+            return;
+
         this._block = block;
         this._onItemCountChanged();
     }



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