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/CMakeLists.txt | 2 -- main/data/conversation_selector/view.ui | 15 --------- main/data/unified_main_content.ui | 9 ++++- main/src/ui/application.vala | 4 +-- main/src/ui/conversation_selector/list.vala | 51 ++++++++++++++++++----------- main/src/ui/conversation_selector/view.vala | 23 ------------- main/src/ui/unified_window.vala | 10 +++--- main/src/ui/unified_window_controller.vala | 13 ++------ 8 files changed, 50 insertions(+), 77 deletions(-) delete mode 100644 main/data/conversation_selector/view.ui delete mode 100644 main/src/ui/conversation_selector/view.vala diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index a0996093..ea1a649c 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -34,7 +34,6 @@ set(RESOURCE_LIST conversation_list_titlebar.ui conversation_list_titlebar_csd.ui global_search.ui - conversation_selector/view.ui conversation_selector/chat_row_tooltip.ui conversation_selector/conversation_row.ui conversation_summary/image_toolbar.ui @@ -105,7 +104,6 @@ SOURCES src/ui/global_search.vala src/ui/conversation_selector/conversation_row.vala src/ui/conversation_selector/list.vala - src/ui/conversation_selector/view.vala src/ui/conversation_summary/chat_state_populator.vala src/ui/conversation_summary/content_item_widget_factory.vala src/ui/conversation_summary/content_populator.vala diff --git a/main/data/conversation_selector/view.ui b/main/data/conversation_selector/view.ui deleted file mode 100644 index c5560ad1..00000000 --- a/main/data/conversation_selector/view.ui +++ /dev/null @@ -1,15 +0,0 @@ - - - - diff --git a/main/data/unified_main_content.ui b/main/data/unified_main_content.ui index b2f3a891..0fde37e8 100644 --- a/main/data/unified_main_content.ui +++ b/main/data/unified_main_content.ui @@ -5,8 +5,15 @@ horizontal True - + + True + never True + + + True + + False diff --git a/main/src/ui/application.vala b/main/src/ui/application.vala index ca78c735..29dec20c 100644 --- a/main/src/ui/application.vala +++ b/main/src/ui/application.vala @@ -134,12 +134,12 @@ public class Dino.Ui.Application : Gtk.Application, Dino.Application { set_accels_for_action("app.add_conference", new string[]{"G"}); SimpleAction loop_conversations_action = new SimpleAction("loop_conversations", null); - loop_conversations_action.activate.connect(() => {controller.loop_conversations(false);}); + loop_conversations_action.activate.connect(() => { window.loop_conversations(false); }); add_action(loop_conversations_action); set_accels_for_action("app.loop_conversations", new string[]{"Tab"}); SimpleAction loop_conversations_bw_action = new SimpleAction("loop_conversations_bw", null); - loop_conversations_bw_action.activate.connect(() => {controller.loop_conversations(true);}); + loop_conversations_bw_action.activate.connect(() => { window.loop_conversations(true); }); add_action(loop_conversations_bw_action); set_accels_for_action("app.loop_conversations_bw", new string[]{"Tab"}); } 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; - } - -} - -} diff --git a/main/src/ui/unified_window.vala b/main/src/ui/unified_window.vala index 123d3efb..38a95091 100644 --- a/main/src/ui/unified_window.vala +++ b/main/src/ui/unified_window.vala @@ -43,7 +43,7 @@ public class UnifiedWindow : Gtk.Window { public ChatInput.View chat_input; public ConversationListTitlebar conversation_list_titlebar; public ConversationListTitlebarCsd conversation_list_titlebar_csd; - public ConversationSelector.View filterable_conversation_list; + public ConversationSelector.List filterable_conversation_list; public ConversationSummary.ConversationView conversation_frame; public ConversationTitlebar conversation_titlebar; public ConversationTitlebarCsd conversation_titlebar_csd; @@ -88,8 +88,6 @@ public class UnifiedWindow : Gtk.Window { if (this.conversation == null || !this.conversation.equals(conversation)) { this.conversation = conversation; conversation_selected(conversation); - - } } @@ -99,7 +97,7 @@ public class UnifiedWindow : Gtk.Window { box.add(paned); chat_input = ((ChatInput.View) builder.get_object("chat_input")).init(stream_interactor); conversation_frame = ((ConversationSummary.ConversationView) builder.get_object("conversation_frame")).init(stream_interactor); - filterable_conversation_list = ((ConversationSelector.View) builder.get_object("conversation_list")).init(stream_interactor); + filterable_conversation_list = ((ConversationSelector.List) builder.get_object("conversation_list")).init(stream_interactor); goto_end_revealer = (Revealer) builder.get_object("goto_end_revealer"); goto_end_button = (Button) builder.get_object("goto_end_button"); search_box = ((GlobalSearch) builder.get_object("search_box")).init(stream_interactor); @@ -167,6 +165,10 @@ public class UnifiedWindow : Gtk.Window { } } } + + public void loop_conversations(bool backwards) { + filterable_conversation_list.loop_conversations(backwards); + } } public class WelcomePlceholder : UnifiedWindowPlaceholder { diff --git a/main/src/ui/unified_window_controller.vala b/main/src/ui/unified_window_controller.vala index ce15ecc9..912b235c 100644 --- a/main/src/ui/unified_window_controller.vala +++ b/main/src/ui/unified_window_controller.vala @@ -79,7 +79,7 @@ public class UnifiedWindowController : Object { window.accounts_placeholder.primary_button.clicked.connect(() => { app.activate_action("accounts", null); }); window.conversations_placeholder.primary_button.clicked.connect(() => { app.activate_action("add_chat", null); }); window.conversations_placeholder.secondary_button.clicked.connect(() => { app.activate_action("add_conference", null); }); - window.filterable_conversation_list.conversation_list.conversation_selected.connect((conversation) => select_conversation(conversation)); + window.filterable_conversation_list.conversation_selected.connect((conversation) => select_conversation(conversation)); var vadjustment = window.conversation_frame.scrolled.vadjustment; vadjustment.notify["value"].connect(() => { @@ -131,7 +131,7 @@ public class UnifiedWindowController : Object { stream_interactor.get_module(ChatInteraction.IDENTITY).on_conversation_selected(conversation); conversation.active = true; // only for conversation_selected - window.filterable_conversation_list.conversation_list.on_conversation_selected(conversation); // only for conversation_opened + window.filterable_conversation_list.on_conversation_selected(conversation); // only for conversation_opened if (do_reset_search) { reset_search_entry(); @@ -142,15 +142,6 @@ public class UnifiedWindowController : Object { } } - public void loop_conversations(bool backwards = false) { - Gee.List conversations = stream_interactor.get_module(ConversationManager.IDENTITY).get_active_conversations(); - conversations.sort((a, b) => { return b.last_active.compare(a.last_active); }); - int index = conversations.index_of(this.conversation); - index += backwards ? -1 : 1; - select_conversation(conversations.get(index % conversations.size)); - } - - private void update_conversation_display_name() { conversation_display_name = Util.get_conversation_display_name(stream_interactor, conversation); } -- cgit v1.2.3-70-g09d2