[polari/wip/fmuellner/paste-confirmation: 8/16] entryArea: Take over processing of the result URL
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari/wip/fmuellner/paste-confirmation: 8/16] entryArea: Take over processing of the result URL
- Date: Fri, 12 Feb 2016 21:26:17 +0000 (UTC)
commit 3cf17ae3b6749a2df298935a4e7cdddec4ae7579
Author: Florian Müllner <fmuellner gnome org>
Date: Thu Feb 11 20:50:51 2016 +0100
entryArea: Take over processing of the result URL
In order to allow users to send paste URLs as part of normal messages
rather than stand-alone, the result URL should be handled by the
appropriate entry rather than generically by the paste manager.
Also removing code duplication between text- and image pastes is a nice
side effect.
https://bugzilla.gnome.org/show_bug.cgi?id=760315
src/entryArea.js | 27 +++++++++++++++++++-
src/pasteManager.js | 68 ++------------------------------------------------
2 files changed, 29 insertions(+), 66 deletions(-)
---
diff --git a/src/entryArea.js b/src/entryArea.js
index 2a5b65e..e1fd6b0 100644
--- a/src/entryArea.js
+++ b/src/entryArea.js
@@ -11,6 +11,7 @@ const Mainloop = imports.mainloop;
const TabCompletion = imports.tabCompletion;
const Tp = imports.gi.TelepathyGLib;
const PasteManager = imports.pasteManager;
+const Utils = imports.utils;
const MAX_NICK_UPDATE_TIME = 5; /* s */
const MAX_LINES = 5;
@@ -242,14 +243,38 @@ const EntryArea = new Lang.Class({
},
_onPasteClicked: function() {
+ let title;
+ let nick = this._room.channel.connection.self_contact.alias;
+ if (this._room.type == Tp.HandleType.ROOM)
+ /* translators: %s is a nick, #%s a channel */
+ title = _("%s in #%s").format(nick, this._room.display_name);
+ else
+ title = _("Paste from %s").format(nick);
+
let app = Gio.Application.get_default();
try {
- app.pasteManager.pasteContent(this._pasteContent);
+ app.pasteManager.pasteContent(this._pasteContent, title,
+ Lang.bind(this, function(url) {
+ if (!url)
+ return;
+
+ let type = Tp.ChannelTextMessageType.NORMAL;
+ let message = Tp.ClientMessage.new_text(type, url);
+ this._room.channel.send_message_async(message, 0,
+ Lang.bind(this, function(c, res) {
+ try {
+ c.send_message_finish(res);
+ } catch(e) {
+ logError(e, 'Failed to send message')
+ }
+ }));
+ }));
} catch(e) {
let type = typeof this._pasteContent;
Utils.debug('Failed to paste content of type ' +
(type == 'object' ? this._pasteContent.toString() : type));
}
+
this._setPasteContent(null);
},
diff --git a/src/pasteManager.js b/src/pasteManager.js
index 9ec3638..848d0a7 100644
--- a/src/pasteManager.js
+++ b/src/pasteManager.js
@@ -68,78 +68,16 @@ const PasteManager = new Lang.Class({
this._widgets.push(widget);
},
- pasteContent: function(content) {
+ pasteContent: function(content, title, callback) {
if (typeof content == 'string') {
- this.pasteText(content);
+ Utils.gpaste(content, title, callback);
} else if (content instanceof GdkPixbuf.Pixbuf) {
- this.pasteImage(content);
+ Utils.imgurPaste(content, title, callback);
} else {
throw new Error('Unhandled content type');
}
},
- pasteText: function(text) {
- let room = this._roomManager.getActiveRoom();
- if (!room)
- return;
-
- let title;
- let nick = room.channel.connection.self_contact.alias;
- if (room.type == Tp.HandleType.ROOM)
- /* translators: %s is a nick, #%s a channel */
- title = _("%s in #%s").format(nick, room.display_name);
- else
- title = _("Paste from %s").format(nick);
-
- Utils.gpaste(text, title, Lang.bind(this,
- function(url) {
- if (!url)
- return;
-
- let type = Tp.ChannelTextMessageType.NORMAL;
- let message = Tp.ClientMessage.new_text(type, url);
- room.channel.send_message_async(message, 0, Lang.bind(this,
- function(c, res) {
- try {
- c.send_message_finish(res);
- } catch(e) {
- logError(e, 'Failed to send message')
- }
- }));
- }));
- },
-
- pasteImage: function(pixbuf) {
- let room = this._roomManager.getActiveRoom();
- if (!room)
- return;
-
- let title;
- let nick = room.channel.connection.self_contact.alias;
- if (room.type == Tp.HandleType.ROOM)
- /* translators: %s is a nick, #%s a channel */
- title = _("%s in #%s").format(nick, room.display_name);
- else
- title = _("Paste from %s").format(nick);
-
- Utils.imgurPaste(pixbuf, title, Lang.bind(this,
- function(url) {
- if (!url)
- return;
-
- let type = Tp.ChannelTextMessageType.NORMAL;
- let message = Tp.ClientMessage.new_text(type, url);
- room.channel.send_message_async(message, 0, Lang.bind(this,
- function(c, res) {
- try {
- c.send_message_finish(res);
- } catch(e) {
- logError(e, 'Failed to send message')
- }
- }));
- }));
- },
-
_onDragDrop: function(widget, context, x, y, time) {
if (!Polari.drag_dest_supports_target(widget, context, null))
return Gdk.EVENT_PROPAGATE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]