[gnome-documents] view: Replace "Load more" button with edge hit detection



commit a04f842d8c25d4bb6c25663cba106c89d1e5c896
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun Oct 12 15:37:27 2014 +0200

    view: Replace "Load more" button with edge hit detection
    
    If scrolling happens towards the bottom of the view, further elements
    are loaded.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=738881

 configure.ac |    2 +-
 src/view.js  |  127 ++++------------------------------------------------------
 2 files changed, 9 insertions(+), 120 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 9a14b44..9b5a227 100644
--- a/configure.ac
+++ b/configure.ac
@@ -52,7 +52,7 @@ AC_SUBST(LIBM)
 EVINCE_MIN_VERSION=3.13.3
 WEBKITGTK_MIN_VERSION=1.10.0
 GLIB_MIN_VERSION=2.39.3
-GTK_MIN_VERSION=3.13.2
+GTK_MIN_VERSION=3.15.0
 GOBJECT_INTROSPECTION_MIN_VERSION=1.31.6
 GDATA_MIN_VERSION=0.13.3
 GOA_MIN_VERSION=3.2.0
diff --git a/src/view.js b/src/view.js
index ad671f3..196065d 100644
--- a/src/view.js
+++ b/src/view.js
@@ -37,74 +37,6 @@ const TrackerUtils = imports.trackerUtils;
 const WindowMode = imports.windowMode;
 const Utils = imports.utils;
 
-const LoadMoreButton = new Lang.Class({
-    Name: 'LoadMoreButton',
-
-    _init: function() {
-        this._block = false;
-
-        this._controller = Application.offsetController;
-        this._controllerId =
-            this._controller.connect('item-count-changed',
-                                     Lang.bind(this, this._onItemCountChanged));
-
-        let child = new Gtk.Grid({ column_spacing: 10,
-                                   hexpand: true,
-                                   halign: Gtk.Align.CENTER,
-                                   visible: true });
-
-        this._spinner = new Gtk.Spinner({ halign: Gtk.Align.CENTER,
-                                          no_show_all: true });
-        this._spinner.set_size_request(16, 16);
-        child.add(this._spinner);
-
-        // Translators: "more" refers to documents in this context
-        this._label = new Gtk.Label({ label: _("Load More"),
-                                      visible: true });
-        child.add(this._label);
-
-        this.widget = new Gtk.Button({ no_show_all: true,
-                                       child: child });
-        this.widget.get_style_context().add_class('documents-load-more');
-        this.widget.connect('clicked', Lang.bind(this,
-            function() {
-                this._label.label = _("Loading…");
-                this._spinner.show();
-                this._spinner.start();
-
-                this._controller.increaseOffset();
-            }));
-
-        this.widget.connect('destroy', Lang.bind(this,
-            function() {
-                this._controller.disconnect(this._controllerId);
-            }));
-
-        this._onItemCountChanged();
-    },
-
-    _onItemCountChanged: function() {
-        let remainingDocs = this._controller.getRemainingDocs();
-        let visible = !(remainingDocs <= 0 || this._block);
-        this.widget.set_visible(visible);
-
-        if (!visible) {
-            // Translators: "more" refers to documents in this context
-            this._label.label = _("Load More");
-            this._spinner.stop();
-            this._spinner.hide();
-        }
-    },
-
-    setBlock: function(block) {
-        if (this._block == block)
-            return;
-
-        this._block = block;
-        this._onItemCountChanged();
-    }
-});
-
 const ViewModel = new Lang.Class({
     Name: 'ViewModel',
 
@@ -193,9 +125,6 @@ const ViewContainer = new Lang.Class({
         this.view = new Gd.MainView({ shadow_type: Gtk.ShadowType.NONE });
         this.widget.add(this.view);
 
-        this._loadMore = new LoadMoreButton();
-        this.widget.add(this._loadMore.widget);
-
         this.widget.show_all();
 
         this.view.connect('item-activated',
@@ -413,57 +342,17 @@ const ViewContainer = new Lang.Class({
     },
 
     _connectView: function() {
-        this._adjustmentValueId =
-            this.view.vadjustment.connect('value-changed',
-                                          Lang.bind(this, this._onScrolledWinChange));
-        this._adjustmentChangedId =
-            this.view.vadjustment.connect('changed',
-                                          Lang.bind(this, this._onScrolledWinChange));
-        this._scrollbarVisibleId =
-            this.view.get_vscrollbar().connect('notify::visible',
-                                               Lang.bind(this, this._onScrolledWinChange));
-        this._onScrolledWinChange();
-    },
-
-    _onScrolledWinChange: function() {
-        let vScrollbar = this.view.get_vscrollbar();
-        let adjustment = this.view.vadjustment;
-        let revealAreaHeight = 32;
-
-        // if there's no vscrollbar, or if it's not visible, hide the button
-        if (!vScrollbar ||
-            !vScrollbar.get_visible()) {
-            this._loadMore.setBlock(true);
-            return;
-        }
-
-        let value = adjustment.value;
-        let upper = adjustment.upper;
-        let page_size = adjustment.page_size;
-
-        let end = false;
-
-        // special case this values which happen at construction
-        if ((value == 0) && (upper == 1) && (page_size == 1))
-            end = false;
-        else
-            end = !(value < (upper - page_size - revealAreaHeight));
-
-        this._loadMore.setBlock(!end);
+        this._edgeHitId = this.view.connect('edge-overshot', Lang.bind(this,
+            function (view, pos) {
+                if (pos == Gtk.PositionType.BOTTOM)
+                    Application.offsetController.increaseOffset();
+            }));
     },
 
     _disconnectView: function() {
-        if (this._adjustmentValueId != 0) {
-            this.view.vadjustment.disconnect(this._adjustmentValueId);
-            this._adjustmentValueId = 0;
-        }
-        if (this._adjustmentChangedId != 0) {
-            this.view.vadjustment.disconnect(this._adjustmentChangedId);
-            this._adjustmentChangedId = 0;
-        }
-        if (this._scrollbarVisibleId != 0) {
-            this.view.get_vscrollbar().disconnect(this._scrollbarVisibleId);
-            this._scrollbarVisibleId = 0;
+        if (this._edgeHitId != 0) {
+            this.view.disconnect(this._edgeHitId);
+            this._edgeHitId = 0;
         }
     }
 });


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