anotherim-desktop/main/src/ui/chat_input/view.vala

115 lines
4.3 KiB
Vala
Raw Normal View History

2017-03-02 14:37:32 +00:00
using Gdk;
using Gee;
using Gtk;
using Dino.Entities;
using Xmpp;
2017-03-23 23:15:00 +00:00
namespace Dino.Ui.ChatInput {
2017-03-10 17:07:28 +00:00
[GtkTemplate (ui = "/im/dino/Dino/chat_input.ui")]
2017-03-23 23:15:00 +00:00
public class View : Box {
2017-03-02 14:37:32 +00:00
2017-08-25 19:20:09 +00:00
public string text {
owned get { return chat_text_view.text_view.buffer.text; }
set { chat_text_view.text_view.buffer.text = value; }
2017-08-25 19:20:09 +00:00
}
2017-03-02 14:37:32 +00:00
private StreamInteractor stream_interactor;
2017-03-23 23:15:00 +00:00
private Conversation? conversation;
2017-03-02 14:37:32 +00:00
private HashMap<Conversation, string> entry_cache = new HashMap<Conversation, string>(Conversation.hash_func, Conversation.equals_func);
2019-08-02 01:15:12 +00:00
[GtkChild] public Frame frame;
[GtkChild] public ChatTextView chat_text_view;
2019-08-02 01:15:12 +00:00
[GtkChild] public Box outer_box;
[GtkChild] public Button file_button;
[GtkChild] public Separator file_separator;
[GtkChild] public Label chat_input_status;
public EncryptionButton encryption_widget;
2017-03-02 14:37:32 +00:00
2018-07-04 21:38:28 +00:00
public View init(StreamInteractor stream_interactor) {
2017-03-02 14:37:32 +00:00
this.stream_interactor = stream_interactor;
2017-03-23 23:15:00 +00:00
2019-09-09 17:47:11 +00:00
encryption_widget = new EncryptionButton(stream_interactor) { relief=ReliefStyle.NONE, margin_top=3, valign=Align.START, visible=true };
2019-08-02 01:15:12 +00:00
file_button.get_style_context().add_class("dino-attach-button");
encryption_widget.get_style_context().add_class("dino-chatinput-button");
2019-09-09 17:47:11 +00:00
2019-09-14 13:48:07 +00:00
// Emoji button for emoji picker (recents don't work < 3.22.19, category icons don't work <3.23.2)
if (Gtk.get_major_version() >= 3 && Gtk.get_minor_version() >= 24) {
MenuButton emoji_button = new MenuButton() { relief=ReliefStyle.NONE, margin_top=3, valign=Align.START, visible=true };
emoji_button.get_style_context().add_class("flat");
emoji_button.get_style_context().add_class("dino-chatinput-button");
emoji_button.image = new Image.from_icon_name("dino-emoticon-symbolic", IconSize.BUTTON) { visible=true };
EmojiChooser chooser = new EmojiChooser();
chooser.emoji_picked.connect((emoji) => {
chat_text_view.text_view.buffer.insert_at_cursor(emoji, emoji.data.length);
2019-09-14 13:48:07 +00:00
});
emoji_button.set_popover(chooser);
outer_box.add(emoji_button);
}
2019-09-09 17:47:11 +00:00
outer_box.add(encryption_widget);
Util.force_css(frame, "* { border-radius: 3px; }");
2018-07-04 21:38:28 +00:00
return this;
2017-03-02 14:37:32 +00:00
}
2020-04-22 13:44:12 +00:00
public void set_file_upload_active(bool active) {
file_button.visible = active;
file_separator.visible = active;
2019-09-10 18:56:00 +00:00
}
2017-03-23 23:15:00 +00:00
2019-09-10 18:56:00 +00:00
public void initialize_for_conversation(Conversation conversation) {
if (this.conversation != null) entry_cache[this.conversation] = chat_text_view.text_view.buffer.text;
2017-03-02 14:37:32 +00:00
this.conversation = conversation;
chat_text_view.text_view.buffer.text = "";
2017-03-02 14:37:32 +00:00
if (entry_cache.has_key(conversation)) {
chat_text_view.text_view.buffer.text = entry_cache[conversation];
2017-03-02 14:37:32 +00:00
}
do_focus();
2017-03-02 14:37:32 +00:00
}
2019-08-02 01:15:12 +00:00
public void set_input_state(Plugins.InputFieldStatus.MessageType message_type) {
switch (message_type) {
case Plugins.InputFieldStatus.MessageType.NONE:
this.get_style_context().remove_class("dino-input-warning");
this.get_style_context().remove_class("dino-input-error");
break;
case Plugins.InputFieldStatus.MessageType.INFO:
this.get_style_context().remove_class("dino-input-warning");
this.get_style_context().remove_class("dino-input-error");
break;
case Plugins.InputFieldStatus.MessageType.WARNING:
this.get_style_context().add_class("dino-input-warning");
this.get_style_context().remove_class("dino-input-error");
break;
case Plugins.InputFieldStatus.MessageType.ERROR:
this.get_style_context().remove_class("dino-input-warning");
this.get_style_context().add_class("dino-input-error");
break;
2017-03-02 14:37:32 +00:00
}
2019-08-02 01:15:12 +00:00
}
public void highlight_state_description() {
chat_input_status.get_style_context().add_class("input-status-highlight-once");
Timeout.add_seconds(1, () => {
chat_input_status.get_style_context().remove_class("input-status-highlight-once");
return false;
});
2017-03-02 14:37:32 +00:00
}
public void do_focus() {
chat_text_view.text_view.grab_focus();
}
2017-03-02 14:37:32 +00:00
}
2017-03-10 17:07:28 +00:00
2017-08-16 20:44:12 +00:00
}