self.notes.update();
}
+ /// Saves and detaches the current note. This does NOT change self.selected_note
+ pub fn detach_current_note(&self) {
+ // detach the current note
+ if let Some(current) = &self.selected_note {
+ // doc_ref.get_doc() should never fail here
+ if let Some(mut doc) = self.doc_ref.get_doc() {
+ // save the note
+ let note_proxy = current.doc_proxy();
+ let backend = self.backend.clone();
+ let collection_id = self.collection_id;
+ note_proxy.call_mainthread(move |_doc, note|{
+ note.save(collection_id, &backend);
+ });
+
+ // detach the note
+ doc.ctx.detach(current);
+ }
+ }
+ }
+
#[action]
pub fn note_selected(&mut self, event: &ActionEvent) {
if let EventType::ListSelection(s) = event.event_type {
if let Some(note) = s.selected_element(self.notes.data()) {
- // detach the current note
- if let Some(current) = &self.selected_note {
- // doc_ref.get_doc() should never fail here
- if let Some(mut doc) = self.doc_ref.get_doc() {
- // save the note
- let note_proxy = current.doc_proxy();
- let backend = self.backend.clone();
- let collection_id = self.collection_id;
- note_proxy.call_mainthread(move |_doc, note|{
- note.save(collection_id, &backend);
- });
-
- // detach the note
- doc.ctx.detach(current);
- self.selected_note = None;
- }
- }
+ self.detach_current_note();
+ self.selected_note = None;
// Create the new note
let note_data: crate::note::Note = Default::default();
- // TODO: setting the text here is the right thing to do, but for some
- // reasons it doesn't work yet. Fix this shit.
- //note_data.text.set(note.content.as_str());
// Create the note document object
let note_doc = UiDoc::new2(note_data, |n,d| {
impl Drop for Notebook {
fn drop(&mut self) {
- println!("Notebook dropped");
+
}
}
\ No newline at end of file