[gnome-documents] preview: Disable search if EvDocumentFind is not implemented



commit 3c5418c362c5a9a3eaf72d4d68e589633850b19c
Author: Debarshi Ray <debarshir gnome org>
Date:   Thu May 30 14:24:30 2013 +0200

    preview: Disable search if EvDocumentFind is not implemented
    
    We use a dummy call to a method to hack around the inability of the
    instanceof operator to work with interfaces.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=701264

 src/preview.js |   19 +++++++++++++++++--
 1 files changed, 17 insertions(+), 2 deletions(-)
---
diff --git a/src/preview.js b/src/preview.js
index 888aa65..b95567c 100644
--- a/src/preview.js
+++ b/src/preview.js
@@ -859,9 +859,24 @@ const PreviewToolbar = new Lang.Class({
         this._searchAction.enabled = false;
     },
 
-    _onLoadFinished: function() {
+    _onLoadFinished: function(manager, doc, docModel) {
         this._gearMenu.enabled = true;
-        this._searchAction.enabled = true;
+
+        let evDoc = docModel.get_document();
+        let hasPages = (evDoc.get_n_pages() > 0);
+        let isFind = true;
+
+        try {
+            // This is a hack to find out if evDoc implements the
+            // EvDocument.DocumentFind interface or not. We don't expect
+            // the following invocation to work.
+            evDoc.find_text();
+        } catch (e if e instanceof TypeError) {
+            isFind = false;
+        } catch (e) {
+        }
+
+        this._searchAction.enabled = (hasPages && isFind);
     },
 
     _getPreviewMenu: function() {


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