[gnome-documents] epubview: Create the entire bar in one place



commit 1697514303e361d635686e801add1d840a6c65f7
Author: Debarshi Ray <debarshir gnome org>
Date:   Thu Jun 1 14:51:04 2017 +0200

    epubview: Create the entire bar in one place
    
    It's semantically cleaner to consolidate the creation of the entire
    bar in createBarWidget.
    
    More practically, if we ever use something more sophisticated than a
    GtkBox, then the whole thing might be instantiated in createBarWidget
    anyway. In fact, we might have to do that now to implement
    hover-handling for the bar in a way similar to GdNavBar.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=782685

 src/epubview.js |   50 +++++++++++++++++++++++++++++++-------------------
 1 files changed, 31 insertions(+), 19 deletions(-)
---
diff --git a/src/epubview.js b/src/epubview.js
index baeb64e..7f146dc 100644
--- a/src/epubview.js
+++ b/src/epubview.js
@@ -204,22 +204,19 @@ const EPUBViewNavControls = new Lang.Class({
     Name: 'EPUBViewNavControls',
     Extends: Preview.PreviewNavControls,
 
-    setDocument: function(epubdoc) {
-        this._label = new Gtk.Label();
-        this._level = Gtk.Scale.new_with_range(Gtk.Orientation.HORIZONTAL, 1,
-                                               this.preview.numPages, 1.0);
-        this._level.set_draw_value(false);
-        this._level.set_digits(0);
-
-        this.barWidget.add(this._label);
-        this.barWidget.pack_start(this._level, true, true, 5);
+    _init: function(preview, overlay) {
+        this._epubdoc = null;
+        this.parent(preview, overlay);
+    },
 
-        this._level.connect('value-changed', Lang.bind(this, function() {
-            epubdoc.set_page(this._level.get_value() - 1);
-        }));
+    setDocument: function(epubdoc) {
+        this._epubdoc = epubdoc;
 
-        epubdoc.connect('notify::page', Lang.bind(this, this._updatePage));
-        this._updatePage();
+        if (this._epubdoc != null) {
+            this._level.set_range(1.0, this.preview.numPages);
+            this._epubdoc.connect('notify::page', Lang.bind(this, this._updatePage));
+            this._updatePage();
+        }
     },
 
     _updatePage: function() {
@@ -232,11 +229,26 @@ const EPUBViewNavControls = new Lang.Class({
     },
 
     createBarWidget: function() {
-        return new EPUBBarWidget({ orientation: Gtk.Orientation.HORIZONTAL,
-                                   spacing: 10,
-                                   margin: Preview.PREVIEW_NAVBAR_MARGIN,
-                                   valign: Gtk.Align.END,
-                                   opacity: 0 });
+        let barWidget = new EPUBBarWidget({ orientation: Gtk.Orientation.HORIZONTAL,
+                                            spacing: 10,
+                                            margin: Preview.PREVIEW_NAVBAR_MARGIN,
+                                            valign: Gtk.Align.END,
+                                            opacity: 0 });
+
+        this._label = new Gtk.Label();
+        barWidget.add(this._label);
+
+        this._level = new Gtk.Scale({ orientation: Gtk.Orientation.HORIZONTAL });
+        this._level.set_increments(1.0, 1.0);
+        this._level.set_draw_value(false);
+        this._level.set_digits(0);
+        barWidget.pack_start(this._level, true, true, 5);
+        this._level.connect('value-changed', Lang.bind(this, function() {
+            if (this._epubdoc != null)
+                this._epubdoc.set_page(this._level.get_value() - 1);
+        }));
+
+        return barWidget;
     }
 });
 


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