SourceViewEntry: Move it to its own widget
This commit is contained in:
parent
4841efa75c
commit
cd5a1e86a7
3 changed files with 110 additions and 74 deletions
|
@ -1,10 +1,6 @@
|
|||
extern crate gtk;
|
||||
use gtk::prelude::*;
|
||||
|
||||
use uibuilder::gtk::BuilderExt;
|
||||
use libhandy::{Column, ColumnExt};
|
||||
use gtk::{self, prelude::*};
|
||||
use sourceview;
|
||||
use sourceview::ViewExt;
|
||||
use widgets::SVEntry;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct UI {
|
||||
|
@ -67,76 +63,18 @@ impl UI {
|
|||
}
|
||||
|
||||
fn room_message_entry_reimpl(builder: >k::Builder) {
|
||||
let column = Column::new();
|
||||
column.set_maximum_width(800);
|
||||
/* For some reason the Column is not seen as a gtk::container
|
||||
* and therefore we can't call add() without the cast */
|
||||
let column = column.upcast::<gtk::Widget>();
|
||||
let column = column.downcast::<gtk::Container>().unwrap();
|
||||
column.set_vexpand(false);
|
||||
|
||||
let room_msg_box = gtk::Box::new(gtk::Orientation::Horizontal, 6);
|
||||
room_msg_box.set_vexpand(false);
|
||||
|
||||
let size = gtk::IconSize::Button.into();
|
||||
let attach = gtk::Button::new();
|
||||
let attach_img = gtk::Image::new_from_icon_name("mail-attachment-symbolic", size);
|
||||
attach.set_image(&attach_img);
|
||||
attach.set_valign(gtk::Align::End);
|
||||
attach.set_receives_default(true);
|
||||
// TODO: there was an a11y object in the xml
|
||||
/*
|
||||
<object class="AtkObject" id="attach_button-atkobject">
|
||||
<property name="AtkObject::accessible-name" translatable="yes">Attach files</property>
|
||||
</object>
|
||||
*/
|
||||
|
||||
let markdown = gtk::MenuButton::new();
|
||||
let markdown_img = gtk::Image::new_from_icon_name("format-justify-left-symbolic", size);
|
||||
markdown.set_image(&markdown_img);
|
||||
markdown.set_valign(gtk::Align::End);
|
||||
markdown.set_receives_default(true);
|
||||
// TODO: there was an a11y object in the xml
|
||||
/*
|
||||
<object class="AtkObject" id="a11y-markdown_button">
|
||||
<property name="AtkObject::accessible_name" translatable="yes">Text formatting</property>
|
||||
</object>
|
||||
*/
|
||||
|
||||
let msg_entry_box = gtk::Box::new(gtk::Orientation::Vertical, 0);
|
||||
msg_entry_box.get_style_context().map(|c| c.add_class("message-input"));
|
||||
|
||||
let scroll = gtk::ScrolledWindow::new(None, None);
|
||||
|
||||
let buffer = sourceview::Buffer::new(None);
|
||||
let sv = sourceview::View::new_with_buffer(&buffer);
|
||||
sv.set_wrap_mode(gtk::WrapMode::WordChar);
|
||||
sv.set_indent_on_tab(false);
|
||||
|
||||
scroll.add(&sv);
|
||||
scroll.set_hexpand(true);
|
||||
scroll.set_vexpand(true);
|
||||
scroll.set_policy(gtk::PolicyType::Automatic, gtk::PolicyType::External);
|
||||
scroll.set_max_content_height(100);
|
||||
scroll.set_propagate_natural_height(true);
|
||||
msg_entry_box.add(&scroll);
|
||||
|
||||
room_msg_box.pack_start(&attach, false, false, 0);
|
||||
room_msg_box.pack_start(&markdown, false, false, 0);
|
||||
room_msg_box.pack_start(&msg_entry_box, false, true, 0);
|
||||
let entry = SVEntry::default();
|
||||
|
||||
let parent: gtk::Box = builder.get_object("room_parent").unwrap();
|
||||
column.add(&room_msg_box);
|
||||
parent.add(&column);
|
||||
column.show_all();
|
||||
parent.add(&entry.column);
|
||||
|
||||
// Keep compatibilit with the rest of the codebase
|
||||
builder.expose_object::<gtk::Box>("room_message_box", &room_msg_box);
|
||||
builder.expose_object::<gtk::Button>("attach_button", &attach);
|
||||
builder.expose_object::<gtk::MenuButton>("markdown_button", &markdown);
|
||||
builder.expose_object::<gtk::Image>("md_img", &markdown_img);
|
||||
builder.expose_object::<gtk::Box>("msg_entry_box", &msg_entry_box);
|
||||
builder.expose_object::<gtk::ScrolledWindow>("input_scroll", &scroll);
|
||||
builder.expose_object::<sourceview::View>("msg_entry", &sv);
|
||||
builder.expose_object::<sourceview::Buffer>("msg_entry_buffer", &buffer);
|
||||
builder.expose_object::<gtk::Box>("room_message_box", &entry.container);
|
||||
builder.expose_object::<gtk::Button>("attach_button", &entry.attach);
|
||||
builder.expose_object::<gtk::MenuButton>("markdown_button", &entry.markdown);
|
||||
builder.expose_object::<gtk::Image>("md_img", &entry.markdown_img);
|
||||
builder.expose_object::<gtk::Box>("msg_entry_box", &entry.entry_box);
|
||||
builder.expose_object::<gtk::ScrolledWindow>("input_scroll", &entry.scroll);
|
||||
builder.expose_object::<sourceview::View>("msg_entry", &entry.view);
|
||||
builder.expose_object::<sourceview::Buffer>("msg_entry_buffer", &entry.buffer);
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ pub mod media_viewer;
|
|||
pub mod divider;
|
||||
pub mod image;
|
||||
mod inline_player;
|
||||
mod sourceview_entry;
|
||||
pub mod message_menu;
|
||||
|
||||
pub use self::message::MessageBox;
|
||||
|
@ -33,3 +34,4 @@ pub use self::avatar::AvatarData;
|
|||
pub use self::avatar::admin_badge;
|
||||
pub use self::avatar::AdminColor;
|
||||
pub use self::inline_player::AudioPlayerWidget;
|
||||
pub use self::sourceview_entry::SVEntry;
|
||||
|
|
96
fractal-gtk/src/widgets/sourceview_entry.rs
Normal file
96
fractal-gtk/src/widgets/sourceview_entry.rs
Normal file
|
@ -0,0 +1,96 @@
|
|||
use gtk::{self, prelude::*};
|
||||
use libhandy::{Column, ColumnExt};
|
||||
use sourceview::{self, ViewExt};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SVEntry {
|
||||
pub column: Column,
|
||||
pub container: gtk::Box,
|
||||
pub attach: gtk::Button,
|
||||
pub markdown: gtk::MenuButton,
|
||||
pub markdown_img: gtk::Image,
|
||||
pub entry_box: gtk::Box,
|
||||
pub scroll: gtk::ScrolledWindow,
|
||||
pub view: sourceview::View,
|
||||
pub buffer: sourceview::Buffer,
|
||||
}
|
||||
|
||||
impl Default for SVEntry {
|
||||
fn default() -> Self {
|
||||
let column = Column::new();
|
||||
column.set_maximum_width(800);
|
||||
/* For some reason the Column is not seen as a gtk::container
|
||||
* and therefore we can't call add() without the cast */
|
||||
let column = column.upcast::<gtk::Widget>();
|
||||
let column = column.downcast::<gtk::Container>().unwrap();
|
||||
column.set_vexpand(false);
|
||||
|
||||
let container = gtk::Box::new(gtk::Orientation::Horizontal, 6);
|
||||
container.set_vexpand(false);
|
||||
|
||||
let size = gtk::IconSize::Button.into();
|
||||
let attach = gtk::Button::new();
|
||||
let attach_img = gtk::Image::new_from_icon_name("mail-attachment-symbolic", size);
|
||||
attach.set_image(&attach_img);
|
||||
attach.set_valign(gtk::Align::End);
|
||||
attach.set_receives_default(true);
|
||||
// TODO: there was an a11y object in the xml
|
||||
/*
|
||||
<object class="AtkObject" id="attach_button-atkobject">
|
||||
<property name="AtkObject::accessible-name" translatable="yes">Attach files</property>
|
||||
</object>
|
||||
*/
|
||||
|
||||
let markdown = gtk::MenuButton::new();
|
||||
let markdown_img = gtk::Image::new_from_icon_name("format-justify-left-symbolic", size);
|
||||
markdown.set_image(&markdown_img);
|
||||
markdown.set_valign(gtk::Align::End);
|
||||
markdown.set_receives_default(true);
|
||||
// TODO: there was an a11y object in the xml
|
||||
/*
|
||||
<object class="AtkObject" id="a11y-markdown_button">
|
||||
<property name="AtkObject::accessible_name" translatable="yes">Text formatting</property>
|
||||
</object>
|
||||
*/
|
||||
|
||||
let entry_box = gtk::Box::new(gtk::Orientation::Vertical, 0);
|
||||
entry_box.get_style_context().map(|c| c.add_class("message-input"));
|
||||
|
||||
let scroll = gtk::ScrolledWindow::new(None, None);
|
||||
|
||||
let buffer = sourceview::Buffer::new(None);
|
||||
let view = sourceview::View::new_with_buffer(&buffer);
|
||||
view.set_wrap_mode(gtk::WrapMode::WordChar);
|
||||
view.set_indent_on_tab(false);
|
||||
|
||||
scroll.add(&view);
|
||||
scroll.set_hexpand(true);
|
||||
scroll.set_vexpand(true);
|
||||
scroll.set_policy(gtk::PolicyType::Automatic, gtk::PolicyType::External);
|
||||
scroll.set_max_content_height(100);
|
||||
scroll.set_propagate_natural_height(true);
|
||||
entry_box.add(&scroll);
|
||||
|
||||
container.pack_start(&attach, false, false, 0);
|
||||
container.pack_start(&markdown, false, false, 0);
|
||||
container.pack_start(&entry_box, false, true, 0);
|
||||
|
||||
column.add(&container);
|
||||
column.show_all();
|
||||
|
||||
let column = column.upcast::<gtk::Widget>();
|
||||
let column = column.downcast::<Column>().unwrap();
|
||||
|
||||
SVEntry {
|
||||
column,
|
||||
container,
|
||||
attach,
|
||||
markdown,
|
||||
markdown_img,
|
||||
entry_box,
|
||||
scroll,
|
||||
view,
|
||||
buffer,
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue