[gnome-documents/wip/ui-changes: 22/25] print: first basic implementation of a Print button



commit 881e0220f3c88b38954976fa9b2d97ead782108f
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Sun Feb 26 16:26:48 2012 -0500

    print: first basic implementation of a Print button
    
    Very rough still. Uses the stock Evince PrintOperation implementation,
    and launches evince-previewer (!?) when "Print Preview" is clicked.
    Also, metadata and print settings are not remembered neither globally in
    the application nor per-document yet (Evince does both).

 src/selections.js |   38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)
---
diff --git a/src/selections.js b/src/selections.js
index 903108a..c0d6099 100644
--- a/src/selections.js
+++ b/src/selections.js
@@ -19,6 +19,7 @@
  *
  */
 
+const EvView = imports.gi.EvinceView;
 const Gd = imports.gi.Gd;
 const GLib = imports.gi.GLib;
 const Gtk = imports.gi.Gtk;
@@ -663,6 +664,11 @@ SelectionToolbar.prototype = {
         this._leftBox.add(this._toolbarFavorite);
         this._toolbarFavorite.connect('clicked', Lang.bind(this, this._onToolbarFavorite));
 
+        this._toolbarPrint = new Gtk.Button({ child: new Gtk.Image ({ icon_name: 'printer-symbolic',
+                                                                      pixel_size: 32 })});
+        this._leftBox.add(this._toolbarPrint);
+        this._toolbarPrint.connect('clicked', Lang.bind(this, this._onToolbarPrint));
+
         this._separator = new Gtk.SeparatorToolItem({ draw: false });
         this._separator.set_expand(true);
         this.widget.insert(this._separator, -1);
@@ -740,6 +746,7 @@ SelectionToolbar.prototype = {
         let favCount = 0;
         let showFavorite = true;
         let canTrash = true;
+        let showPrint = false;
 
         this._insideRefresh = true;
 
@@ -761,6 +768,17 @@ SelectionToolbar.prototype = {
 
         showFavorite &= ((favCount == 0) || (favCount == selection.length));
 
+        if (selection.length == 1) {
+            let urn = selection[0];
+            if (!Global.collectionManager.getItemById(urn))
+                showPrint = true;
+        }
+
+        if (showPrint)
+            this._toolbarPrint.show_all();
+        else
+            this._toolbarPrint.hide();
+
         // if we're showing the favorite icon, also show the separator
         this._separator.set_visible(showFavorite);
 
@@ -857,6 +875,26 @@ SelectionToolbar.prototype = {
             }));
     },
 
+    _onToolbarPrint: function(widget) {
+        let selection = Global.selectionController.getSelection();
+
+        if (selection.length != 1)
+            return;
+
+        let doc = Global.documentManager.getItemById(selection[0]);
+        doc.load(null, Lang.bind(this,
+            function(doc, evDoc, error) {
+                if (!evDoc) {
+                    // TODO: handle error here!
+                    return;
+                }
+
+                let printOp = EvView.PrintOperation.new(evDoc);
+                let toplevel = this.widget.get_toplevel();
+                printOp.run(toplevel);
+            }));
+    },
+
     _fadeIn: function() {
         if (this.actor.opacity != 0)
             return;



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