From: Olaf Wintermann Date: Sun, 23 Aug 2026 17:07:21 +0000 (+0200) Subject: implement toolbar button for adding attachments X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=HEAD;p=note.git implement toolbar button for adding attachments --- diff --git a/application/note/src/main.rs b/application/note/src/main.rs index fc01db4..d820e73 100644 --- a/application/note/src/main.rs +++ b/application/note/src/main.rs @@ -163,12 +163,14 @@ fn create_toolbar(app: &AppContext) { .action("notebook_view_changed") .varname("note_maximized") .create(); + app.toolbar_item("add_attachment").icon(UiIconSet::Add.as_str()).action("add_attachment").create(); app.toolbar_add_default("new_notebook", ToolbarItemPosition::SidebarLeft); app.toolbar_add_default("go_back", ToolbarItemPosition::Left); app.toolbar_add_default("go_forward", ToolbarItemPosition::Left); app.toolbar_add_default("new_note", ToolbarItemPosition::Left); + app.toolbar_add_default("add_attachment", ToolbarItemPosition::RightPanelLeft); app.toolbar_add_default("note_maximize", ToolbarItemPosition::RightPanelRight); app.toolbar_appmenu(|menu|{ diff --git a/application/note/src/note.rs b/application/note/src/note.rs index 1695c23..719fe84 100644 --- a/application/note/src/note.rs +++ b/application/note/src/note.rs @@ -25,7 +25,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::rc::Rc; use std::sync::atomic::{AtomicU64, Ordering}; use std::time::SystemTime; @@ -519,6 +519,41 @@ impl Note { }) .create(); } + + #[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); + } + } + }); + }); + } + }); + } } impl NoteViewModel for Note {