From 9702db04d067f797482bea0954e84a538de8eef7 Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Mon, 12 May 2025 19:18:10 +0200 Subject: [PATCH] update sourcelist when notebooks are added --- application/window.c | 19 +++++++++++-------- application/window.h | 1 + 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/application/window.c b/application/window.c index bb1e251..9428d6b 100644 --- a/application/window.c +++ b/application/window.c @@ -276,17 +276,17 @@ static void action_nnd_new_group(UiEvent *event, void *userdata) { } } -struct NotebookCreatedResult { +typedef struct NotebookCreatedResult { + MainWindow *window; Resource *parent; Resource *notebook; -}; +} NotebookCreatedResult; static void notebook_created(UiEvent *event, int64_t newid, int error, void *userdata) { - struct NotebookCreatedResult *result = userdata; + NotebookCreatedResult *result = userdata; cxListAdd(result->parent->children, result->notebook); + update_sublists(result->window->obj->ctx, result->window->notebooks); free(result); - - // TODO: update windows } static void action_nnd_button(UiEvent *event, void *userdata) { @@ -318,7 +318,8 @@ static void action_nnd_button(UiEvent *event, void *userdata) { notebook->parent_id = parent->resource_id; notebook->nodename = cx_strdup_a(store->mp->allocator, name).ptr; - struct NotebookCreatedResult *result = malloc(sizeof(struct NotebookCreatedResult)); + NotebookCreatedResult *result = malloc(sizeof(NotebookCreatedResult)); + result->window = wdata->parent; result->parent = parent; result->notebook = notebook; @@ -347,7 +348,9 @@ void action_notebook_add(UiEvent *event, void *userdata) { //ui_set_group(obj->ctx, NEWNOTEBOOK_DIALOG_STATE_SELECT_GROUP); NewNotebookDialog *wdata = ui_malloc(obj->ctx, sizeof(NewNotebookDialog)); + wdata->parent = event->window; wdata->groups = ui_list_new(obj->ctx, NULL); + wdata->group_name = ui_string_new(obj->ctx, NULL); wdata->notebook_name = ui_string_new(obj->ctx, NULL); wdata->gs_new_group = ui_int_new(obj->ctx, NULL); wdata->gn_new_group = ui_int_new(obj->ctx, NULL); @@ -365,7 +368,7 @@ void action_notebook_add(UiEvent *event, void *userdata) { ui_widget_set_groups(obj->ctx, gs_button, (ui_enablefunc)ui_set_visible, NEWNOTEBOOK_DIALOG_STATE_SELECT_GROUP, -1); UIWIDGET gn_label = ui_rlabel(obj, .label = "Group"); - UIWIDGET gn_textfield = ui_textfield(obj, .varname = "notebook_group_name", .hexpand = TRUE, .hfill = TRUE); + UIWIDGET gn_textfield = ui_textfield(obj, .value = wdata->group_name, .hexpand = TRUE, .hfill = TRUE); UIWIDGET gn_button = ui_togglebutton(obj, .label = "New Group", .value = wdata->gn_new_group, .onchange = action_nnd_new_group); ui_newline(obj); @@ -375,7 +378,7 @@ void action_notebook_add(UiEvent *event, void *userdata) { ui_newline(obj); ui_rlabel(obj, .label = "Name"); - ui_textfield(obj, .varname = "notebook_name", .colspan = 2, .hfill = TRUE); + ui_textfield(obj, .value = wdata->notebook_name, .colspan = 2, .hfill = TRUE); } // Dialog Data diff --git a/application/window.h b/application/window.h index 29be0bc..dc06ae5 100644 --- a/application/window.h +++ b/application/window.h @@ -44,6 +44,7 @@ extern "C" { typedef struct NewNotebookDialog { + MainWindow *parent; UiList *groups; UiString *group_name; UiString *notebook_name; -- 2.43.5