aboutsummaryrefslogtreecommitdiff
path: root/main/src
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2019-04-12 16:24:43 +0200
committerfiaxh <git@lightrise.org>2019-04-14 09:46:54 +0200
commitd9e45071d0d3cd5a7a162908267c98c6366038bf (patch)
tree1d68dcd4010b5c057b1d862f9ece8013212c2575 /main/src
parent27fe07c3b41a53a276fb5f6a71c4c97cb0279170 (diff)
downloaddino-d9e45071d0d3cd5a7a162908267c98c6366038bf.tar.gz
dino-d9e45071d0d3cd5a7a162908267c98c6366038bf.zip
Only use UI data for active converations cycling, clean up ConversationSelector
Diffstat (limited to 'main/src')
-rw-r--r--main/src/ui/application.vala4
-rw-r--r--main/src/ui/conversation_selector/list.vala51
-rw-r--r--main/src/ui/conversation_selector/view.vala23
-rw-r--r--main/src/ui/unified_window.vala10
-rw-r--r--main/src/ui/unified_window_controller.vala13
5 files changed, 42 insertions, 59 deletions
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[]{"<Ctrl>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[]{"<Ctrl>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[]{"<Ctrl><Shift>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<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;
- }
-
-}
-
-}
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<Conversation> 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);
}