pub struct Notebook {
pub collection_id: i32,
- #[bind]
+ #[bind("notes")]
pub notes: UiList<Note>
}
collection_id: id, ..Default::default()
}
}
+
+ pub fn set_notes(&mut self, notes: Vec<Note>) {
+ let notes_list = self.notes.data_mut();
+ notes_list.clear();
+ for note in notes {
+ notes_list.push(note);
+ }
+ self.notes.update();
+ }
}
pub fn note_getvalue<'a>(elm: &Note, col: i32, _row: i32) -> ListValue<'a> {
let notebook = Notebook::new(nb.collection_id);
let doc = UiDoc::new(notebook);
-
- // TODO: load notes
+ let proxy = doc.doc_proxy();
+ e.data.backend.get_notes(nb.collection_id, |result|{
+ proxy.call_mainthread(|nb| {
+ match result {
+ Ok(notes) => {
+ nb.set_notes(notes);
+ },
+ Err(err) => {
+ eprintln!("get_notes failed: {}", err);
+ }
+ }
+ });
+ });
e.obj.ctx.attach(&doc);
e.data.selected_notebook = Some(doc);
obj.tableview_builder::<Note>()
.varname("notes")
+ .model(&model)
.fill(true)
.getvalue(note_getvalue)
.create();
}
void ui_mainthread_object_unref(UiObject *obj) {
+ // TODO: detect if this is already the main thread and call
+ // ui_object_unref directly in that case
ui_call_mainthread(obj_unref, obj);
}
}
void ui_mainthread_document_unref(void *doc) {
+ // TODO: see ui_mainthread_object_unref
ui_call_mainthread(doc_unref, doc);
}