From bc8f2cf93b3783345ad2044256609c475a4fbb31 Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Sun, 2 Mar 2025 12:05:29 +0100 Subject: [PATCH] restore selected note on notebook change --- application/notebook.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/application/notebook.c b/application/notebook.c index a0c5a81..5ba84fa 100644 --- a/application/notebook.c +++ b/application/notebook.c @@ -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) { -- 2.43.5