});
});
- 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);
note_id: i32,
backend: BackendHandle,
- attachments: Vec<entity::attachment::Model>,
- content: Vec<Option<entity::attachmentcontent::Model>>,
+ attachments: Vec<Attachment>,
selection: Option<i32>,
selected_index: Option<usize>,
pub webview: UiWeb,
}
+struct Attachment {
+ attachment: entity::attachment::Model,
+ content: Option<entity::attachmentcontent::Model>
+}
+
+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 {
note_id,
backend,
attachments: Vec::new(),
- content: Vec::new(),
selection: None,
selected_index: None,
image: Default::default(),
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::<Vec<_>>();
+
+ 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);
}
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);
+ }
+ }
+ });
+ });
}
}