+
+ #[action]
+ pub fn add_attachment(&mut self, event: &mut ActionEvent) {
+ let Some(doc) = self.doc.get_doc() else {
+ return;
+ };
+ let Some(obj) = &event.obj else {
+ return;
+ };
+
+ // TODO: currently it is unsupported to add attachments to unsaved notes
+ let NoteId::Id(note_id) = self.id else {
+ return;
+ };
+
+ let proxy = doc.doc_proxy();
+ let backend = self.backend.clone();
+ obj.openfile_dialog(false, move|event|{
+ if let EventType::FileList(file_selection) = event.event_type && let Some(file) = file_selection.get(0) {
+ let path = Path::new(file);
+ backend.add_note_attachment(note_id, path, move|result|{
+ proxy.call_mainthread(|_doc, note|{
+ match result {
+ Ok((attachment, content)) => {
+ println!("attachment: {} id: {}", attachment.attachment_id, content.attachment_id);
+ },
+ Err(e) => {
+ println!("cannot add attachment: {}", e);
+ }
+ }
+ });
+ });
+ }
+ });
+ }