implements sending
This commit is contained in:
57
src/transcript-view/transcript-view.vala
Normal file
57
src/transcript-view/transcript-view.vala
Normal file
@@ -0,0 +1,57 @@
|
||||
using Gtk;
|
||||
using Adw;
|
||||
|
||||
class TranscriptView : Adw.Bin {
|
||||
public MessageListView message_list;
|
||||
public Entry message_entry;
|
||||
public signal void on_send(string message);
|
||||
|
||||
private Box container;
|
||||
private Button send_button;
|
||||
|
||||
public TranscriptView () {
|
||||
container = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
|
||||
set_child (container);
|
||||
|
||||
// Create message list view
|
||||
message_list = new MessageListView();
|
||||
message_list.set_vexpand(true);
|
||||
container.append(message_list);
|
||||
|
||||
// Create bottom box for input
|
||||
var input_box = new Box(Orientation.HORIZONTAL, 6);
|
||||
input_box.add_css_class("message-input-box");
|
||||
input_box.set_valign(Align.END);
|
||||
input_box.set_spacing(6);
|
||||
container.append(input_box);
|
||||
|
||||
// Create message entry
|
||||
message_entry = new Entry();
|
||||
message_entry.add_css_class("message-input-entry");
|
||||
message_entry.set_placeholder_text("Type a message...");
|
||||
message_entry.set_hexpand(true);
|
||||
message_entry.changed.connect(on_text_changed);
|
||||
message_entry.activate.connect(on_request_send);
|
||||
input_box.append(message_entry);
|
||||
|
||||
// Create send button
|
||||
send_button = new Button();
|
||||
send_button.set_label("Send");
|
||||
send_button.set_sensitive(false);
|
||||
send_button.add_css_class("suggested-action");
|
||||
send_button.clicked.connect(on_request_send);
|
||||
input_box.append(send_button);
|
||||
}
|
||||
|
||||
private void on_text_changed() {
|
||||
send_button.set_sensitive(message_entry.text.length > 0);
|
||||
}
|
||||
|
||||
private void on_request_send() {
|
||||
if (message_entry.text.length > 0) {
|
||||
on_send(message_entry.text);
|
||||
message_entry.text = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user