[polari] entryArea: Update and activate paste service integration
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari] entryArea: Update and activate paste service integration
- Date: Thu, 20 Aug 2015 14:42:55 +0000 (UTC)
commit ec24d293bac59b4e65002024728694ad12038c2f
Author: Bastian Ilsø <bastianilso src gnome org>
Date: Mon Aug 17 19:13:21 2015 +0200
entryArea: Update and activate paste service integration
Bring 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.
https://bugzilla.gnome.org/show_bug.cgi?id=725088
src/application.js | 8 ++++++
src/entryArea.js | 69 +++++++++++++++++++++++++++++++++++++++++++++++----
src/ircParser.js | 19 ++++----------
3 files changed, 77 insertions(+), 19 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..8b149e0 100644
--- a/src/entryArea.js
+++ b/src/entryArea.js
@@ -10,6 +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({
@@ -39,10 +40,9 @@ const EntryArea = new Lang.Class({
},
_createWidget: function() {
- this.widget = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL,
- sensitive: false,
- margin: 6 });
- this.widget.get_style_context().add_class('linked');
+ this.widget = new Gtk.Stack({ transition_type: Gtk.StackTransitionType.CROSSFADE,
+ sensitive: false,
+ margin: 6 });
this.widget.connect('destroy', Lang.bind(this, this._onDestroy));
this.widget.connect('notify::sensitive', Lang.bind(this, this._onSensitiveChanged));
@@ -53,10 +53,13 @@ const EntryArea = new Lang.Class({
Lang.bind(this, this._onKeyPressEvent));
}));
+ let chatBox = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL });
+ chatBox.get_style_context().add_class('linked');
+
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 +84,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 +93,39 @@ const EntryArea = new Lang.Class({
this._entry.text = '';
}));
+ this.widget.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);
+
+ let cancelButton = new Gtk.Button({ label: _("_Cancel"),
+ use_underline: true });
+ cancelButton.connect('clicked', Lang.bind(this, this._onButtonClicked));
+ multiLineBox.add(cancelButton);
+
+ this._pasteButton = new Gtk.Button({ label: _("_Paste"),
+ use_underline: true,
+ action_name: 'app.paste-text' });
+ this._pasteButton.get_style_context().add_class('suggested-action');
+ this._pasteButton.connect('clicked',
+ Lang.bind(this, this._onButtonClicked));
+ multiLineBox.add(this._pasteButton);
+
+ 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.widget.add_named(multiLineBox, 'multiline');
this.widget.show_all();
},
@@ -142,6 +179,26 @@ const EntryArea = new Lang.Class({
return Gdk.EVENT_STOP;
},
+ _onEntryChanged: function() {
+ let nLines = this._entry.text.split('\n').length;
+
+ if (nLines < MAX_LINES)
+ return;
+
+ this._multiLinelabel.label =
+ 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', this._entry.text);
+ this.widget.visible_child_name = 'multiline';
+ this._pasteButton.grab_focus();
+ },
+
+ _onButtonClicked: function() {
+ this._entry.text = '';
+ this.widget.visible_child_name = 'default';
+ },
+
_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]