From: Olaf Wintermann Date: Wed, 7 May 2025 21:13:05 +0000 (+0200) Subject: load group list in the add notebook dialog X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=6443af8f4838556de4ee8ae1b497904e7a25cddb;p=note.git load group list in the add notebook dialog --- diff --git a/application/window.c b/application/window.c index a4552e6..175129c 100644 --- a/application/window.c +++ b/application/window.c @@ -276,6 +276,18 @@ static void action_nnd_new_group(UiEvent *event, void *userdata) { } } +static void action_nnd_button(UiEvent *event, void *userdata) { + if(event->intval == 1) { + // add + } // 4: cancel + ui_close(event->obj); +} + +static void* nnd_group_value(void *elm, int unused) { + Resource *res = elm; + return res->displayname ? res->displayname : res->nodename; +} + void action_notebook_add(UiEvent *event, void *userdata) { UiObject *obj = ui_dialog_window(event->obj, .modal = UI_ON, @@ -283,7 +295,8 @@ void action_notebook_add(UiEvent *event, void *userdata) { .title = "Add Notebook", .lbutton1 = "Add", .rbutton4 = "Cancel", - .default_button = 1); + .default_button = 1, + .onclick = action_nnd_button); ui_set_group(obj->ctx, NEWNOTEBOOK_DIALOG_STATE_SELECT_GROUP); NewNotebookDialog *wdata = ui_malloc(obj->ctx, sizeof(NewNotebookDialog)); @@ -294,9 +307,10 @@ void action_notebook_add(UiEvent *event, void *userdata) { wdata->new_group = 0; obj->window = wdata; + // Dialog UI ui_grid(obj, .margin = 10, .columnspacing = 10, .rowspacing = 10, .def_vfill = TRUE, .fill = UI_ON) { UIWIDGET gs_label = ui_rlabel(obj, .label = "Group"); - UIWIDGET gs_list = ui_combobox(obj, .varname = "notebook_groups", .hexpand = TRUE, .hfill = TRUE); + UIWIDGET gs_list = ui_combobox(obj, .list = wdata->groups, .getvalue = nnd_group_value, .hexpand = TRUE, .hfill = TRUE); UIWIDGET gs_button = ui_togglebutton(obj, .label = "New Group", .value = wdata->gs_new_group, .onchange = action_nnd_new_group); ui_newline(obj); ui_widget_set_groups(obj->ctx, gs_label, (ui_enablefunc)ui_set_visible, NEWNOTEBOOK_DIALOG_STATE_SELECT_GROUP, -1); @@ -317,6 +331,24 @@ void action_notebook_add(UiEvent *event, void *userdata) { ui_textfield(obj, .varname = "notebook_name", .colspan = 2, .hfill = TRUE); } + // Dialog Data + NoteStore *notestore = note_store_get(); + if(notestore->root) { + if(notestore->root->children) { + CxIterator i = cxListIterator(notestore->root->children); + cx_foreach(Resource *, group, i) { + ui_list_append(wdata->groups, group); + } + ui_list_update(wdata->groups); + } else { + // if no notebooks are available, show the textfield for new groups + ui_set(wdata->gs_new_group, 1); + ui_set_group(event->obj->ctx, NEWNOTEBOOK_DIALOG_STATE_NEW_GROUP); + ui_unset_group(event->obj->ctx, NEWNOTEBOOK_DIALOG_STATE_SELECT_GROUP); + } + } + + ui_show(obj); }