diff options
author | fiaxh <git@lightrise.org> | 2019-04-12 16:24:43 +0200 |
---|---|---|
committer | fiaxh <git@lightrise.org> | 2019-04-14 09:46:54 +0200 |
commit | d9e45071d0d3cd5a7a162908267c98c6366038bf (patch) | |
tree | 1d68dcd4010b5c057b1d862f9ece8013212c2575 /main/src/ui/conversation_selector | |
parent | 27fe07c3b41a53a276fb5f6a71c4c97cb0279170 (diff) | |
download | dino-d9e45071d0d3cd5a7a162908267c98c6366038bf.tar.gz dino-d9e45071d0d3cd5a7a162908267c98c6366038bf.zip |
Only use UI data for active converations cycling, clean up ConversationSelector
Diffstat (limited to 'main/src/ui/conversation_selector')
-rw-r--r-- | main/src/ui/conversation_selector/list.vala | 51 | ||||
-rw-r--r-- | main/src/ui/conversation_selector/view.vala | 23 |
2 files changed, 32 insertions, 42 deletions
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<Conversation, ConversationRow> rows = new HashMap<Conversation, ConversationRow>(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; - } - -} - -} |