From 4d5e6ec394935111e9b71ae18bf091eee1fca8fa Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Sat, 10 May 2025 07:45:26 +0200 Subject: [PATCH] save resource in the New Notebook dialog --- application/window.c | 48 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/application/window.c b/application/window.c index 4f4d893..bb1e251 100644 --- a/application/window.c +++ b/application/window.c @@ -276,9 +276,54 @@ static void action_nnd_new_group(UiEvent *event, void *userdata) { } } +struct NotebookCreatedResult { + Resource *parent; + Resource *notebook; +}; + +static void notebook_created(UiEvent *event, int64_t newid, int error, void *userdata) { + struct NotebookCreatedResult *result = userdata; + cxListAdd(result->parent->children, result->notebook); + free(result); + + // TODO: update windows +} + static void action_nnd_button(UiEvent *event, void *userdata) { + NewNotebookDialog *wdata = event->window; if(event->intval == 1) { + char *nodename = ui_get(wdata->notebook_name); + cxstring name = cx_str(nodename); + if(name.length == 0) { + return; // TODO: error + } + // add + NoteStore *store = note_store_get(); + + UiListSelection sel = ui_list_getselection(wdata->groups); + if(sel.count == 0) { + fprintf(stderr, "Error: no group selected\n"); + return; // TODO: error + } + Resource *parent = ui_list_get(wdata->groups, sel.rows[0]); + ui_listselection_free(sel); + + if(!parent) { + fprintf(stderr, "Error: no parent found\n"); + return; // TODO: error + } + + Resource *notebook = cxCalloc(store->mp->allocator, 1, sizeof(Resource)); + notebook->parent_id = parent->resource_id; + notebook->nodename = cx_strdup_a(store->mp->allocator, name).ptr; + + struct NotebookCreatedResult *result = malloc(sizeof(struct NotebookCreatedResult)); + result->parent = parent; + result->notebook = notebook; + + + note_store_new_notebook_async(event->obj, notebook, notebook_created, result); } // 4: cancel ui_close(event->obj); @@ -298,7 +343,8 @@ void action_notebook_add(UiEvent *event, void *userdata) { .rbutton4 = "Cancel", .default_button = 1, .onclick = action_nnd_button); - ui_set_group(obj->ctx, NEWNOTEBOOK_DIALOG_STATE_SELECT_GROUP); + // TODO: enable when creating new groups is implemented + //ui_set_group(obj->ctx, NEWNOTEBOOK_DIALOG_STATE_SELECT_GROUP); NewNotebookDialog *wdata = ui_malloc(obj->ctx, sizeof(NewNotebookDialog)); wdata->groups = ui_list_new(obj->ctx, NULL); -- 2.43.5