Skip to content

Commit

Permalink
Merge branch 'main' of github.com:p2panda/aardvark into feature/ci-wi…
Browse files Browse the repository at this point in the history
…n-mac-builds
  • Loading branch information
silviot committed Dec 7, 2024
2 parents f9a469c + 0806ada commit f0085ae
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/aardvark.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
<gresource prefix="/org/p2panda/aardvark">
<file preprocess="xml-stripblanks">window.ui</file>
<file preprocess="xml-stripblanks">gtk/help-overlay.ui</file>
<file compressed="true" alias="style.css">style.css</file>
</gresource>
</gresources>
35 changes: 31 additions & 4 deletions src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AutoCommit>,
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]
Expand All @@ -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,
}
}
}

Expand All @@ -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()
});

Expand Down
4 changes: 4 additions & 0 deletions src/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.invite-code {
font-size: 20px;
font-style: bold;
}
24 changes: 23 additions & 1 deletion src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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<Vec<Signal>> = 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 {}
Expand Down
60 changes: 60 additions & 0 deletions src/window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
<property name="menu-model">primary_menu</property>
</object>
</child>
<child type="end">
<object class="GtkMenuButton" id="ShareButton">
<property name="icon-name">folder-publicshare-symbolic</property>
<property name="tooltip-text" translatable="yes">Share Document</property>
<property name="popover">share_popover</property>
</object>
</child>
</object>
</child>
<property name="content">
Expand All @@ -39,6 +46,59 @@
</object>
</property>
</template>
<object class="GtkPopover" id="share_popover">
<property name="has-arrow">true</property>
<property name="name">share_popover</property>
<property name="child">
<object class="GtkBox" id="plain-popover-box">
<property name="margin-top">18</property>
<property name="margin-bottom">18</property>
<property name="margin-start">18</property>
<property name="margin-end">18</property>
<property name="orientation">vertical</property>
<property name="spacing">12</property>
<property name="width-request">100</property>
<property name="name">share-popover-box</property>
<child>
<object class="GtkLabel">
<property name="label" translatable="true">Share Document</property>
<style>
<class name="title-2" />
</style>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label" translatable="true">Give others access to this document by sharing this invite code with them:</property>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label" translatable="true">sdf032jbn39aw0y23l0nd9dkeb200b21m289he </property>
<style>
<class name="invite-code" />
<class name="monospace" />
</style>
</object>
</child>
<child>
<object class="GtkBox">
<property name="halign">center</property>
<property name="margin-top">12</property>

<child>
<object class="GtkButton">
<property name="label" translatable="true">Copy to Clipboard</property>
<style>
<class name="pill" />
</style>
</object>
</child>
</object>
</child>
</object>
</property>
</object>
<menu id="primary_menu">
<section>
<item>
Expand Down

0 comments on commit f0085ae

Please sign in to comment.