[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 17:14:04 +0000 (UTC)
commit bdcece8d730b12bca5428dae0ca18cac6e1a5e18
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 | 47 ++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 52 insertions(+), 3 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..8cc9fb2 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,33 @@ 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"),
+ 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);
+
+ this.stack.add_named(multiLineBox, 'multiline');
+ this.widget.add(this.stack);
this.widget.show_all();
},
@@ -142,6 +172,17 @@ 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';
+ },
+
_onSensitiveChanged: function() {
if (!this.widget.sensitive)
return;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]