[gnome-documents/gnome-3-14] application, documents, edit: Disable Print menu item when unsupported



commit 0c46e25738cc6ce426441d84f8e6d2f9a2e67da9
Author: Bastien Nocera <hadess hadess net>
Date:   Tue Nov 24 15:31:55 2015 +0100

    application, documents, edit: Disable Print menu item when unsupported
    
    When we finish to load a document, verify whether it can be printed
    before enabling the "Print..." menu item.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=758445

 src/application.js |    3 +--
 src/documents.js   |   10 ++++++++++
 src/edit.js        |    6 ++++++
 3 files changed, 17 insertions(+), 2 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index e31c643..5785ac8 100644
--- a/src/application.js
+++ b/src/application.js
@@ -487,8 +487,7 @@ const Application = new Lang.Class({
               state: GLib.Variant.new('b', false),
               accel: 'F5' },
             { name: 'print-current', accel: '<Primary>p',
-              callback: this._onActionPrintCurrent,
-              window_mode: WindowMode.WindowMode.PREVIEW },
+              callback: this._onActionPrintCurrent },
             { name: 'search',
               callback: this._onActionToggle,
               state: GLib.Variant.new('b', false),
diff --git a/src/documents.js b/src/documents.js
index f8c5bc8..2fa4b3a 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -369,6 +369,13 @@ const DocCommon = new Lang.Class({
         log('Error: DocCommon implementations must override canTrash');
     },
 
+    canPrint: function(docModel) {
+        if (!docModel)
+            return false;
+
+        return EvView.PrintOperation.exists_for_document(docModel.get_document());
+    },
+
     trash: function() {
         if (!this.canTrash())
             return;
@@ -600,6 +607,9 @@ const DocCommon = new Lang.Class({
                     return;
                 }
 
+                if (!this.canPrint(docModel))
+                    return;
+
                 let printOp = EvView.PrintOperation.new(docModel.get_document());
 
                 printOp.connect('begin-print', Lang.bind(this,
diff --git a/src/edit.js b/src/edit.js
index b4b47f4..5abffe9 100644
--- a/src/edit.js
+++ b/src/edit.js
@@ -88,6 +88,9 @@ const EditView = new Lang.Class({
                 Application.modeController.setWindowMode(WindowMode.WindowMode.PREVIEW);
             }));
 
+        this._printAction = Application.application.lookup_action('print-current');
+        this._printAction.set_enabled(false);
+
         Application.documentManager.connect('load-started',
                                             Lang.bind(this, this._onLoadStarted));
         Application.documentManager.connect('load-finished',
@@ -98,6 +101,7 @@ const EditView = new Lang.Class({
     _onLoadStarted: function() {
         this._editAction.enabled = false;
         this._viewAction.enabled = false;
+        this._printAction.set_enabled(false);
     },
 
     _onLoadFinished: function(manager, doc, docModel) {
@@ -105,6 +109,8 @@ const EditView = new Lang.Class({
             if (doc.canEdit())
                 this._editAction.enabled = true;
             this._viewAction.enabled = true;
+            if (doc.canPrint(docModel))
+                this._printAction.set_enabled(true);
         }
     },
 


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