[polari/wip/bastianilso/paste-integration] Update and activate paste service integration



commit 29d3536d81e46a81636c7dc4cadee589137c913d
Author: Bastian Ilsø <bastianilso src gnome org>
Date:   Mon Aug 17 19:13:21 2015 +0200

    Update and activate paste service integration
    
    Brings back paste service integration to Polari.
    When pasting more than 5 lines into the entry area,
    ask the user if the multiline text should be uploaded
    to a public paste service. 'Enter' confirms and 'Esc'
    cancels.

 src/application.js |    8 +++++++
 src/entryArea.js   |   59 +++++++++++++++++++++++++++++++++++++++++++++++++--
 src/ircParser.js   |   19 +++++-----------
 3 files changed, 70 insertions(+), 16 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index aeb432d..5582db9 100644
--- a/src/application.js
+++ b/src/application.js
@@ -70,6 +70,9 @@ const Application = new Lang.Class({
           { name: 'message-user',
             activate: Lang.bind(this, this._onMessageUser),
             parameter_type: GLib.VariantType.new('(ssu)') },
+          { name: 'paste-text',
+            activate: Lang.bind(this, this._onPasteText),
+            parameter_type: GLib.VariantType.new('s') },
           { name: 'leave-room',
             activate: Lang.bind(this, this._onLeaveRoom),
             parameter_type: GLib.VariantType.new('(ss)') },
@@ -352,6 +355,11 @@ const Application = new Lang.Class({
                              contactName, time);
     },
 
+    _onPasteText: function(action, parameter) {
+        let text = parameter.deep_unpack();
+        this.pasteManager.pasteText(text);
+    },
+
     _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 6b00bb1..4e7c967 100644
--- a/src/entryArea.js
+++ b/src/entryArea.js
@@ -10,7 +10,7 @@ const TabCompletion = imports.tabCompletion;
 const Tp = imports.gi.TelepathyGLib;
 
 const MAX_NICK_UPDATE_TIME = 5; /* s */
-
+const MAX_LINES = 5;
 
 const EntryArea = new Lang.Class({
     Name: 'EntryArea',
@@ -53,10 +53,12 @@ const EntryArea = new Lang.Class({
                                                           Lang.bind(this, this._onKeyPressEvent));
             }));
 
+        let chatBox = new Gtk.Box ({ orientation: Gtk.Orientation.HORIZONTAL });
+
         this._nickEntry = new Gtk.Entry();
         this._nickEntry.width_chars = ChatView.MAX_NICK_CHARS
         this._nickEntry.get_style_context().add_class('polari-nick-entry');
-        this.widget.add(this._nickEntry);
+        chatBox.add(this._nickEntry);
 
         this._nickEntry.connect('activate', Lang.bind(this,
             function() {
@@ -81,7 +83,8 @@ const EntryArea = new Lang.Class({
 
         this._entry = new Gtk.Entry({ hexpand: true,
                                       activates_default: true });
-        this.widget.add(this._entry);
+        this._entry.connect('changed', Lang.bind(this, this._onEntryChanged));
+        chatBox.add(this._entry);
 
         this._entry.connect('activate', Lang.bind(this,
             function() {
@@ -89,6 +92,44 @@ const EntryArea = new Lang.Class({
                 this._entry.text = '';
             }));
 
+        this.stack = new Gtk.Stack({ transition_type: Gtk.StackTransitionType.CROSSFADE,
+                                     vhomogeneous: true });
+        this.stack.add_named(chatBox, 'default');
+
+        let multiLineBox = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL,
+                                         spacing: 6 });
+
+        this._multiLinelabel = new Gtk.Label({ halign: Gtk.Align.START,
+                                               xalign: 0, hexpand: true });
+        multiLineBox.add(this._multiLinelabel);
+
+        this._pasteButton = new Gtk.Button({ label: _("Paste"), has_focus: true,
+                                             action_name: 'app.paste-text' });
+        this._pasteButton.get_style_context().add_class('suggested-action');
+        this._pasteButton.connect('clicked', Lang.bind(this, function() {
+                this._entry.text = '';
+                this.stack.visible_child_name = 'default';
+            }));
+        multiLineBox.add(this._pasteButton);
+
+        let cancelButton = new Gtk.Button({ label: _("Cancel") });
+        cancelButton.connect('clicked', Lang.bind(this, function() {
+                this._entry.text = '';
+                this.stack.visible_child_name = 'default';
+            }));
+        multiLineBox.add(cancelButton);
+        multiLineBox.connect_after('key-press-event', Lang.bind(this,
+            function(w, event) {
+                let [, keyval] = event.get_keyval();
+                if (keyval == Gdk.KEY_Escape) {
+                    cancelButton.clicked();
+                    return Gdk.EVENT_STOP;
+                }
+                return Gdk.EVENT_PROPAGATE;
+            }));
+
+        this.stack.add_named(multiLineBox, 'multiline');
+        this.widget.add(this.stack);
         this.widget.show_all();
     },
 
@@ -142,6 +183,18 @@ const EntryArea = new Lang.Class({
         return Gdk.EVENT_STOP;
     },
 
+    _onEntryChanged: function() {
+        let lineAmount = this._entry.text.split('\n').length;
+
+        if (lineAmount < MAX_LINES)
+            return;
+
+        this._multiLinelabel.label = _("Paste %s lines of text to public paste service?").format(lineAmount);
+        this._pasteButton.action_target = new GLib.Variant('s', this._entry.text),
+        this.stack.visible_child_name = 'multiline';
+        this._pasteButton.grab_focus();
+    },
+
     _onSensitiveChanged: function() {
         if (!this.widget.sensitive)
             return;
diff --git a/src/ircParser.js b/src/ircParser.js
index cfc8988..673cdb4 100644
--- a/src/ircParser.js
+++ b/src/ircParser.js
@@ -9,7 +9,6 @@ const Signals = imports.signals;
 
 const N_ = function(s) { return s; };
 
-const MAX_LINES = 5;
 const TP_CURRENT_TIME = GLib.MAXUINT32;
 
 const knownCommands = {
@@ -70,7 +69,7 @@ const IrcParser = new Lang.Class({
             return;
 
         if (text[0] != '/') {
-            this._sendOrPasteText(text);
+            this._sendText(text);
             return;
         }
 
@@ -244,7 +243,7 @@ const IrcParser = new Lang.Class({
                     output = this._createFeedbackUsage(cmd);
                     break;
                 }
-                this._sendOrPasteText(stripCommand(text));
+                this._sendText(stripCommand(text));
                 break;
             }
             case 'TOPIC': {
@@ -263,16 +262,10 @@ const IrcParser = new Lang.Class({
             this._app.commandOutputQueue.addNotification(output);
     },
 
-    _sendOrPasteText: function(text) {
-        // auto-paste needs some design; disable for now
-        if (false && text.split('\n').length > MAX_LINES) {
-            let app = Gio.Application.get_default();
-            app.pasteManager.pasteText(text);
-        } else {
-            let type = Tp.ChannelTextMessageType.NORMAL;
-            let message = Tp.ClientMessage.new_text(type, text);
-            this._sendMessage(message);
-        }
+    _sendText: function(text) {
+        let type = Tp.ChannelTextMessageType.NORMAL;
+        let message = Tp.ClientMessage.new_text(type, text);
+        this._sendMessage(message);
     },
 
     _sendMessage: function(message) {


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