[gnome-documents] preview: The toolbar is created after load-{started, finished}



commit a4a422db184defaa5ce5d48ebac9a278bbc96ecb
Author: Debarshi Ray <debarshir gnome org>
Date:   Mon Feb 24 10:30:35 2014 +0100

    preview: The toolbar is created after load-{started, finished}
    
    Fallout from cde99212000c2f2b0beb29d66956aad7b791b44e
    
    https://bugzilla.gnome.org/show_bug.cgi?id=700716

 src/preview.js |   34 +++++++++++++++-------------------
 1 files changed, 15 insertions(+), 19 deletions(-)
---
diff --git a/src/preview.js b/src/preview.js
index da7de03..7a0966f 100644
--- a/src/preview.js
+++ b/src/preview.js
@@ -783,8 +783,14 @@ const PreviewToolbar = new Lang.Class({
         this.parent();
         this.toolbar.set_show_close_button(true);
 
+        this._handleEvent = false;
+        this._model = null;
+
         this._searchAction = Application.application.lookup_action('search');
+        this._searchAction.enabled = false;
+
         this._gearMenu = Application.application.lookup_action('gear-menu');
+        this._gearMenu.enabled = true;
 
         // back button, on the left of the toolbar
         let backButton = this.addBackButton();
@@ -807,29 +813,17 @@ const PreviewToolbar = new Lang.Class({
         this._setToolbarTitle();
         this.toolbar.show_all();
 
-        let loadStartId =
-            Application.documentManager.connect('load-started',
-                Lang.bind(this, this._onLoadStarted));
-        let loadFinishId =
-            Application.documentManager.connect('load-finished',
-                Lang.bind(this, this._onLoadFinished));
-
-        this.widget.connect('destroy',
+        this.widget.connect('destroy', Lang.bind(this,
             function() {
-                Application.documentManager.disconnect(loadStartId);
-                Application.documentManager.disconnect(loadFinishId);
-            });
-    },
-
-    _onLoadStarted: function() {
-        this._gearMenu.enabled = false;
-        this._searchAction.enabled = false;
+                this._searchAction.enabled = true;
+            }));
     },
 
-    _onLoadFinished: function(manager, doc, docModel) {
-        this._gearMenu.enabled = true;
+    _enableSearch: function() {
+        if (!this._model)
+            return;
 
-        let evDoc = docModel.get_document();
+        let evDoc = this._model.get_document();
         let hasPages = (evDoc.get_n_pages() > 0);
         let isFind = true;
 
@@ -843,6 +837,7 @@ const PreviewToolbar = new Lang.Class({
         } catch (e) {
         }
 
+        this._handleEvent = (hasPages && isFind);
         this._searchAction.enabled = (hasPages && isFind);
     },
 
@@ -880,6 +875,7 @@ const PreviewToolbar = new Lang.Class({
             return;
 
         this._model = model;
+        this._enableSearch();
         this._setToolbarTitle();
     }
 });


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