[polari/wip/fmuellner/paste-confirmation: 7/16] entryArea: Handle paste directly



commit 9df0fb543b24bf1a3e63fcfd63c42ff8999d8af8
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Feb 11 20:38:22 2016 +0100

    entryArea: Handle paste directly

 data/resources/entry-area.ui |    1 -
 src/application.js           |   18 ------------------
 src/entryArea.js             |   23 ++++++++++++-----------
 3 files changed, 12 insertions(+), 30 deletions(-)
---
diff --git a/data/resources/entry-area.ui b/data/resources/entry-area.ui
index 26b6b28..af10152 100644
--- a/data/resources/entry-area.ui
+++ b/data/resources/entry-area.ui
@@ -123,7 +123,6 @@
                 <property name="label" translatable="yes">_Paste</property>
                 <property name="visible">True</property>
                 <property name="receives-default">True</property>
-                <property name="action-name">app.paste-content</property>
                 <property name="use-underline">True</property>
                 <style>
                   <class name="suggested-action"/>
diff --git a/src/application.js b/src/application.js
index a1e50d6..dfe927c 100644
--- a/src/application.js
+++ b/src/application.js
@@ -67,9 +67,6 @@ const Application = new Lang.Class({
           { name: 'message-user',
             activate: Lang.bind(this, this._onMessageUser),
             parameter_type: GLib.VariantType.new('(sssu)') },
-          { name: 'paste-content',
-            activate: Lang.bind(this, this._onPasteContent),
-            parameter_type: GLib.VariantType.new('(ayi)') },
           { name: 'leave-room',
             activate: Lang.bind(this, this._onLeaveRoom),
             parameter_type: GLib.VariantType.new('(ss)') },
@@ -378,21 +375,6 @@ const Application = new Lang.Class({
         }));
     },
 
-    _onPasteContent: function(action, parameter) {
-        let [data, type] = parameter.deep_unpack();
-        switch (type) {
-            case PasteManager.DndTargetType.TEXT:
-                let text = data.toString();
-                this.pasteManager.pasteText(text);
-                break;
-            case PasteManager.DndTargetType.IMAGE:
-                this.pasteManager.pasteImage(data);
-                break;
-            default:
-                log('Unhandled paste content of type %d'.format(type));
-        }
-    },
-
     _onLeaveRoom: function(action, parameter) {
         let [roomId, message] = parameter.deep_unpack();
         let reason = Tp.ChannelGroupChangeReason.NONE;
diff --git a/src/entryArea.js b/src/entryArea.js
index 8f6cc57..4246e52 100644
--- a/src/entryArea.js
+++ b/src/entryArea.js
@@ -127,8 +127,8 @@ const EntryArea = new Lang.Class({
                 }
             }));
 
-        this._cancelButton.connect('clicked', Lang.bind(this, this._onButtonClicked));
-        this._pasteButton.connect('clicked', Lang.bind(this, this._onButtonClicked));
+        this._cancelButton.connect('clicked', Lang.bind(this, this._onCancelClicked));
+        this._pasteButton.connect('clicked', Lang.bind(this, this._onPasteClicked));
 
         this._pasteBox.connect_after('key-press-event', Lang.bind(this,
             function(w, event) {
@@ -216,7 +216,7 @@ const EntryArea = new Lang.Class({
     },
 
     _setPasteContent: function(content) {
-        this._pasteButton.action_target = content;
+        this._pasteContent = content;
 
         if (content) {
             this._pasteButton.grab_focus();
@@ -233,20 +233,21 @@ const EntryArea = new Lang.Class({
             ngettext("Paste %s line of text to public paste service?",
                      "Paste %s lines of text to public paste service?",
                      nLines).format(nLines);
-        this._setPasteContent(new GLib.Variant('(ayi)', [text, PasteManager.DndTargetType.TEXT]));
+        this._setPasteContent(text);
     },
 
-    _onImagePasted: function(entry, data) {
+    _onImagePasted: function(entry, pixbuf) {
         this._confirmLabel.label = _("Upload image to public paste service?");
+        this._setPasteContent(pixbuf);
+    },
 
-        let [success, buffer] = data.save_to_bufferv('png',[],[]);
-        if (!success)
-            return;
-
-        this._setPasteContent(new GLib.Variant('(ayi)', [buffer, PasteManager.DndTargetType.IMAGE]));
+    _onPasteClicked: function() {
+        let app = Gio.Application.get_default();
+        app.pasteManager.pasteContent(this._pasteContent);
+        this._setPasteContent(null);
     },
 
-    _onButtonClicked: function() {
+    _onCancelClicked: function() {
         this._setPasteContent(null);
     },
 


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