[polari/wip/bastianilso/paste-integration] WIP: Drag n Drop support
- From: Bastian Ilsø Hougaard <bastianilso src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari/wip/bastianilso/paste-integration] WIP: Drag n Drop support
- Date: Wed, 19 Aug 2015 22:14:44 +0000 (UTC)
commit 3fefcbc1a46537b12ea37c71400ffc444b75e0e5
Author: Bastian Ilsø <bastianilso src gnome org>
Date: Thu Aug 20 00:14:02 2015 +0200
WIP: Drag n Drop support
src/chatView.js | 25 +++++++++++--------------
src/entryArea.js | 32 +++++++++++++++++---------------
src/pasteManager.js | 12 +++++++-----
src/roomStack.js | 6 ++++--
4 files changed, 39 insertions(+), 36 deletions(-)
---
diff --git a/src/chatView.js b/src/chatView.js
index d6979c1..1de3a81 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -135,7 +135,7 @@ const ChatView = new Lang.Class({
Lang.bind(this, this._onStyleUpdated));
this._onStyleUpdated();
- this._room = room;
+ this.room = room;
this._state = { lastNick: null, lastTimestamp: 0 };
this._active = false;
this._toplevelFocus = false;
@@ -162,9 +162,6 @@ const ChatView = new Lang.Class({
let adj = this.widget.vadjustment;
this._scrollBottom = adj.upper - adj.page_size;
- this._app = Gio.Application.get_default();
- this._app.pasteManager.addWidget(this._view);
-
this._linkCursor = Gdk.Cursor.new(Gdk.CursorType.HAND1);
this._channelSignals = [];
@@ -318,7 +315,7 @@ const ChatView = new Lang.Class({
this._channelSignals = [];
for (let i = 0; i < this._roomSignals.length; i++)
- this._room.disconnect(this._roomSignals[i]);
+ this.room.disconnect(this._roomSignals[i]);
this._roomSignals = [];
},
@@ -371,7 +368,7 @@ const ChatView = new Lang.Class({
if (!this._channel)
return;
- if (this._room.type == Tp.HandleType.ROOM) {
+ if (this.room.type == Tp.HandleType.ROOM) {
let members = this._channel.group_dup_members_contacts();
for (let j = 0; j < members.length; j++)
this._setNickStatus(members[j].get_alias(),
@@ -627,7 +624,7 @@ const ChatView = new Lang.Class({
},
_onChannelChanged: function() {
- if (this._channel == this._room.channel)
+ if (this._channel == this.room.channel)
return;
if (this._channel) {
@@ -636,7 +633,7 @@ const ChatView = new Lang.Class({
this._channelSignals = [];
}
- this._channel = this._room.channel;
+ this._channel = this.room.channel;
if (!this._channel)
return;
@@ -657,11 +654,11 @@ const ChatView = new Lang.Class({
this._channel.dup_pending_messages().forEach(Lang.bind(this,
function(message) {
- this._insertTpMessage(this._room, message);
+ this._insertTpMessage(this.room, message);
}));
this._checkMessages();
- if (this._room.type == Tp.HandleType.ROOM) {
+ if (this.room.type == Tp.HandleType.ROOM) {
let members = this._channel.group_dup_members_contacts();
for (let j = 0; j < members.length; j++)
this._setNickStatus(members[j].get_alias(),
@@ -821,7 +818,7 @@ const ChatView = new Lang.Class({
timestamp = tpMessage.get_received_timestamp();
message.timestamp = timestamp;
- message.shouldHighlight = this._room.should_highlight_message(tpMessage);
+ message.shouldHighlight = this.room.should_highlight_message(tpMessage);
this._ensureNewLine();
@@ -833,15 +830,15 @@ const ChatView = new Lang.Class({
if (message.shouldHighlight &&
!(this._toplevelFocus && this._active)) {
- let summary = '%s %s'.format(this._room.display_name, message.nick);
+ let summary = '%s %s'.format(this.room.display_name, message.nick);
let notification = new Gio.Notification();
notification.set_title(summary);
notification.set_body(message.text);
- let account = this._room.account;
+ let account = this.room.account;
let param = GLib.Variant.new('(ssu)',
[ account.get_object_path(),
- this._room.channel_name,
+ this.room.channel_name,
TP_CURRENT_TIME ]);
notification.set_default_action_and_target('app.join-room', param);
this._app.send_notification('pending-message-' + id, notification);
diff --git a/src/entryArea.js b/src/entryArea.js
index 4e7c967..3157f51 100644
--- a/src/entryArea.js
+++ b/src/entryArea.js
@@ -74,6 +74,7 @@ const EntryArea = new Lang.Class({
this._nickEntry.connect_after('key-press-event', Lang.bind(this,
function(w, event) {
let [, keyval] = event.get_keyval();
+ log(keyval);
if (keyval == Gdk.KEY_Escape) {
this._entry.grab_focus();
return Gdk.EVENT_STOP;
@@ -103,36 +104,37 @@ const EntryArea = new Lang.Class({
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';
- }));
+ cancelButton.connect('clicked', Lang.bind(this, this._resetEntry));
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();
+ let [, mods] = event.get_state();
+ if (keyval == Gdk.KEY_Escape || keyval == Gdk.KEY_BackSpace ||
+ keyval == Gdk.KEY_z && mods & Gdk.ModifierType.CONTROL_MASK) {
+ this._resetEntry();
return Gdk.EVENT_STOP;
}
return Gdk.EVENT_PROPAGATE;
}));
+ 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, this._resetEntry));
+ multiLineBox.add(this._pasteButton);
+
this.stack.add_named(multiLineBox, 'multiline');
this.widget.add(this.stack);
this.widget.show_all();
},
+ _resetEntry: function() {
+ this._entry.text = '';
+ this.stack.visible_child_name = 'default';
+ },
+
_updateCompletions: function() {
let nicks = [];
diff --git a/src/pasteManager.js b/src/pasteManager.js
index 8c87a92..a485a05 100644
--- a/src/pasteManager.js
+++ b/src/pasteManager.js
@@ -31,9 +31,9 @@ const PasteManager = new Lang.Class({
this._roomManager = ChatroomManager.getDefault();
},
- addWidget: function(widget) {
- // auto-paste needs some design; disable for now
- return;
+ addWidget: function(area) {
+ this._area = area;
+ let widget = this._area.widget;
if (this._widgets.indexOf(widget) != -1)
return;
@@ -202,7 +202,8 @@ const PasteManager = new Lang.Class({
let success = false;
switch(info) {
case DndTargetType.TEXT:
- this.pasteText(data.get_text());
+ //this.pasteText(data.get_text());
+ this._area.inputWidget.text = data.get_text();
success = true;
break;
case DndTargetType.IMAGE:
@@ -257,7 +258,8 @@ const PasteManager = new Lang.Class({
file.load_contents_async(null, Lang.bind(this,
function(f, res) {
let [, contents, ,] = f.load_contents_finish(res);
- this._pasteText(contents.toString(), n);
+ //this._pasteText(contents.toString(), n);
+ this._area.inputWidget.text = contents.toString();
}));
} else if (type == DndTargetType.IMAGE) {
file.read_async(GLib.PRIORITY_DEFAULT, null, Lang.bind(this,
diff --git a/src/roomStack.js b/src/roomStack.js
index dae4c6d..ee02e2f 100644
--- a/src/roomStack.js
+++ b/src/roomStack.js
@@ -34,6 +34,7 @@ const RoomStack = new Lang.Class({
_addView: function(id, view) {
this._rooms[id] = view;
+ this._app.pasteManager.addWidget(view);
this._inputSizeGroup.add_widget(view.inputWidget);
if (!this.widget.visible_child)
@@ -152,6 +153,9 @@ const RoomView = new Lang.Class({
this._view = room ? new ChatView.ChatView(room)
: new ChatPlaceholder();
+ this._app = Gio.Application.get_default();
+ this._app.pasteManager.addWidget(this._view);
+
this._entryArea = new EntryArea.EntryArea(room);
this.widget = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL });
@@ -161,8 +165,6 @@ const RoomView = new Lang.Class({
this.inputWidget.get_style_context().add_class('polari-input-area');
this.widget.add(this.inputWidget);
- this.inputWidget.add(this._entryArea.widget);
-
this.widget.show_all();
},
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]