From a7e92960a3f4d31cfb2fbe2e3ba4941cf3b8faf2 Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Sun, 8 Apr 2018 20:35:54 +0200 Subject: Allow switching conversations when dragging and dropping --- .../conversation_selector.vala | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'main/src/ui/conversation_selector') diff --git a/main/src/ui/conversation_selector/conversation_selector.vala b/main/src/ui/conversation_selector/conversation_selector.vala index 9276148b..ac087183 100644 --- a/main/src/ui/conversation_selector/conversation_selector.vala +++ b/main/src/ui/conversation_selector/conversation_selector.vala @@ -11,6 +11,7 @@ public class ConversationSelector : ListBox { public signal void conversation_selected(Conversation conversation); private StreamInteractor stream_interactor; + private uint? drag_timeout; private HashMap rows = new HashMap(Conversation.hash_func, Conversation.equals_func); public ConversationSelector init(StreamInteractor stream_interactor) { @@ -72,10 +73,36 @@ public class ConversationSelector : ListBox { rows[conversation] = row; add(row); row.main_revealer.set_reveal_child(true); + drag_dest_set(row, DestDefaults.MOTION, null, Gdk.DragAction.COPY); + drag_dest_set_track_motion(row, true); + row.drag_motion.connect(this.on_drag_motion); + row.drag_leave.connect(this.on_drag_leave); } invalidate_sort(); } + public bool on_drag_motion(Widget widget, Gdk.DragContext context, + int x, int y, uint time) { + if (this.drag_timeout != null) + return false; + this.drag_timeout = Timeout.add(200, () => { + if (widget.get_type().is_a(typeof(ConversationRow))) { + ConversationRow row = widget as ConversationRow; + conversation_selected(row.conversation); + } + this.drag_timeout = null; + return false; + }); + return false; + } + + public void on_drag_leave(Widget widget, Gdk.DragContext context, uint time) { + if (this.drag_timeout != null) { + Source.remove(this.drag_timeout); + this.drag_timeout = null; + } + } + private void select_fallback_conversation(Conversation conversation) { if (get_selected_row() == rows[conversation]) { int index = rows[conversation].get_index(); -- cgit v1.2.3-54-g00ecf