[polari/wip/bastianilso/paste-integration] WIP: Paste Integration
- From: Bastian Ilsø Hougaard <bastianilso src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari/wip/bastianilso/paste-integration] WIP: Paste Integration
- Date: Mon, 17 Aug 2015 23:20:25 +0000 (UTC)
commit 4cddfde16d6b30374268df76faf9b1e05953f4f0
Author: Bastian Ilsø <bastianilso src gnome org>
Date: Mon Aug 17 19:13:21 2015 +0200
WIP: Paste Integration
src/application.js | 8 +++++++
src/entryArea.js | 58 +++++++++++++++++++++++++++++++++++++++++++++++++--
src/ircParser.js | 19 +++++-----------
3 files changed, 69 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..d16e06e 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,43 @@ const EntryArea = new Lang.Class({
this._entry.text = '';
}));
+ this.stack = new Gtk.Stack({ transition_type: Gtk.StackTransitionType.CROSSFADE });
+ 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 +182,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]