diff --git a/src/aardvark.gresource.xml b/src/aardvark.gresource.xml
index 0b132e0..fc6e8c7 100644
--- a/src/aardvark.gresource.xml
+++ b/src/aardvark.gresource.xml
@@ -3,5 +3,6 @@
window.ui
gtk/help-overlay.ui
+ style.css
diff --git a/src/application.rs b/src/application.rs
index 33a19ed..5ae6a33 100644
--- a/src/application.rs
+++ b/src/application.rs
@@ -27,13 +27,27 @@ use gtk::{gio, glib};
use crate::config::VERSION;
use crate::network;
use crate::AardvarkWindow;
+use crate::glib::closure_local;
+use automerge::transaction::Transactable;
+use automerge::ObjType;
+use std::cell::RefCell;
+use automerge::ObjId;
mod imp {
use super::*;
- #[derive(Debug, Default)]
+ #[derive(Debug)]
pub struct AardvarkApplication {
- automerge: AutoCommit,
+ automerge: RefCell,
+ root: ObjId,
+ }
+
+ impl AardvarkApplication {
+ fn update_text(&self, text: &str) {
+ println!("app: {}", text);
+ let mut doc = self.automerge.borrow_mut();
+ doc.update_text(&self.root, text).unwrap();
+ }
}
#[glib::object_subclass]
@@ -43,8 +57,13 @@ mod imp {
type ParentType = adw::Application;
fn new() -> Self {
- let automerge = AutoCommit::new();
- AardvarkApplication { automerge }
+ let mut am = AutoCommit::new();
+ let root = am.put_object(automerge::ROOT, "root", ObjType::Text).unwrap();
+ let automerge = RefCell::new(am);
+ AardvarkApplication {
+ automerge,
+ root,
+ }
}
}
@@ -67,6 +86,14 @@ mod imp {
// Get the current window or create one if necessary
let window = application.active_window().unwrap_or_else(|| {
let window = AardvarkWindow::new(&*application);
+ let app = application.clone();
+ window.connect_closure(
+ "text-changed",
+ false,
+ closure_local!(|_window: AardvarkWindow, text: &str| {
+ app.imp().update_text(text);
+ }),
+ );
window.upcast()
});
diff --git a/src/style.css b/src/style.css
new file mode 100644
index 0000000..8591759
--- /dev/null
+++ b/src/style.css
@@ -0,0 +1,4 @@
+.invite-code {
+ font-size: 20px;
+ font-style: bold;
+}
diff --git a/src/window.rs b/src/window.rs
index f9b7444..8577784 100644
--- a/src/window.rs
+++ b/src/window.rs
@@ -21,6 +21,8 @@
use gtk::prelude::*;
use adw::subclass::prelude::*;
use gtk::{gio, glib};
+use glib::subclass::Signal;
+use std::sync::OnceLock;
mod imp {
use super::*;
@@ -48,7 +50,27 @@ mod imp {
}
}
- impl ObjectImpl for AardvarkWindow {}
+ impl ObjectImpl for AardvarkWindow {
+ fn constructed(&self) {
+ self.parent_constructed();
+ let buffer = self.text_view.buffer();
+ let obj = self.obj().clone();
+ buffer.connect_changed(move |buffer| {
+ let s = buffer.text(&buffer.start_iter(), &buffer.end_iter(), false);
+ obj.emit_by_name::<()>("text-changed", &[&s.as_str()]);
+ });
+ }
+
+ fn signals() -> &'static [Signal] {
+ static SIGNALS: OnceLock> = OnceLock::new();
+ SIGNALS.get_or_init(|| {
+ vec![Signal::builder("text-changed")
+ .param_types([str::static_type()])
+ .build()]
+ })
+ }
+ }
+
impl WidgetImpl for AardvarkWindow {}
impl WindowImpl for AardvarkWindow {}
impl ApplicationWindowImpl for AardvarkWindow {}
diff --git a/src/window.ui b/src/window.ui
index 756869d..df7e578 100644
--- a/src/window.ui
+++ b/src/window.ui
@@ -18,6 +18,13 @@
primary_menu
+
+
+
@@ -39,6 +46,59 @@
+