aboutsummaryrefslogtreecommitdiff
path: root/libdino/src/ui/conversation_selector/view.vala
blob: c551d2587128bf5f16fe05ecebb1c0b1c1f12b40 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using Gee;
using Gtk;
using Gdk;

using Dino.Entities;

namespace Dino.Ui.ConversationSelector {

[GtkTemplate (ui = "/org/dino-im/conversation_selector/view.ui")]
public class View : Grid {
    public List conversation_list;

    [GtkChild]
    public SearchEntry search_entry;

    [GtkChild]
    public SearchBar search_bar;

    [GtkChild]
    private ScrolledWindow scrolled;

    public View(StreamInteractor stream_interactor) {
        conversation_list = new List(stream_interactor);
        scrolled.add(conversation_list);
        search_entry.key_release_event.connect(search_key_release_event);
        search_entry.search_changed.connect(search_changed);
    }

    public void conversation_selected(Conversation? conversation) {
        search_entry.set_text("");
    }

    private void refilter() {
        string[]? values = null;
        string str = search_entry.get_text ();
        if (str != "") values = str.split(" ");
        conversation_list.set_filter_values(values);
    }

    private void search_changed(Editable editable) {
        refilter();
    }

    private bool search_key_release_event(EventKey event) {
        conversation_list.select_row(conversation_list.get_row_at_y(0));
        if (event.keyval == Key.Down) {
            ConversationRow? row = (ConversationRow) conversation_list.get_row_at_index(0);
            if (row != null) {
                conversation_list.select_row(row);
                row.grab_focus();
            }
        }
        return false;
    }
}
}