aboutsummaryrefslogtreecommitdiff
path: root/main/src/ui/global_search.vala
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2021-10-12 16:23:25 +0200
committerfiaxh <git@lightrise.org>2021-10-12 19:43:57 +0200
commitbea85c8ab5f74d96f37c1b3a6ea1e83edd0de500 (patch)
tree973d1211daa374679d87c27312b4d1d671fe7944 /main/src/ui/global_search.vala
parent76e425ed2705349b201444e78719896419862b00 (diff)
downloaddino-bea85c8ab5f74d96f37c1b3a6ea1e83edd0de500.tar.gz
dino-bea85c8ab5f74d96f37c1b3a6ea1e83edd0de500.zip
Fix compiler warnings ('cast between incompatible function types') by not connecting closures
Diffstat (limited to 'main/src/ui/global_search.vala')
-rw-r--r--main/src/ui/global_search.vala94
1 files changed, 50 insertions, 44 deletions
diff --git a/main/src/ui/global_search.vala b/main/src/ui/global_search.vala
index f765d4d9..abefccac 100644
--- a/main/src/ui/global_search.vala
+++ b/main/src/ui/global_search.vala
@@ -28,54 +28,60 @@ public class GlobalSearch : Overlay {
search_entry.search_changed.connect(() => {
set_search(search_entry.text);
});
- search_entry.notify["text"].connect_after(() => { update_auto_complete(); });
- search_entry.notify["cursor-position"].connect_after(() => { update_auto_complete(); });
-
- results_scrolled.vadjustment.notify["value"].connect(() => {
- if (results_scrolled.vadjustment.upper - (results_scrolled.vadjustment.value + results_scrolled.vadjustment.page_size) < 100) {
- if (!reloading_mutex.trylock()) return;
- Gee.List<MessageItem> new_messages = stream_interactor.get_module(SearchProcessor.IDENTITY).match_messages(search, loaded_results);
- if (new_messages.size == 0) {
- reloading_mutex.unlock();
- return;
- }
- loaded_results += new_messages.size;
- append_messages(new_messages);
+ search_entry.notify["text"].connect_after(update_auto_complete);
+ search_entry.notify["cursor-position"].connect_after(update_auto_complete);
+
+ results_scrolled.vadjustment.notify["value"].connect(on_scrolled_window_vadjustment_value);
+ results_scrolled.vadjustment.notify["upper"].connect_after(on_scrolled_window_vadjustment_upper);
+
+ event.connect(on_event);
+
+ return this;
+ }
+
+ private void on_scrolled_window_vadjustment_value() {
+ if (results_scrolled.vadjustment.upper - (results_scrolled.vadjustment.value + results_scrolled.vadjustment.page_size) < 100) {
+ if (!reloading_mutex.trylock()) return;
+ Gee.List<MessageItem> new_messages = stream_interactor.get_module(SearchProcessor.IDENTITY).match_messages(search, loaded_results);
+ if (new_messages.size == 0) {
+ reloading_mutex.unlock();
+ return;
}
- });
- results_scrolled.vadjustment.notify["upper"].connect_after(() => {
- reloading_mutex.trylock();
- reloading_mutex.unlock();
- });
+ loaded_results += new_messages.size;
+ append_messages(new_messages);
+ }
+ }
- event.connect((event) => {
- if (auto_complete_overlay.visible) {
- if (event.type == Gdk.EventType.KEY_PRESS && event.key.keyval == Gdk.Key.Up) {
- var row = auto_complete_list.get_selected_row();
- var index = row == null ? -1 : row.get_index() - 1;
- if (index == -1) index = (int)auto_complete_list.get_children().length() - 1;
- auto_complete_list.select_row(auto_complete_list.get_row_at_index(index));
- return true;
- }
- if (event.type == Gdk.EventType.KEY_PRESS && event.key.keyval == Gdk.Key.Down) {
- var row = auto_complete_list.get_selected_row();
- var index = row == null ? 0 : row.get_index() + 1;
- if (index == auto_complete_list.get_children().length()) index = 0;
- auto_complete_list.select_row(auto_complete_list.get_row_at_index(index));
- return true;
- }
- if (event.type == Gdk.EventType.KEY_PRESS && event.key.keyval == Gdk.Key.Tab ||
+ private void on_scrolled_window_vadjustment_upper() {
+ reloading_mutex.trylock();
+ reloading_mutex.unlock();
+ }
+
+ private bool on_event(Gdk.Event event) {
+ if (auto_complete_overlay.visible) {
+ if (event.type == Gdk.EventType.KEY_PRESS && event.key.keyval == Gdk.Key.Up) {
+ var row = auto_complete_list.get_selected_row();
+ var index = row == null ? -1 : row.get_index() - 1;
+ if (index == -1) index = (int)auto_complete_list.get_children().length() - 1;
+ auto_complete_list.select_row(auto_complete_list.get_row_at_index(index));
+ return true;
+ }
+ if (event.type == Gdk.EventType.KEY_PRESS && event.key.keyval == Gdk.Key.Down) {
+ var row = auto_complete_list.get_selected_row();
+ var index = row == null ? 0 : row.get_index() + 1;
+ if (index == auto_complete_list.get_children().length()) index = 0;
+ auto_complete_list.select_row(auto_complete_list.get_row_at_index(index));
+ return true;
+ }
+ if (event.type == Gdk.EventType.KEY_PRESS && event.key.keyval == Gdk.Key.Tab ||
event.type == Gdk.EventType.KEY_RELEASE && event.key.keyval == Gdk.Key.Return) {
- auto_complete_list.get_selected_row().activate();
- return true;
- }
+ auto_complete_list.get_selected_row().activate();
+ return true;
}
- // TODO: Handle cursor movement in results
- // TODO: Direct all keystrokes to text input
- return false;
- });
-
- return this;
+ }
+ // TODO: Handle cursor movement in results
+ // TODO: Direct all keystrokes to text input
+ return false;
}
private void update_auto_complete() {