diff options
author | Thibaut Girka <thib@sitedethib.com> | 2018-04-08 20:35:54 +0200 |
---|---|---|
committer | fiaxh <git@lightrise.org> | 2020-02-22 02:47:08 +0100 |
commit | a7e92960a3f4d31cfb2fbe2e3ba4941cf3b8faf2 (patch) | |
tree | c857cf89ce5048ca51bedc907b4e420d4c5955a7 /main | |
parent | f5e0ecafae87c73d4d2959976849306011b65d85 (diff) | |
download | dino-a7e92960a3f4d31cfb2fbe2e3ba4941cf3b8faf2.tar.gz dino-a7e92960a3f4d31cfb2fbe2e3ba4941cf3b8faf2.zip |
Allow switching conversations when dragging and dropping
Diffstat (limited to 'main')
-rw-r--r-- | main/src/ui/conversation_selector/conversation_selector.vala | 27 |
1 files changed, 27 insertions, 0 deletions
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<Conversation, ConversationSelectorRow> rows = new HashMap<Conversation, ConversationSelectorRow>(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(); |