From: Olaf Wintermann Date: Tue, 3 Jun 2025 18:03:48 +0000 (+0200) Subject: implement button for adding new groups in the notebook config dialog X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=0563e0d4a0f18553ca8f1dc55e6f8b576f22e652;p=note.git implement button for adding new groups in the notebook config dialog --- diff --git a/application/window.c b/application/window.c index 771b359..7c587f7 100644 --- a/application/window.c +++ b/application/window.c @@ -377,12 +377,15 @@ static void* reslist_getvalue(void *data, int col) { } void nbconfig_update_lists(NotebookConfigDialog *wdata) { + ui_list_clear(wdata->tab1_groups); + ui_list_clear(wdata->tab2_groups); CxIterator i = cxListIterator(wdata->groups); cx_foreach(Resource *, res, i) { ui_list_append(wdata->tab1_groups, res); ui_list_append(wdata->tab2_groups, res); } + ui_list_clear(wdata->tab2_notebooks); i = cxListIterator(wdata->notebooks); cx_foreach(Resource *, res, i) { ui_list_append(wdata->tab2_notebooks, res); @@ -434,6 +437,8 @@ static void nbconfig_grouplist_activate(UiEvent *event, void *userdata) { return; } nbconfig_tab1_load_group(wdata, res); + // TODO: check for empty new group and discard it in that case + wdata->new_group = NULL; } static void nbconfig_notebooklist_activate(UiEvent *event, void *userdata) { @@ -445,6 +450,79 @@ static void nbconfig_notebooklist_activate(UiEvent *event, void *userdata) { nbconfig_tab2_load_notebook(wdata, res); } +static void nbconfig_grouplist_add(UiEvent *event, void *userdata) { + NotebookConfigDialog *wdata = event->window; + NoteStore *store = note_store_get(); + + Resource *group = cxCalloc(store->mp->allocator, 1, sizeof(Resource)); + group->parent_id = store->root->resource_id; + group->notebook = cxCalloc(store->mp->allocator, 1, sizeof(Notebook)); + + if(wdata->new_group) { + // TODO + } + + wdata->new_group = group; + + ui_set(wdata->tab1_group_name, ""); + ui_list_setselection(wdata->tab1_repositories, 0); + ui_list_setselection(wdata->tab1_types, 0); +} + +static void nbconfig_grouplist_delete(UiEvent *event, void *userdata) { + +} + +static void nbconfig_grouplist_move_up(UiEvent *event, void *userdata) { + +} + +static void nbconfig_grouplist_move_down(UiEvent *event, void *userdata) { + +} + +static void nbconfig_grouplist_name_changed(UiEvent *event, void *userdata) { + if(event->set) { + return; + } + NotebookConfigDialog *wdata = event->window; + NoteStore *store = note_store_get(); + + if(wdata->new_group) { + UiBool add_group = FALSE; + if(!wdata->new_group->nodename) { + add_group = TRUE; + } else { + cxFree(store->mp->allocator, wdata->new_group->nodename); + } + + wdata->new_group->nodename = cx_strdup_a(store->mp->allocator, cx_str(ui_get(wdata->tab1_group_name))).ptr; + + if(add_group) { + cxListAdd(wdata->groups, wdata->new_group); + } + nbconfig_update_lists(wdata); // TODO: update only single row + } +} + +static void nbconfig_notebooklist_add(UiEvent *event, void *userdata) { + +} + +static void nbconfig_notebooklist_delete(UiEvent *event, void *userdata) { + +} + +static void nbconfig_notebooklist_move_up(UiEvent *event, void *userdata) { + +} + +static void nbconfig_notebooklist_move_down(UiEvent *event, void *userdata) { + +} + + + void action_notebook_config(UiEvent *event, void *userdata) { NoteStore *store = note_store_get(); // TODO: check store->root and show different dialog, when root is missing @@ -507,16 +585,16 @@ void action_notebook_config(UiEvent *event, void *userdata) { ui_vbox(obj, .fill = UI_OFF) { ui_listview(obj, .list = wdata->tab1_groups, .getvalue = reslist_getvalue, .fill = UI_ON, .onactivate = nbconfig_grouplist_activate); ui_hbox(obj, .fill = UI_OFF) { - ui_button(obj, .icon = UI_ICON_NEW_FOLDER); - ui_button(obj, .icon = UI_ICON_DELETE); - ui_button(obj, .icon = UI_ICON_GO_UP); - ui_button(obj, .icon = UI_ICON_GO_DOWN); + ui_button(obj, .icon = UI_ICON_NEW_FOLDER, .onclick = nbconfig_grouplist_add); + ui_button(obj, .icon = UI_ICON_DELETE, .onclick = nbconfig_grouplist_delete); + ui_button(obj, .icon = UI_ICON_GO_UP, .onclick = nbconfig_grouplist_move_up); + ui_button(obj, .icon = UI_ICON_GO_DOWN, .onclick = nbconfig_grouplist_move_down); } } ui_grid(obj, .columnspacing = 10, .rowspacing = 10, .fill = UI_ON, .def_vfill = TRUE) { ui_rlabel(obj, .label = "Name"); - ui_textfield(obj, .value = wdata->tab1_group_name); + ui_textfield(obj, .value = wdata->tab1_group_name, .onchange = nbconfig_grouplist_name_changed); ui_newline(obj); ui_rlabel(obj, .label = "Default Repository"); @@ -534,10 +612,10 @@ void action_notebook_config(UiEvent *event, void *userdata) { ui_vbox(obj, .fill = UI_OFF) { ui_listview(obj, .list = wdata->tab2_notebooks, .getvalue = reslist_getvalue, .fill = UI_ON, .onactivate = nbconfig_notebooklist_activate); ui_hbox(obj, .fill = UI_OFF) { - ui_button(obj, .icon = UI_ICON_NEW_FOLDER); - ui_button(obj, .icon = UI_ICON_DELETE); - ui_button(obj, .icon = "go-up"); - ui_button(obj, .icon = "go-down"); + ui_button(obj, .icon = UI_ICON_NEW_FOLDER, .onclick = nbconfig_notebooklist_add); + ui_button(obj, .icon = UI_ICON_DELETE, .onclick = nbconfig_notebooklist_delete); + ui_button(obj, .icon = UI_ICON_GO_UP, .onclick = nbconfig_notebooklist_move_up); + ui_button(obj, .icon = UI_ICON_GO_DOWN, .onclick = nbconfig_notebooklist_move_down); } } diff --git a/application/window.h b/application/window.h index 1fef0dd..11596ea 100644 --- a/application/window.h +++ b/application/window.h @@ -65,6 +65,9 @@ typedef struct NotebookConfigDialog { UiString *tab2_notebook_name; UiList *tab2_types; UiList *tab2_repositories; + + Resource *new_group; + Resource *new_notebook; } NotebookConfigDialog; void window_create();