]> uap-core.de Git - note.git/commitdiff
add UiDoc reference to UiDocProxy callback
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Mon, 25 May 2026 15:34:45 +0000 (17:34 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Mon, 25 May 2026 15:34:45 +0000 (17:34 +0200)
application/src/note.rs
application/src/notebook.rs
application/src/window.rs
ui-rs/src/ui/toolkit.rs

index ffc2e77e5f8ec595ada1eb5104bf7d17496bdc80..afac9dbc7d0984571b056a936487aa4ac3b71c76 100644 (file)
@@ -19,10 +19,9 @@ impl Note {
     pub fn init_from_model(&mut self, model: &entity::note::Model) {
         self.text.set(model.content.as_str());
 
-        let tab = match(model.kind) {
+        let tab = match model.kind {
             NoteType::PlainTextNote => NoteTypeTabView::TextArea,
             NoteType::MDTextNote => NoteTypeTabView::TextArea,
-            _ => NoteTypeTabView::Empty
         };
         self.note_type.set(tab as i64);
     }
index 40de6f4fca06ca67e217f9c037543aaf6d942564..5ceeacfd3b3302fe865b6e2bc79e68fc913abc5d 100644 (file)
@@ -1,8 +1,7 @@
 use ui_rs::{action, ui_actions, UiModel};
 use ui_rs::ui::*;
 
-use entity::note::{Model as Note, NoteType};
-use crate::window::NoteTypeTabView;
+use entity::note::{Model as Note};
 
 #[derive(UiModel, Default)]
 pub struct Notebook {
@@ -34,7 +33,7 @@ impl Notebook {
 
     #[action]
     pub fn note_selected(&mut self, event: &ActionEvent) {
-        if let (EventType::ListSelection(s)) = event.event_type {
+        if let EventType::ListSelection(s) = event.event_type {
             if let Some(note) = s.selected_element(self.notes.data()) {
                 // detach the current note
                 if let Some(current) = &self.selected_note {
@@ -43,7 +42,7 @@ impl Notebook {
                 }
 
                 // Create the new note
-                let mut note_data: crate::note::Note = Default::default();
+                let note_data: crate::note::Note = Default::default();
                 // TODO: setting the text here is the right thing to do, but for some
                 //       reasons it doesn't work yet. Fix this shit.
                 //note_data.text.set(note.content.as_str());
index b37b03858d49adf5e8b37cae7d69fc860d0c8c22..8534825cf260960e7c865bc93b812ffc9649a3c8 100644 (file)
@@ -138,7 +138,7 @@ pub fn create_window(app: &App, ctx: &AppContext<MainWindow>) -> UiObject<MainWi
                             });
                             let proxy = doc.doc_proxy();
                             e.data.backend.get_notes(nb.collection_id, |result|{
-                                proxy.call_mainthread(|nb| {
+                                proxy.call_mainthread(|_, nb| {
                                     match result {
                                         Ok(notes) => {
                                             nb.set_notes(notes);
@@ -168,7 +168,7 @@ pub fn create_window(app: &App, ctx: &AppContext<MainWindow>) -> UiObject<MainWi
                 .model(&model)
                 .fill(true)
                 .getvalue(note_getvalue)
-                .onselection_action(("note_selected"))
+                .onselection_action("note_selected")
                 .create();
         });
 
@@ -203,6 +203,6 @@ fn init_window_data(window: &mut MainWindow, data: &App) {
 }
 
 pub enum NoteTypeTabView {
-    Empty = 0,
+    _Empty = 0,
     TextArea = 1
 }
\ No newline at end of file
index 937cbc2660546c5212856897b4a9d278f4b62aa0..25aa0c1295fd9d55c3345890f16d364b955b892e 100644 (file)
@@ -166,11 +166,11 @@ impl<T: UiModel + UiActions> UiDoc<T> {
         }
     }
 
-    pub fn new(mut data: T) -> UiDoc<T> {
+    pub fn new(data: T) -> UiDoc<T> {
         UiDoc::new2(data, |_,_| {})
     }
     
-    pub fn new2<F>(mut data: T, init: F) -> UiDoc<T>
+    pub fn new2<F>(data: T, init: F) -> UiDoc<T>
     where F: FnOnce(&mut T, &UiDoc<T>) {
         unsafe {
             let doc = ui_document_new(mem::size_of::<*mut T>());
@@ -468,12 +468,12 @@ impl<T: UiModel + UiActions> UiDocProxy<T> {
     }
 
     pub fn call_mainthread<F>(self, f: F)
-    where F: FnOnce(&mut T) + Send + 'static {
+    where F: FnOnce(&UiDoc<T>, &mut T) + Send + 'static {
         call_mainthread(|| {
             let doc: UiDoc<T> = UiDoc::from_ptr(self.ptr);
             unsafe {
                 let data = doc.get_data_ptr();
-                f(&mut *data);
+                f(&doc, &mut *data);
             }
             drop(self);
         });
@@ -874,6 +874,12 @@ impl ListSelection {
         }
         None
     }
+
+    pub fn count(&self) -> usize {
+        unsafe {
+            ui_list_selection_get_count(self.ptr) as usize
+        }
+    }
 }