From: Olaf Wintermann Date: Sat, 5 Sep 2026 12:12:09 +0000 (+0200) Subject: load attachment content X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=558a4c66a2e1a098ba367872afea1f9d537f2611;p=note.git load attachment content --- diff --git a/application/note/src/attachments_window.rs b/application/note/src/attachments_window.rs index 9352afd..7ebf530 100644 --- a/application/note/src/attachments_window.rs +++ b/application/note/src/attachments_window.rs @@ -43,9 +43,14 @@ pub fn attachments_window_create(backend: BackendHandle, note_id: i32, selected_ }); }); - tabview!(obj, tabview_type = TabViewType::Invisible, varname = "attachment_view_type", |tv|{ + tabview!(obj, tabview_type = TabViewType::Invisible, varname = "attachment_view_type", fill = true, |tv|{ tv.tab("img", |obj|{ - imageviewer!(obj, varname = "image", fill = true); + imageviewer!(obj, + varname = "image", + fill = true, + autoscale = true, + scrollview = true, + useradjustable = true); }); tv.tab("webview", |obj|{ webview!(obj, varname = "webview", fill = true); @@ -65,8 +70,7 @@ pub struct AttachmentsWindow { note_id: i32, backend: BackendHandle, - attachments: Vec, - content: Vec>, + attachments: Vec, selection: Option, selected_index: Option, @@ -77,6 +81,20 @@ pub struct AttachmentsWindow { pub webview: UiWeb, } +struct Attachment { + attachment: entity::attachment::Model, + content: Option +} + +impl Attachment { + fn new(attachment: &entity::attachment::Model) -> Attachment { + Self { + attachment: attachment.clone(), + content: None, + } + } +} + #[ui_actions] impl AttachmentsWindow { pub fn new(backend: BackendHandle, note_id: i32) -> AttachmentsWindow { @@ -85,7 +103,6 @@ impl AttachmentsWindow { note_id, backend, attachments: Vec::new(), - content: Vec::new(), selection: None, selected_index: None, image: Default::default(), @@ -104,11 +121,14 @@ impl AttachmentsWindow { match result { Ok(attachments) => { println!("attachments loaded"); - wdata.attachments = attachments; - wdata.content = vec![None; wdata.attachments.len()]; + let ats = attachments.iter() + .map(|a| Attachment::new(a) ) + .collect::>(); + + wdata.attachments = ats; if let Some(selection) = wdata.selection { - wdata.selected_index = wdata.attachments.iter().position(|a| a.attachment_id == selection); + wdata.selected_index = attachments.iter().position(|a| a.attachment_id == selection); if let Some(index) = wdata.selected_index { wdata.load_content(index); } @@ -127,16 +147,34 @@ impl AttachmentsWindow { let Some(obj) = self.obj.get_object() else { return; }; - if index >= self.content.len() { + if index >= self.attachments.len() { return; } - let ct = &self.content[index]; - if let Some(content) = ct { + let a = &self.attachments[index]; + if let Some(content) = &a.content { self.image.image_load_data(&content.content); } else { let proxy = obj.obj_proxy(); - // TODO: load attachment data + let attachment_id = a.attachment.attachment_id; + self.backend.get_attachment_content(attachment_id, move|result|{ + proxy.call_mainthread(move |doc, wdata|{ + match result { + Ok(content) => { + let a = wdata.attachments.get_mut(index); + if let Some(a) = a { + if let Some(selection) = wdata.selection && selection == a.attachment.attachment_id { + wdata.image.image_load_data(&content.content); + } + a.content = Some(content); + } + }, + Err(e) => { + println!("Cannot get attachment content: {}", e); + } + } + }); + }); } }