From d9e45071d0d3cd5a7a162908267c98c6366038bf Mon Sep 17 00:00:00 2001 From: fiaxh Date: Fri, 12 Apr 2019 16:24:43 +0200 Subject: Only use UI data for active converations cycling, clean up ConversationSelector --- main/src/ui/conversation_selector/list.vala | 51 ++++++++++++++++++----------- main/src/ui/conversation_selector/view.vala | 23 ------------- 2 files changed, 32 insertions(+), 42 deletions(-) delete mode 100644 main/src/ui/conversation_selector/view.vala (limited to 'main/src/ui/conversation_selector') diff --git a/main/src/ui/conversation_selector/list.vala b/main/src/ui/conversation_selector/list.vala index 8d71419b..95e5aae7 100644 --- a/main/src/ui/conversation_selector/list.vala +++ b/main/src/ui/conversation_selector/list.vala @@ -14,14 +14,9 @@ public class List : ListBox { private string[]? filter_values; private HashMap rows = new HashMap(Conversation.hash_func, Conversation.equals_func); - public List(StreamInteractor stream_interactor) { + public List init(StreamInteractor stream_interactor) { this.stream_interactor = stream_interactor; - get_style_context().add_class("sidebar"); - set_filter_func(filter); - set_header_func(header); - set_sort_func(sort); - stream_interactor.get_module(ConversationManager.IDENTITY).conversation_activated.connect(add_conversation); stream_interactor.get_module(ConversationManager.IDENTITY).conversation_deactivated.connect(remove_conversation); stream_interactor.get_module(MessageProcessor.IDENTITY).message_received.connect(on_message_received); @@ -34,6 +29,17 @@ public class List : ListBox { foreach (Conversation conversation in stream_interactor.get_module(ConversationManager.IDENTITY).get_active_conversations()) { add_conversation(conversation); } + return this; + } + + construct { + this.stream_interactor = stream_interactor; + + get_style_context().add_class("sidebar"); + set_filter_func(filter); + set_header_func(header); + set_sort_func(sort); + realize.connect(() => { ListBoxRow? first_row = get_row_at_index(0); if (first_row != null) { @@ -77,37 +83,44 @@ public class List : ListBox { row = new ConversationRow(stream_interactor, conversation); rows[conversation] = row; add(row); - row.closed.connect(() => { select_next_conversation(conversation); }); + row.closed.connect(() => { select_fallback_conversation(conversation); }); row.main_revealer.set_reveal_child(true); } invalidate_sort(); } - private void select_next_conversation(Conversation conversation) { + private void select_fallback_conversation(Conversation conversation) { if (get_selected_row() == rows[conversation]) { int index = rows[conversation].get_index(); - ListBoxRow? index_p1 = get_row_at_index(index + 1); - if (index_p1 != null) { - select_row(index_p1); - row_activated(index_p1); - } else if (index > 0) { - ListBoxRow? index_m1 = get_row_at_index(index - 1); - if (index_m1 != null) { - select_row(index_m1); - row_activated(index_m1); - } + ListBoxRow? next_select_row = get_row_at_index(index + 1); + if (next_select_row == null) { + next_select_row = get_row_at_index(index - 1); + } + if (next_select_row != null) { + select_row(next_select_row); + row_activated(next_select_row); } } } private void remove_conversation(Conversation conversation) { - select_next_conversation(conversation); + select_fallback_conversation(conversation); if (rows.has_key(conversation) && !conversation.active) { remove(rows[conversation]); rows.unset(conversation); } } + public void loop_conversations(bool backwards) { + int index = get_selected_row().get_index(); + int new_index = ((index + (backwards ? -1 : 1)) + rows.size) % rows.size; + ListBoxRow? next_select_row = get_row_at_index(new_index); + if (next_select_row != null) { + select_row(next_select_row); + row_activated(next_select_row); + } + } + private void header(ListBoxRow row, ListBoxRow? before_row) { if (row.get_header() == null && before_row != null) { row.set_header(new Separator(Orientation.HORIZONTAL)); diff --git a/main/src/ui/conversation_selector/view.vala b/main/src/ui/conversation_selector/view.vala deleted file mode 100644 index d06ad133..00000000 --- a/main/src/ui/conversation_selector/view.vala +++ /dev/null @@ -1,23 +0,0 @@ -using Gee; -using Gtk; -using Gdk; - -using Dino.Entities; - -namespace Dino.Ui.ConversationSelector { - -[GtkTemplate (ui = "/im/dino/Dino/conversation_selector/view.ui")] -public class View : Box { - public List conversation_list; - - [GtkChild] private ScrolledWindow scrolled; - - public View init(StreamInteractor stream_interactor) { - conversation_list = new List(stream_interactor) { visible=true }; - scrolled.add(conversation_list); - return this; - } - -} - -} -- cgit v1.2.3-70-g09d2