[polari/wip/kunaljain/image-paste-service: 80/81] Make paste functions generic



commit cc8e626b0fe01cc760df32f2d4bb67f98c4eeac4
Author: Kunaal Jain <kunaalus gmail com>
Date:   Wed Feb 10 16:25:51 2016 +0530

    Make paste functions generic

 data/resources/entry-area.ui |    2 +-
 src/application.js           |   12 ++++++------
 src/entryArea.js             |    3 ++-
 src/pasteManager.js          |   12 +++++++-----
 4 files changed, 16 insertions(+), 13 deletions(-)
---
diff --git a/data/resources/entry-area.ui b/data/resources/entry-area.ui
index 40af1e0..f7beca8 100644
--- a/data/resources/entry-area.ui
+++ b/data/resources/entry-area.ui
@@ -123,7 +123,7 @@
                 <property name="label" translatable="yes">_Paste</property>
                 <property name="visible">True</property>
                 <property name="receives-default">True</property>
-                <property name="action-name">app.paste-text</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 28cbaba..df2f1eb 100644
--- a/src/application.js
+++ b/src/application.js
@@ -67,9 +67,9 @@ const Application = new Lang.Class({
           { name: 'message-user',
             activate: Lang.bind(this, this._onMessageUser),
             parameter_type: GLib.VariantType.new('(sssu)') },
-          { name: 'paste-text',
-            activate: Lang.bind(this, this._onPasteText),
-            parameter_type: GLib.VariantType.new('s') },
+          { name: 'paste-content',
+            activate: Lang.bind(this, this._onPasteContent),
+            parameter_type: GLib.VariantType.new('(si)') },
           { name: 'leave-room',
             activate: Lang.bind(this, this._onLeaveRoom),
             parameter_type: GLib.VariantType.new('(ss)') },
@@ -376,9 +376,9 @@ const Application = new Lang.Class({
         }));
     },
 
-    _onPasteText: function(action, parameter) {
-        let text = parameter.deep_unpack();
-        this.pasteManager.pasteText(text);
+    _onPasteContent: function(action, parameter) {
+        let [data, type] = parameter.deep_unpack();
+        this.pasteManager.pasteContent(data, type);
     },
 
     _onLeaveRoom: function(action, parameter) {
diff --git a/src/entryArea.js b/src/entryArea.js
index a9f8612..c1ca35e 100644
--- a/src/entryArea.js
+++ b/src/entryArea.js
@@ -9,6 +9,7 @@ const Lang = imports.lang;
 const Mainloop = imports.mainloop;
 const TabCompletion = imports.tabCompletion;
 const Tp = imports.gi.TelepathyGLib;
+const PasteManager = imports.pasteManager;
 
 const MAX_NICK_UPDATE_TIME = 5; /* s */
 const MAX_LINES = 5;
@@ -210,7 +211,7 @@ 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._pasteButton.action_target = new GLib.Variant('s', text);
+        this._pasteButton.action_target = new GLib.Variant('(si)', text, PasteManager.DndTargetType.TEXT);
         this.visible_child_name = 'multiline';
         this._pasteButton.grab_focus();
     },
diff --git a/src/pasteManager.js b/src/pasteManager.js
index cccd048..2aeb419 100644
--- a/src/pasteManager.js
+++ b/src/pasteManager.js
@@ -73,12 +73,14 @@ const PasteManager = new Lang.Class({
         this._widgets.push(widget);
     },
 
-    pasteText: function(text) {
+    pasteContent: function(data, type) {
         let app = Gio.Application.get_default();
-        let n = new UploadNotification("text");
-        app.notificationQueue.addNotification(n);
 
-        this._pasteText(text, n);
+        if (type == DndTargetType.TEXT) {
+            let n = new UploadNotification("text");
+            app.notificationQueue.addNotification(n);
+            this._pasteText(data, n);
+        }
     },
 
     _pasteText: function(text, notification) {
@@ -217,7 +219,7 @@ const PasteManager = new Lang.Class({
             let success = false;
             switch(info) {
                 case DndTargetType.TEXT:
-                    this.pasteText(data.get_text());
+                    this.pasteContent(data.get_text(), DndTargetType.TEXT);
                     success = true;
                     break;
                 case DndTargetType.IMAGE:


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