Move chat input to .ui file, fix smiley conversion on enter

This commit is contained in:
fiaxh 2018-05-10 15:08:14 +02:00
parent 4067e45779
commit e852a0a60b
2 changed files with 55 additions and 36 deletions

View file

@ -4,28 +4,58 @@
<template class="DinoUiChatInputView"> <template class="DinoUiChatInputView">
<property name="hexpand">True</property> <property name="hexpand">True</property>
<property name="orientation">horizontal</property> <property name="orientation">horizontal</property>
<property name="margin">5</property>
<property name="visible">True</property> <property name="visible">True</property>
<style> <style>
<class name="dino-chatinput"/> <class name="dino-chatinput"/>
</style> </style>
<child> <child>
<object class="GtkScrolledWindow" id="scrolled"> <object class="GtkFrame" id="frame">
<property name="max_content_height">300</property> <property name="margin">12</property>
<property name="propagate_natural_height">True</property> <property name="margin_top">0</property>
<property name="visible">True</property> <property name="visible">True</property>
<child> <child>
<object class="GtkFrame"> <object class="GtkBox" id="outer_box">
<property name="orientation">horizontal</property>
<property name="visible">True</property> <property name="visible">True</property>
<child> <child>
<object class="GtkBox" id="box"> <object class="GtkButton" id="file_button">
<property name="can-focus">False</property>
<property name="margin-top">3</property>
<property name="relief">none</property>
<property name="valign">start</property>
<property name="visible">True</property>
<style>
<class name="flat"/>
<class name="dino-chatinput-button"/>
<class name="image-button"/>
</style>
<child>
<object class="GtkImage">
<property name="icon-name">mail-attachment-symbolic</property>
<property name="icon-size">1</property>
<property name="visible">True</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkSeparator" id="file_separator">
<property name="orientation">vertical</property>
<property name="visible">True</property>
</object>
</child>
<child>
<object class="GtkScrolledWindow" id="scrolled">
<property name="max_content_height">300</property>
<property name="propagate_natural_height">true</property>
<property name="visible">True</property> <property name="visible">True</property>
<child> <child>
<object class="GtkTextView" id="text_input"> <object class="GtkTextView" id="text_input">
<property name="wrap-mode">GTK_WRAP_WORD_CHAR</property>
<property name="border-width">5</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="hexpand">True</property> <property name="hexpand">True</property>
<property name="margin">8</property>
<property name="wrap-mode">GTK_WRAP_WORD_CHAR</property>
<property name="valign">center</property>
<property name="visible">True</property> <property name="visible">True</property>
</object> </object>
</child> </child>

View file

@ -7,12 +7,9 @@ using Xmpp;
namespace Dino.Ui.ChatInput { namespace Dino.Ui.ChatInput {
[GtkTemplate (ui = "/im/dino/Dino/chat_input.ui")]
public class View : Box { public class View : Box {
private ScrolledWindow scrolled;
private TextView text_input;
private Box outer_box;
public string text { public string text {
owned get { return text_input.buffer.text; } owned get { return text_input.buffer.text; }
set { text_input.buffer.text = value; } set { text_input.buffer.text = value; }
@ -22,19 +19,26 @@ public class View : Box {
private Conversation? conversation; private Conversation? conversation;
private HashMap<Conversation, string> entry_cache = new HashMap<Conversation, string>(Conversation.hash_func, Conversation.equals_func); private HashMap<Conversation, string> entry_cache = new HashMap<Conversation, string>(Conversation.hash_func, Conversation.equals_func);
private int vscrollbar_min_height; private int vscrollbar_min_height;
private OccupantsTabCompletor occupants_tab_completor; private OccupantsTabCompletor occupants_tab_completor;
private SmileyConverter smiley_converter; private SmileyConverter smiley_converter;
private EditHistory edit_history; private EditHistory edit_history;
private EncryptionButton encryption_widget;
private Button file_button = new Button.from_icon_name("mail-attachment-symbolic", IconSize.MENU) { margin_top=3, valign=Align.START, relief=ReliefStyle.NONE }; [GtkChild] private Frame frame;
private Separator file_separator = new Separator(Orientation.VERTICAL); [GtkChild] private ScrolledWindow scrolled;
[GtkChild] private TextView text_input;
[GtkChild] private Box outer_box;
[GtkChild] private Button file_button;
[GtkChild] private Separator file_separator;
private EncryptionButton encryption_widget = new EncryptionButton() { margin_top=3, valign=Align.START, visible=true };
public View(StreamInteractor stream_interactor) { public View(StreamInteractor stream_interactor) {
this.stream_interactor = stream_interactor; this.stream_interactor = stream_interactor;
outer_box = new Box(Orientation.HORIZONTAL, 0) { visible=true }; occupants_tab_completor = new OccupantsTabCompletor(stream_interactor, text_input);
smiley_converter = new SmileyConverter(stream_interactor, text_input);
edit_history = new EditHistory(text_input, GLib.Application.get_default());
file_button.get_style_context().add_class("dino-chatinput-button");
file_button.clicked.connect(() => { file_button.clicked.connect(() => {
PreviewFileChooserNative chooser = new PreviewFileChooserNative("Select file", get_toplevel() as Gtk.Window, FileChooserAction.OPEN, "Select", "Cancel"); PreviewFileChooserNative chooser = new PreviewFileChooserNative("Select file", get_toplevel() as Gtk.Window, FileChooserAction.OPEN, "Select", "Cancel");
@ -53,32 +57,17 @@ public class View : Box {
stream_interactor.get_module(FileManager.IDENTITY).send_file(uri, conversation); stream_interactor.get_module(FileManager.IDENTITY).send_file(uri, conversation);
} }
}); });
outer_box.add(file_button);
outer_box.add(file_separator);
scrolled = new ScrolledWindow(null, null) { max_content_height=300, propagate_natural_height=true, visible=true };
text_input = new TextView() { valign=Align.CENTER, wrap_mode=WrapMode.WORD_CHAR, margin=8, can_focus=true, hexpand=true, visible=true };
scrolled.add(text_input);
outer_box.add(scrolled);
encryption_widget = new EncryptionButton() { margin_top=3, valign=Align.START, visible=true };
encryption_widget.get_style_context().add_class("dino-chatinput-button");
outer_box.add(encryption_widget);
scrolled.get_vscrollbar().get_preferred_height(out vscrollbar_min_height, null); scrolled.get_vscrollbar().get_preferred_height(out vscrollbar_min_height, null);
scrolled.vadjustment.notify["upper"].connect_after(on_upper_notify); scrolled.vadjustment.notify["upper"].connect_after(on_upper_notify);
encryption_widget.get_style_context().add_class("dino-chatinput-button");
outer_box.add(encryption_widget);
text_input.key_press_event.connect(on_text_input_key_press); text_input.key_press_event.connect(on_text_input_key_press);
text_input.buffer.changed.connect(on_text_input_changed); text_input.buffer.changed.connect(on_text_input_changed);
Frame frame = new Frame(null) { margin=12, margin_top=0, visible=true };
Util.force_css(frame, "* { border-radius: 3px; }"); Util.force_css(frame, "* { border-radius: 3px; }");
frame.add(outer_box);
this.add(frame);
occupants_tab_completor = new OccupantsTabCompletor(stream_interactor, text_input);
smiley_converter = new SmileyConverter(stream_interactor, text_input);
edit_history = new EditHistory(text_input, GLib.Application.get_default());
stream_interactor.get_module(FileManager.IDENTITY).upload_available.connect(on_upload_available); stream_interactor.get_module(FileManager.IDENTITY).upload_available.connect(on_upload_available);
} }