blob: 81f2bd0f825610614959a1f312b396b98bd2034d (
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
using Gdk;
using Gee;
using Gtk;
using Dino.Entities;
using Xmpp;
namespace Dino.Ui.ChatInput {
[GtkTemplate (ui = "/im/dino/Dino/chat_input.ui")]
public class View : Box {
public string text {
owned get { return chat_text_view.text_view.buffer.text; }
set { chat_text_view.text_view.buffer.text = value; }
}
private StreamInteractor stream_interactor;
private Conversation? conversation;
private HashMap<Conversation, string> entry_cache = new HashMap<Conversation, string>(Conversation.hash_func, Conversation.equals_func);
[GtkChild] public unowned Frame frame;
[GtkChild] public unowned ChatTextView chat_text_view;
[GtkChild] public unowned Box outer_box;
[GtkChild] public unowned Button file_button;
[GtkChild] public unowned MenuButton emoji_button;
[GtkChild] public unowned MenuButton encryption_button;
[GtkChild] public unowned Separator file_separator;
[GtkChild] public unowned Label chat_input_status;
public EncryptionButton encryption_widget;
public View init(StreamInteractor stream_interactor) {
this.stream_interactor = stream_interactor;
encryption_widget = new EncryptionButton(stream_interactor, encryption_button);
EmojiChooser chooser = new EmojiChooser();
chooser.emoji_picked.connect((emoji) => {
chat_text_view.text_view.buffer.insert_at_cursor(emoji, emoji.data.length);
});
emoji_button.set_popover(chooser);
Util.force_css(frame, "* { border-radius: 3px; }");
return this;
}
public void set_file_upload_active(bool active) {
file_button.visible = active;
file_separator.visible = active;
}
public void initialize_for_conversation(Conversation conversation) {
if (this.conversation != null) entry_cache[this.conversation] = chat_text_view.text_view.buffer.text;
this.conversation = conversation;
chat_text_view.text_view.buffer.text = "";
if (entry_cache.has_key(conversation)) {
chat_text_view.text_view.buffer.text = entry_cache[conversation];
}
do_focus();
}
public void set_input_state(Plugins.InputFieldStatus.MessageType message_type) {
switch (message_type) {
case Plugins.InputFieldStatus.MessageType.NONE:
this.remove_css_class("dino-input-warning");
this.remove_css_class("dino-input-error");
break;
case Plugins.InputFieldStatus.MessageType.INFO:
this.remove_css_class("dino-input-warning");
this.remove_css_class("dino-input-error");
break;
case Plugins.InputFieldStatus.MessageType.WARNING:
this.add_css_class("dino-input-warning");
this.remove_css_class("dino-input-error");
break;
case Plugins.InputFieldStatus.MessageType.ERROR:
this.remove_css_class("dino-input-warning");
this.add_css_class("dino-input-error");
break;
}
}
public void highlight_state_description() {
chat_input_status.add_css_class("input-status-highlight-once");
Timeout.add_seconds(1, () => {
chat_input_status.remove_css_class("input-status-highlight-once");
return false;
});
}
public void do_focus() {
chat_text_view.text_view.grab_focus();
}
}
}
|