[gnome-documents/wip/lokdocview-rebase: 12/13] Add support for the "Copy" menu item



commit f23080bfc248dc0c2bae1d1056c2bce71bb6f3a9
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Dec 10 13:34:18 2015 +0100

    Add support for the "Copy" menu item
    
    https://bugzilla.gnome.org/show_bug.cgi?id=753686

 src/lokview.js |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)
---
diff --git a/src/lokview.js b/src/lokview.js
index 3c3f599..6c9af4b 100644
--- a/src/lokview.js
+++ b/src/lokview.js
@@ -129,6 +129,9 @@ const LOKView = new Lang.Class({
                 this.view.set_zoom(zoomLevel / 2);
             }));
 
+        this._copy = Application.application.lookup_action('copy');
+        let copyId = this._copy.connect('activate', Lang.bind(this, this._onCopyActivated));
+
         Application.documentManager.connect('load-started',
                                             Lang.bind(this, this._onLoadStarted));
         Application.documentManager.connect('load-error',
@@ -141,6 +144,14 @@ const LOKView = new Lang.Class({
            }));
     },
 
+    _onCopyActivated: function() {
+        let [selectedText, mimeType] = this.view.copy_selection('text/plain;charset=utf-8');
+        let display = Gdk.Display.get_default();
+        let clipboard = Gtk.Clipboard.get_default(display);
+
+        clipboard.set_text(selectedText, selectedText.length);
+    },
+
     _onLoadStarted: function(manager, doc) {
         if (doc.viewType != Documents.ViewType.LOK)
             return;
@@ -149,6 +160,7 @@ const LOKView = new Lang.Class({
         let file = Gio.File.new_for_uri (doc.uri);
         let location = file.get_path();
         this._doc = doc;
+        this._copy.enabled = false;
         this.view.open_document(location, "{}", null, Lang.bind(this, this.open_document_cb));
         this._progressBar.show();
     },
@@ -179,6 +191,7 @@ const LOKView = new Lang.Class({
             return;
         this.view.reset_view();
         this.set_visible_child_full('view', Gtk.StackTransitionType.NONE);
+        this._copy.enabled = false;
     },
 
     _createView: function() {
@@ -187,6 +200,7 @@ const LOKView = new Lang.Class({
             this._sw.add(this.view);
             this.view.show();
             this.view.connect('load-changed', Lang.bind(this, this._onProgressChanged));
+            this.view.connect('text-selection', Lang.bind(this, this._onTextSelection));
         }
 
         this._navControls = new LOKViewNavControls(this, this._overlay);
@@ -197,6 +211,10 @@ const LOKView = new Lang.Class({
         this._progressBar.fraction = this.view.load_progress;
     },
 
+    _onTextSelection: function(hasSelection) {
+        this._copy.enabled = hasSelection;
+    },
+
     _setError: function(primary, secondary) {
         this._errorBox.update(primary, secondary);
         this.set_visible_child_name('error');


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