From: Olaf Wintermann Date: Wed, 26 Aug 2026 18:47:45 +0000 (+0200) Subject: add attachments itemlist to window X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=HEAD;p=note.git add attachments itemlist to window --- diff --git a/application/note/src/note.rs b/application/note/src/note.rs index 3336fbc..978ab28 100644 --- a/application/note/src/note.rs +++ b/application/note/src/note.rs @@ -85,7 +85,10 @@ pub struct Note { pub text: UiText, #[bind("note_info")] - pub info: UiString + pub info: UiString, + + #[bind("note_attachments")] + pub attachments: UiList } #[ui_actions] @@ -117,6 +120,7 @@ impl Note { title: Default::default(), text: Default::default(), info: Default::default(), + attachments: Default::default() } } @@ -263,6 +267,32 @@ impl Note { }); } + pub fn load_attachments(&mut self) { + let NoteId::Id(note_id) = self.id else { + return; + }; + + let Some(doc) = self.doc.get_doc() else { + return; + }; + + let proxy = doc.doc_proxy(); + self.backend.get_note_attachments(note_id, move|result|{ + proxy.call_mainthread(move |_doc, note|{ + match result { + Ok(attachments) => { + note.attachments.data_mut().clear(); + note.attachments.data_mut().extend(attachments); + note.attachments.update(); + }, + Err(e) => { + println!("Cannot get note attachments: {}", e); + } + } + }); + }); + } + pub fn update_title(&mut self, s: &str, notify: bool) { let title = match generate_title(s) { Some(result) => { @@ -337,6 +367,7 @@ impl Note { println!("note changed by {}", _from); self.load_content(); + self.load_attachments(); } /// Event before the text is changed: detect if the change affects the title diff --git a/application/note/src/window.rs b/application/note/src/window.rs index 5cc9087..82deac6 100644 --- a/application/note/src/window.rs +++ b/application/note/src/window.rs @@ -28,10 +28,11 @@ use std::any::Any; use backend::backend::{BackendHandle, BroadcastMessage, NoteId}; -use ui_rs::{action, button, grid, hbox, imageviewer, label, sourcelist, tableview, tabview, textarea, textfield, ui_actions, webview, UiModel}; +use ui_rs::{action, button, grid, hbox, imageviewer, label, scrolledwindow, sourcelist, tableview, tabview, textarea, textfield, ui_actions, webview, UiModel}; use ui_rs::ui::*; use crate::{App, AppStates}; use entity::collection::{CollectionType, Model as Collection, Node}; +use ui_rs::ui::widget::Widget; use crate::newnotebook::new_notebook_dialog; use crate::notebook::{notelist_getvalue, Notebook, NotebookItem}; @@ -286,7 +287,12 @@ pub fn create_window(app: &App, ctx: &AppContext) -> UiObject() + .varname("note_attachments") + .create(); + }); + w.set_size(-1, 120); }); let textarea = textarea!(obj, fill = true, varname = "note_text", onchange_action = "note_text_change", ontextchanged_action = "note_text_changed"); obj.ctx.add_action_untyped("textarea_focus", move|_event|{ diff --git a/ui-rs/src/ui/container.rs b/ui-rs/src/ui/container.rs index a71d767..c0dbb95 100644 --- a/ui-rs/src/ui/container.rs +++ b/ui-rs/src/ui/container.rs @@ -204,6 +204,12 @@ macro_rules! tabview { }}; } +#[macro_export] +macro_rules! itemlist { + ($parent:expr, $($tt:tt)*) => { + $crate::widget!($parent, itemlist, $($tt)*) + }; +} pub struct Container { ptr: *mut c_void } @@ -1318,6 +1324,19 @@ impl<'a, T> TabViewBuilder<'a, T> { } } +impl toolkit::UiObject { + pub fn itemlist<'a, E>(&'a mut self) -> ItemListContainerBuilder<'a, T, E> { + unsafe { + let args = ui_itemlist_container_args_new(); + ItemListContainerBuilder { + args: args, + obj: self, + _marker: PhantomData + } + } + } +} + /* -------------------------------- ItemList Container -------------------------------- */ type CreateUiFunc = extern "C" fn(obj: *mut ffi::UiObject, list: *mut ffi::UiList, row: c_int, elm: *mut c_void, userdata: *mut c_void); @@ -1342,14 +1361,8 @@ pub struct ItemListContainerBuilder<'a, T, C> { } impl<'a, T, C> ItemListContainerBuilder<'a, T, C> { - pub fn create(&mut self, create_ui: F) -> Container - where F: FnOnce(&mut toolkit::UiObject) { + pub fn create(&mut self) -> Container { let widget_ptr = unsafe { ui_itemlist_create(self.obj.ptr, self.args) }; - create_ui(self.obj); - unsafe { - ui_container_begin_close(self.obj.ptr); - ui_container_finish(self.obj.ptr); - } Container { ptr: widget_ptr, } diff --git a/ui-rs/src/ui/list.rs b/ui-rs/src/ui/list.rs index 8e3555e..112da65 100644 --- a/ui-rs/src/ui/list.rs +++ b/ui-rs/src/ui/list.rs @@ -29,7 +29,7 @@ #![allow(dead_code)] use crate::ui::ffi::{UiObject, UiListArgs, UiCallback, UiList, UiSourceListArgs}; -use crate::ui::{event, ffi, toolkit, ui_list_get, ui_list_get_data, Button, EventWrapper}; +use crate::ui::{event, ffi, toolkit, ui_list_get, ui_list_get_data, Button, EventWrapper, ItemListContainerBuilder}; use std::ffi::{c_char, c_int, c_void}; use std::ffi::CString; use std::marker::PhantomData; diff --git a/ui-rs/src/ui/mod.rs b/ui-rs/src/ui/mod.rs index 78679e1..aed82cd 100644 --- a/ui-rs/src/ui/mod.rs +++ b/ui-rs/src/ui/mod.rs @@ -32,7 +32,7 @@ mod application; mod window; mod button; mod container; -mod widget; +pub mod widget; mod text; pub mod event; pub mod list;