]> uap-core.de Git - note.git/commitdiff
restore selected note on notebook change
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 2 Mar 2025 11:05:29 +0000 (12:05 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 2 Mar 2025 11:05:29 +0000 (12:05 +0100)
application/notebook.c

index a0c5a8117fc5f2ad7dc5adbf7aebcb342d6f5f4c..5ba84fadd6959b5d9bc4865189adab3ea5662729 100644 (file)
@@ -41,6 +41,15 @@ NotebookModel* notebookmodel_create() {
     return model;
 }
     
+static void notelist_select_note(NotebookModel *model, Note *note) {
+    CxList *list = model->notes->data; // UiList uses CxList internally
+    list->collection.cmpfunc = cx_cmp_ptr;
+    int index = (int)cxListFind(list, note);
+    if(cxListIndexValid(list, index)) {
+        ui_list_setselection(model->notes, index);
+    }
+}
+
 void notebookmodel_attach(MainWindow *window, NotebookModel *model) {
     if(window->current_notebook) {
         notebookmodel_detach(window->current_notebook);
@@ -49,6 +58,14 @@ void notebookmodel_attach(MainWindow *window, NotebookModel *model) {
     window->current_notebook = model;
     model->window = window;
     ui_list_update(model->notes); // TODO: this should be unnecessary, attaching the document should update all values
+    
+    // TODO: Again, this should work automatically. Why it doesn't work:
+    //       UiList selection is not saved (should the toolkit actually do it?)
+    //       values from sub-values are bound but not reloaded
+    if(model->current_note) {
+        notelist_select_note(model, model->current_note);
+        // notebookmodel_attach_note(model, model->current_note);
+    }
 }
 
 void notebookmodel_detach(NotebookModel *model) {