From 0fb64a0e78fbfbad5061840945a066314c1428fd Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Thu, 22 Jan 2026 20:54:04 +0100 Subject: [PATCH] combine groups and notebooks into a single list in the config dialog --- application/nbconfig.c | 584 ++++++++++++++--------------------------- application/nbconfig.h | 19 +- application/store.c | 15 +- 3 files changed, 211 insertions(+), 407 deletions(-) diff --git a/application/nbconfig.c b/application/nbconfig.c index 47822e0..d5c77c0 100644 --- a/application/nbconfig.c +++ b/application/nbconfig.c @@ -43,9 +43,7 @@ static void* reslist_getvalue(UiList *list, void *elm, int row, int col, void *u Resource *resource = elm; switch(col) { case 0: { - if(resource == wdata->selected_group && wdata->selected_group_name) { - return wdata->selected_group_name; - } else if(resource == wdata->selected_notebook && wdata->selected_notebook_name) { + if(resource == wdata->selected_notebook && wdata->selected_notebook_name) { return wdata->selected_notebook_name; } return resource->displayname ? resource->displayname : resource->nodename; @@ -59,34 +57,53 @@ static void* reslist_getvalue(UiList *list, void *elm, int row, int col, void *u return NULL; } +static UiBool reslist_getstyle(UiList *list, void *elm, int row, int col, void *userdata, UiTextStyle *style) { + NotebookConfigDialog *wdata = userdata; + Resource *resource = elm; + if(col == -1) { + if(resource->parent_id == wdata->root_resource_id) { + style->text_style = UI_TEXT_STYLE_BOLD; + return TRUE; + } + } + return FALSE; +} + static void* repolist_get_value(void *data, int col) { Repository *repo = data; return repo->name; } -void nbconfig_update_list(NotebookConfigDialog *wdata, CxList *list, int index) { - if(list == wdata->groups) { - ui_list_update_row(wdata->tab1_groups, index); - ui_list_update_row(wdata->tab2_groups, index); - } else if(list == wdata->notebooks) { - ui_list_update_row(wdata->tab2_notebooks, index); +void nbconfig_update_notebooklist(NotebookConfigDialog *wdata, Resource *res) { + CxList *nblist = wdata->tab1_notebooks->data; + size_t index = cxListFind(nblist, res); + + if(res->parent_id == wdata->root_resource_id) { + CxList *grouplist = wdata->tab1_groups->data; + size_t group_index = cxListFind(grouplist, res); + ui_list_update_row(wdata->tab1_groups, (int)group_index); } + + ui_list_update_row(wdata->tab1_notebooks, index); } void nbconfig_update_lists(NotebookConfigDialog *wdata) { ui_list_clear(wdata->tab1_groups); - ui_list_clear(wdata->tab2_groups); + ui_list_clear(wdata->tab1_repositories); ui_list_clear(wdata->tab3_repositories); 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); + ui_list_clear(wdata->tab1_notebooks); + i = cxListIterator(wdata->groups); cx_foreach(Resource *, res, i) { - ui_list_append(wdata->tab2_notebooks, res); + ui_list_append(wdata->tab1_notebooks, res); + CxIterator c = cxListIterator(res->children); + cx_foreach(Resource *, nb, c) { + ui_list_append(wdata->tab1_notebooks, nb); + } } i = cxListIterator(wdata->repositories); @@ -95,10 +112,8 @@ void nbconfig_update_lists(NotebookConfigDialog *wdata) { } ui_list_update(wdata->tab1_groups); + ui_list_update(wdata->tab1_notebooks); ui_list_update(wdata->tab1_repositories); - ui_list_update(wdata->tab2_groups); - ui_list_update(wdata->tab2_notebooks); - ui_list_update(wdata->tab2_repositories); ui_list_update(wdata->tab3_repositories); } @@ -117,33 +132,10 @@ void nbconfig_build_current_names_map(NotebookConfigDialog *wdata, Resource *res } } -static void nbconfig_tab1_load_group(NotebookConfigDialog *wdata, Resource *res) { - ui_set(wdata->tab1_group_name, res->nodename); - - wdata->selected_group = res; - // save group name - UiContext *ctx = wdata->obj->ctx; - ui_free(ctx, wdata->selected_group_name); - wdata->selected_group_name = ui_strdup(ctx, res->nodename); -} - -static void nbconfig_tab2_load_notebook(NotebookConfigDialog *wdata, Resource *res) { - Notebook *nb = res->notebook; - - ui_set(wdata->tab2_notebook_name, res->nodename); - CxIterator i = cxListIterator(wdata->groups); - cx_foreach(Resource *, parent, i) { - if(parent->resource_id == res->parent_id) { - ui_list_setselection(wdata->tab2_groups, (int)i.index); - break; - } - } - - wdata->selected_notebook = res; - // save notebook name - UiContext *ctx = wdata->obj->ctx; - ui_free(ctx, wdata->selected_notebook_name); - wdata->selected_notebook_name = ui_strdup(ctx, res->nodename); +static void nbconfig_close(UiEvent *event, void *userdata) { + NotebookConfigDialog *wdata = event->window; + //nbconfig_group_save(wdata); + //nbconfig_notebook_save(wdata); } static int nbconfig_list_activate_event(UiEvent *event, UiList *list, void **listelm) { @@ -157,155 +149,7 @@ static int nbconfig_list_activate_event(UiEvent *event, UiList *list, void **lis return 0; } - -static void group_saved(UiEvent *event, int error, void *userdata) { - if(error) { - fprintf(stderr, "Error: note_store_save_notebook_async failed\n"); - } -} - -static void nbconfig_group_save(NotebookConfigDialog *nbconfig) { - Resource *res = nbconfig->selected_group; - if(!res) { - return; - } - - Resource *dup = cxMapGet(nbconfig->current_names, nbconfig->selected_group_name); - if(dup) { - fprintf(stderr, "Name %s already in use\n", nbconfig->selected_group_name); - // TODO: show error in UI - return; - } - - NoteStore *store = note_store_get(); - cxFree(store->mp->allocator, nbconfig->selected_group->nodename); - nbconfig->selected_group->nodename = cx_strdup_a(store->mp->allocator, nbconfig->selected_group_name).ptr; - - note_store_save_notebook_async(application_global_obj(), res, 0, group_saved, res); -} - -static void nbconfig_grouplist_onselect(UiEvent *event, void *userdata) { - NotebookConfigDialog *wdata = event->window; - if(wdata->valuechange) { - return; - } - Resource *res; - if(nbconfig_list_activate_event(event, wdata->tab1_groups, (void**)&res)) { - return; - } - - nbconfig_group_save(wdata); - nbconfig_tab1_load_group(wdata, res); - wdata->selected_group = res; - - nbconfig_build_current_names_map(wdata, res); -} - -static void nbconfig_grouplist_add(UiEvent *event, void *userdata) { - NotebookConfigDialog *wdata = event->window; - NoteStore *store = note_store_get(); - - nbconfig_group_save(wdata); - - 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)); - group->nodename = cx_strdup_a(store->mp->allocator, "New").ptr; - group->iscollection = TRUE; - - wdata->selected_group = group; - size_t ngroups = cxListSize(wdata->groups); - cxListAdd(wdata->groups, group); - nbconfig_update_lists(wdata); - ui_list_setselection(wdata->tab1_groups, (int)ngroups); - - ui_set(wdata->tab1_group_name, "New"); - - ui_list_setselection(wdata->tab1_repositories, 0); - ui_list_setselection(wdata->tab1_types, 0); - - // TODO: select textfield text -} - -static void nbconfig_grouplist_delete(UiEvent *event, void *userdata) { - -} - -static void nbconfig_grouplist_move_result(UiEvent *event, int error, void *userdata) { - notebooklist_move_inprogress = FALSE; - if(!error) { - NotebookConfigDialog *wdata = event->window; - cxListSwap(wdata->notebooks, notebooklist_move_pos0, notebooklist_move_pos1); - nbconfig_update_lists(wdata); - } else { - printf("nbconfig_notebooklist_move_up_result: error %d\n", error); - } -} - -static void nbconfig_grouplist_move_up(UiEvent *event, void *userdata) { - if(notebooklist_move_inprogress) { - return; - } - - NotebookConfigDialog *wdata = event->window; - UiListSelection sel = ui_list_getselection(wdata->tab1_groups); - if(sel.count == 1 && sel.rows[0] > 0) { - int row = sel.rows[0]; - notebooklist_move_pos0 = row; - notebooklist_move_pos1 = row-1; - Resource *r0 = cxListAt(wdata->groups, notebooklist_move_pos0); - Resource *r1 = cxListAt(wdata->groups, notebooklist_move_pos1); - note_store_notebook_swap_position_async(event->obj, r0->notebook, r1->notebook, nbconfig_grouplist_move_result, NULL); - notebooklist_move_inprogress = TRUE; - } - ui_listselection_free(sel); -} - -static void nbconfig_grouplist_move_down(UiEvent *event, void *userdata) { - if(notebooklist_move_inprogress) { - return; - } - - NotebookConfigDialog *wdata = event->window; - UiListSelection sel = ui_list_getselection(wdata->tab1_groups); - if(sel.count == 1 && sel.rows[0] > 0) { - int row = sel.rows[0]; - notebooklist_move_pos0 = row; - notebooklist_move_pos1 = row+1; - Resource *r0 = cxListAt(wdata->groups, notebooklist_move_pos0); - Resource *r1 = cxListAt(wdata->groups, notebooklist_move_pos1); - note_store_notebook_swap_position_async(event->obj, r0->notebook, r1->notebook, nbconfig_grouplist_move_result, NULL); - notebooklist_move_inprogress = TRUE; - } - ui_listselection_free(sel); -} - -static void nbconfig_grouplist_name_changed(UiEvent *event, void *userdata) { - if(event->set) { - return; - } - NotebookConfigDialog *wdata = event->window; - UiContext *ctx = wdata->obj->ctx; - - wdata->valuechange = TRUE; - - if(wdata->selected_group) { - char *input = ui_get(wdata->tab1_group_name); - - ui_free(ctx, wdata->selected_group_name); - wdata->selected_group_name = ui_strdup(ctx, input); - - nbconfig_update_list(wdata, wdata->groups, cxListFind(wdata->groups, wdata->selected_group)); - - Resource *dup = cxMapGet(wdata->current_names, input); - if(dup) { - fprintf(stderr, "Name %s already in use\n", input); - // TODO: show error in UI - } - } - - wdata->valuechange = FALSE; -} +// ------------------------------- Notebooks --------------------------------- static void notebook_saved(UiEvent *event, int error, void *userdata) { if(error) { @@ -313,7 +157,7 @@ static void notebook_saved(UiEvent *event, int error, void *userdata) { } } -static void nbconfig_notebook_save(NotebookConfigDialog *nbconfig) { +void nbconfig_notebook_save(NotebookConfigDialog *nbconfig) { Resource *res = nbconfig->selected_notebook; if(!res) { return; @@ -333,21 +177,48 @@ static void nbconfig_notebook_save(NotebookConfigDialog *nbconfig) { nbconfig->selected_notebook->nodename = cx_strdup_a(store->mp->allocator, nbconfig->selected_notebook_name).ptr; // update parent - UiListSelection sel = ui_list_getselection(nbconfig->tab2_groups); - if(sel.count == 0) { - return; // shouldn't happen, maybe remove this when ui_list_getselectedindex exists - } - Resource *parent = ui_list_get(nbconfig->tab2_groups, sel.rows[0]); - if(!parent) { - return; //shouldn't happen - } - ui_listselection_free(sel); int64_t prev_parent_id = res->parent_id; - res->parent_id = parent->resource_id; + if(res->parent_id != nbconfig->root_resource_id) { + UiListSelection sel = ui_list_getselection(nbconfig->tab1_groups); + if(sel.count == 0) { + return; // shouldn't happen, maybe remove this when ui_list_getselectedindex exists + } + Resource *parent = ui_list_get(nbconfig->tab1_groups, sel.rows[0]); + if(!parent) { + return; //shouldn't happen + } + ui_listselection_free(sel); + prev_parent_id = res->parent_id; + res->parent_id = parent->resource_id; + } + note_store_save_notebook_async(application_global_obj(), res, prev_parent_id, notebook_saved, res); } +static void nbconfig_load_notebook(NotebookConfigDialog *wdata, Resource *res) { + Notebook *nb = res->notebook; + + ui_set(wdata->tab1_notebook_name, res->nodename); + if(res->parent_id != wdata->root_resource_id) { + CxIterator i = cxListIterator(wdata->groups); + cx_foreach(Resource *, parent, i) { + if(parent->resource_id == res->parent_id) { + ui_list_setselection(wdata->tab1_groups, (int)i.index); + break; + } + } + } else { + // TODO: hide group dropdown menu + } + + wdata->selected_notebook = res; + // save notebook name + UiContext *ctx = wdata->obj->ctx; + ui_free(ctx, wdata->selected_notebook_name); + wdata->selected_notebook_name = ui_strdup(ctx, res->nodename); +} + static void nbconfig_notebooklist_onselect(UiEvent *event, void *userdata) { NotebookConfigDialog *wdata = event->window; if(wdata->valuechange) { @@ -357,64 +228,91 @@ static void nbconfig_notebooklist_onselect(UiEvent *event, void *userdata) { nbconfig_notebook_save(wdata); Resource *res; - if(nbconfig_list_activate_event(event, wdata->tab2_notebooks, (void**)&res)) { + if(nbconfig_list_activate_event(event, wdata->tab1_notebooks, (void**)&res)) { return; } wdata->selected_notebook = res; - nbconfig_tab2_load_notebook(wdata, res); + nbconfig_load_notebook(wdata, res); nbconfig_build_current_names_map(wdata, res); } -static void nbconfig_notebooklist_add(UiEvent *event, void *userdata) { - NotebookConfigDialog *wdata = event->window; +static void nbconfig_tab_view_changed(UiEvent *event, void *userdata) { + +} + +static void add_notebook(NotebookConfigDialog *wdata, int64_t parent_id, const char *name) { NoteStore *store = note_store_get(); UiContext *ctx = wdata->obj->ctx; - Resource *parent = cxListAt(wdata->groups, 0); - Resource *notebook = cxCalloc(store->mp->allocator, 1, sizeof(Resource)); notebook->notebook = cxCalloc(store->mp->allocator, 1, sizeof(Notebook)); - if(parent) { - notebook->parent_id = parent->resource_id; - } - cxListAdd(wdata->notebooks, notebook); + notebook->parent_id = parent_id; wdata->selected_notebook = notebook; ui_free(ctx, wdata->selected_notebook_name); - wdata->selected_notebook_name = ui_strdup(ctx, "New"); - nbconfig_update_lists(wdata); - - ui_set(wdata->tab2_notebook_name, "New"); - ui_list_setselection(wdata->tab2_repositories, 0); - ui_list_setselection(wdata->tab2_types, 0); -} - -static void nbconfig_notebooklist_name_changed(UiEvent *event, void *userdata) { - if(event->set) { - return; - } - - NotebookConfigDialog *wdata = event->window; - UiContext *ctx = wdata->obj->ctx; - - wdata->valuechange = TRUE; - - if(wdata->selected_notebook) { - char *input = ui_get(wdata->tab2_notebook_name); - ui_free(ctx, wdata->selected_notebook_name); - wdata->selected_notebook_name = ui_strdup(ctx, input); + wdata->selected_notebook_name = ui_strdup(ctx, name); + + if(parent_id == wdata->root_resource_id) { + cxListAdd(wdata->groups, notebook); + ui_list_append(wdata->tab1_groups, notebook); + ui_list_append(wdata->tab1_notebooks, notebook); + ui_list_update(wdata->tab1_groups); + ui_list_update(wdata->tab1_notebooks); - nbconfig_update_list(wdata, wdata->notebooks, cxListFind(wdata->notebooks, wdata->selected_notebook)); + int n = ui_list_count(wdata->tab1_notebooks); + wdata->valuechange = TRUE; + ui_list_setselection(wdata->tab1_notebooks, n-1); + wdata->valuechange = FALSE; - Resource *dup = cxMapGet(wdata->current_names, input); - if(dup) { - fprintf(stderr, "Name %s already in use\n", input); - // TODO: show error in UI + n = ui_list_count(wdata->tab1_groups); + ui_list_setselection(wdata->tab1_groups, n-1); + } else { + cxListAdd(wdata->notebooks, notebook); + CxList *nblist = wdata->tab1_notebooks->data; + size_t insert_pos = 0; + int group_index = -1; + CxIterator i = cxListIterator(nblist); + cx_foreach(Resource *, res, i) { + if(group_index >= 0) { + if(res->parent_id != parent_id) { + break; + } + } else if(res->parent_id == parent_id) { + group_index = (int)i.index; + } + insert_pos = i.index; } + insert_pos++; + + cxListInsert(nblist, insert_pos, notebook); + ui_list_update(wdata->tab1_notebooks); + ui_list_update_row(wdata->tab1_groups, group_index); + + wdata->valuechange = TRUE; + ui_list_setselection(wdata->tab1_notebooks, insert_pos); + wdata->valuechange = FALSE; } - wdata->valuechange = FALSE; + ui_set(wdata->tab1_notebook_name, name); + ui_list_setselection(wdata->tab1_repositories, 0); + + ui_textfield_focus(wdata->tab1_notebook_name_textfield); +} + +static void nbconfig_notebooklist_add_group(UiEvent *event, void *userdata) { + NotebookConfigDialog *wdata = event->window; + add_notebook(wdata, wdata->root_resource_id, "New Group"); +} + +static void nbconfig_notebooklist_add_notebook(UiEvent *event, void *userdata) { + NotebookConfigDialog *wdata = event->window; + Resource *parent = cxListAt(wdata->groups, 0); + if(!parent) { + fprintf(stderr, "Error: cannot create a notebook without a group\n"); + return; + } + add_notebook(wdata, parent->resource_id, "New"); } static void notebook_count_children_result(UiEvent *event, int64_t num, int error, void *userdata) { @@ -436,7 +334,7 @@ static void nbconfig_notebooklist_delete(UiEvent *event, void *userdata) { NotebookConfigDialog *wdata = event->window; NoteStore *store = note_store_get(); - UiListSelection sel = ui_list_getselection(wdata->tab2_notebooks); + UiListSelection sel = ui_list_getselection(wdata->tab1_notebooks); if(sel.count == 1) { CxList *list = wdata->notebooks; Resource *delete_res = cxListAt(list, sel.rows[0]); @@ -445,67 +343,46 @@ static void nbconfig_notebooklist_delete(UiEvent *event, void *userdata) { ui_listselection_free(sel); } -static void nbconfig_notebooklist_move_result(UiEvent *event, int error, void *userdata) { - notebooklist_move_inprogress = FALSE; - if(!error) { - NotebookConfigDialog *wdata = event->window; - cxListSwap(wdata->notebooks, notebooklist_move_pos0, notebooklist_move_pos1); - nbconfig_update_lists(wdata); - } else { - printf("nbconfig_notebooklist_move_up_result: error %d\n", error); - } -} - - static void nbconfig_notebooklist_move_up(UiEvent *event, void *userdata) { - if(notebooklist_move_inprogress) { - return; - } - NotebookConfigDialog *wdata = event->window; - UiListSelection sel = ui_list_getselection(wdata->tab2_notebooks); - if(sel.count == 1 && sel.rows[0] > 0) { - int row = sel.rows[0]; - notebooklist_move_pos0 = row; - notebooklist_move_pos1 = row-1; - Resource *r0 = cxListAt(wdata->notebooks, notebooklist_move_pos0); - Resource *r1 = cxListAt(wdata->notebooks, notebooklist_move_pos1); - note_store_notebook_swap_position_async(event->obj, r0->notebook, r1->notebook, nbconfig_notebooklist_move_result, NULL); - notebooklist_move_inprogress = TRUE; - } - ui_listselection_free(sel); } static void nbconfig_notebooklist_move_down(UiEvent *event, void *userdata) { - if(notebooklist_move_inprogress) { + +} + +static void nbconfig_notebooklist_name_changed(UiEvent *event, void *userdata) { + if(event->set) { return; } NotebookConfigDialog *wdata = event->window; - UiListSelection sel = ui_list_getselection(wdata->tab2_notebooks); - size_t sz = cxListSize(wdata->notebooks); - if(sel.count == 1 && sel.rows[0]+1 < sz) { - int row = sel.rows[0]; - notebooklist_move_pos0 = row; - notebooklist_move_pos1 = row+1; - Resource *r0 = cxListAt(wdata->notebooks, notebooklist_move_pos0); - Resource *r1 = cxListAt(wdata->notebooks, notebooklist_move_pos1); - note_store_notebook_swap_position_async(event->obj, r0->notebook, r1->notebook, nbconfig_notebooklist_move_result, NULL); - notebooklist_move_inprogress = TRUE; + UiContext *ctx = wdata->obj->ctx; + + wdata->valuechange = TRUE; + + if(wdata->selected_notebook) { + char *input = ui_get(wdata->tab1_notebook_name); + ui_free(ctx, wdata->selected_notebook_name); + wdata->selected_notebook_name = ui_strdup(ctx, input); + + nbconfig_update_notebooklist(wdata, wdata->selected_notebook); + + Resource *dup = cxMapGet(wdata->current_names, input); + if(dup) { + fprintf(stderr, "Name %s already in use\n", input); + // TODO: show error in UI + } } - ui_listselection_free(sel); + + wdata->valuechange = FALSE; } +// ---------------------------- Repo Config ----------------------------------- + static void nbconfig_repolist_add(UiEvent *event, void *userdata) { - NotebookConfigDialog *wdata = event->window; - NoteStore *store = note_store_get(); - Repository *repo = cxCalloc(store->mp->allocator, 1, sizeof(Repository)); - wdata->new_repository = repo; - - ui_set(wdata->tab3_repo_name, ""); - ui_list_setselection(wdata->tab3_repositories, 0); } static void nbconfig_repolist_delete(UiEvent *event, void *userdata) { @@ -513,28 +390,7 @@ static void nbconfig_repolist_delete(UiEvent *event, void *userdata) { } static void nbconfig_repolist_name_changed(UiEvent *event, void *userdata) { - if(event->set) { - return; - } - - NotebookConfigDialog *wdata = event->window; - NoteStore *store = note_store_get(); - if(wdata->new_repository) { - UiBool add = FALSE; - if(!wdata->new_repository) { - add = TRUE; - } else { - cxFree(store->mp->allocator, wdata->new_repository->name); - } - - wdata->new_repository->name = cx_strdup_a(store->mp->allocator, cx_str(ui_get(wdata->tab3_repo_name))).ptr; - - if(add) { - cxListAdd(wdata->repositories, wdata->new_repository); - } - nbconfig_update_lists(wdata); - } } static void nbconfig_repolist_dir_selected(UiEvent *event, void *userdata) { @@ -551,31 +407,6 @@ static void nbconfig_repolist_open_dir(UiEvent *event, void *userdata) { ui_openfiledialog(event->obj, UI_FILEDIALOG_SELECT_FOLDER, nbconfig_repolist_dir_selected, wdata); } -static void nbconfig_close(UiEvent *event, void *userdata) { - NotebookConfigDialog *wdata = event->window; - nbconfig_group_save(wdata); - nbconfig_notebook_save(wdata); -} - -static void nbconfig_tab_view_changed(UiEvent *event, void *userdata) { - NotebookConfigDialog *wdata = event->window; - - switch(event->intval) { - case 0: { - if(wdata->selected_group) { - nbconfig_build_current_names_map(wdata, wdata->selected_group); - } - break; - } - case 1: { - if(wdata->selected_notebook) { - nbconfig_build_current_names_map(wdata, wdata->selected_notebook); - } - break; - } - } -} - void notebook_config_dialog(void) { NoteStore *store = note_store_get(); // TODO: check store->root and show different dialog, when root is missing @@ -589,15 +420,11 @@ void notebook_config_dialog(void) { wdata->obj = obj; obj->window = wdata; + wdata->tab1_notebooks = ui_list_new(obj->ctx, NULL); wdata->tab1_groups = ui_list_new(obj->ctx, NULL); - wdata->tab1_group_name = ui_string_new(obj->ctx, NULL); + wdata->tab1_notebook_name = ui_string_new(obj->ctx, NULL); wdata->tab1_types = ui_list_new(obj->ctx, NULL); wdata->tab1_repositories = ui_list_new(obj->ctx, NULL); - wdata->tab2_notebooks = ui_list_new(obj->ctx, NULL); - wdata->tab2_groups = ui_list_new(obj->ctx, NULL); - wdata->tab2_notebook_name = ui_string_new(obj->ctx, NULL); - wdata->tab2_types = ui_list_new(obj->ctx, NULL); - wdata->tab2_repositories = ui_list_new(obj->ctx, NULL); wdata->tab3_repositories = ui_list_new(obj->ctx, NULL); wdata->tab3_repo_name = ui_string_new(obj->ctx, NULL); wdata->tab3_repo_local_path = ui_string_new(obj->ctx, NULL); @@ -611,6 +438,10 @@ void notebook_config_dialog(void) { wdata->current_names = cxHashMapCreate(a, CX_STORE_POINTERS, 16); + if(store->root) { + wdata->root_resource_id = store->root->resource_id; + } + // fill data Resource *group1 = NULL; Resource *notebook1 = NULL; @@ -630,67 +461,46 @@ void notebook_config_dialog(void) { ui_list_append(wdata->tab1_types, "Notes"); ui_list_append(wdata->tab1_types, "Feed"); - ui_list_append(wdata->tab2_types, "Notes"); - ui_list_append(wdata->tab2_types, "Feed"); - // UI ui_grid(obj, .margin = 10, .columnspacing = 10, .rowspacing = 10, .fill = TRUE) { ui_tabview(obj, .hfill = TRUE, .hexpand = TRUE, .vfill = TRUE, .vexpand = TRUE, .onchange = nbconfig_tab_view_changed) { - ui_tab(obj, "Groups") { - ui_hbox(obj, .margin = 10, .spacing = 10, .fill = TRUE) { - ui_vbox(obj, .fill = FALSE) { - ui_listview(obj, .list = wdata->tab1_groups, .getvalue2 = reslist_getvalue, .getvalue2data = wdata, .fill = TRUE, .onselection = nbconfig_grouplist_onselect); - ui_hbox(obj, .fill = FALSE) { - 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 = TRUE, .def_vfill = TRUE) { - ui_rlabel(obj, .label = "Name"); - ui_textfield(obj, .value = wdata->tab1_group_name, .onchange = nbconfig_grouplist_name_changed); - ui_newline(obj); - - ui_rlabel(obj, .label = "Default Repository"); - ui_dropdown(obj, .list = wdata->tab1_repositories); - ui_newline(obj); - - ui_rlabel(obj, .label = "Default Notebook Type"); - ui_dropdown(obj, .list = wdata->tab1_types); - ui_newline(obj); - } - } - } ui_tab(obj, "Notebooks") { ui_hbox(obj, .margin = 10, .spacing = 10, .fill = TRUE) { - ui_vbox(obj) { - ui_listview(obj, .list = wdata->tab2_notebooks, .getvalue2 = reslist_getvalue, .getvalue2data = wdata, .fill = TRUE, .onselection = nbconfig_notebooklist_onselect); - ui_hbox(obj) { - ui_button(obj, .icon = UI_ICON_NEW_FOLDER, .onclick = nbconfig_notebooklist_add); - ui_button(obj, .icon = UI_ICON_DELETE, .onclick = nbconfig_notebooklist_delete); + ui_vbox0(obj) { + ui_hbox(obj, .spacing = 2) { + ui_button(obj, .label = "New Group", .onclick = nbconfig_notebooklist_add_group); + ui_button(obj, .label = "New Notebook", .onclick = nbconfig_notebooklist_add_notebook); 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); + ui_button(obj, .icon = UI_ICON_DELETE, .onclick = nbconfig_notebooklist_delete); } + UiModel *model = ui_model(obj->ctx, UI_STRING, "Notebook", -1); + model->columnsize[0] = -1; + ui_table(obj, + .list = wdata->tab1_notebooks, + .model = model, + .getvalue2 = reslist_getvalue, .getvalue2data = wdata, + .getstyle = reslist_getstyle, .getstyledata = wdata, + .width = 300, .fill = TRUE, + .onselection = nbconfig_notebooklist_onselect); } - + ui_grid(obj, .columnspacing = 10, .rowspacing = 10, .fill = TRUE, .def_vfill = TRUE) { ui_rlabel(obj, .label = "Group"); - ui_dropdown(obj, .list = wdata->tab2_groups, .getvalue2 = reslist_getvalue, .getvalue2data = wdata); + ui_dropdown(obj, .list = wdata->tab1_groups, .getvalue2 = reslist_getvalue, .getvalue2data = wdata); ui_newline(obj); - + ui_rlabel(obj, .label = "Name"); - ui_textfield(obj, .value = wdata->tab2_notebook_name, .onchange = nbconfig_notebooklist_name_changed); + wdata->tab1_notebook_name_textfield = ui_textfield(obj, .value = wdata->tab1_notebook_name, .onchange = nbconfig_notebooklist_name_changed); ui_newline(obj); ui_rlabel(obj, .label = "Repository"); ui_dropdown(obj, .list = wdata->tab1_repositories); ui_newline(obj); - + ui_rlabel(obj, .label = "Type"); - ui_dropdown(obj, .list = wdata->tab2_types); + ui_dropdown(obj, .list = wdata->tab1_types); ui_newline(obj); } } @@ -731,14 +541,12 @@ void notebook_config_dialog(void) { } } - ui_list_setselection(wdata->tab1_groups, 0); - ui_list_setselection(wdata->tab2_notebooks, 0); + wdata->valuechange = TRUE; + ui_list_setselection(wdata->tab1_notebooks, 0); + wdata->valuechange = FALSE; if(group1) { - nbconfig_tab1_load_group(wdata, group1); - } - if(notebook1) { - nbconfig_tab2_load_notebook(wdata, notebook1); + nbconfig_load_notebook(wdata, group1); } ui_show(obj); diff --git a/application/nbconfig.h b/application/nbconfig.h index 84fc334..a24da0a 100644 --- a/application/nbconfig.h +++ b/application/nbconfig.h @@ -40,19 +40,17 @@ typedef struct NotebookConfigDialog { MainWindow *parent; UiObject *obj; + UIWIDGET tab1_notebook_name_textfield; + CxList *repositories; CxList *groups; CxList *notebooks; + UiList *tab1_notebooks; UiList *tab1_groups; - UiString *tab1_group_name; + UiString *tab1_notebook_name; UiList *tab1_types; UiList *tab1_repositories; - UiList *tab2_notebooks; - UiList *tab2_groups; - UiString *tab2_notebook_name; - UiList *tab2_types; - UiList *tab2_repositories; UiList *tab3_repositories; UiString *tab3_repo_name; UiString *tab3_repo_url; @@ -60,11 +58,10 @@ typedef struct NotebookConfigDialog { UiList *tab3_repo_encryption_key; UiInteger *tab3_repo_isencrypted; - Resource *selected_group; Resource *selected_notebook; - Repository *new_repository; - char *selected_group_name; + Repository *selected_repository; char *selected_notebook_name; + cchar *selected_repository_name; // a map of all used names in the current context // (all resource names in selected_group -> parent -> children) @@ -72,6 +69,8 @@ typedef struct NotebookConfigDialog { // set to true if currently a textfield onchange callback is running UiBool valuechange; + + int64_t root_resource_id; } NotebookConfigDialog; void nbconfig_update_list(NotebookConfigDialog *wdata, CxList *list, int index); @@ -79,6 +78,8 @@ void nbconfig_update_lists(NotebookConfigDialog *wdata); void nbconfig_build_current_names_map(NotebookConfigDialog *wdata, Resource *res); +void nbconfig_notebook_save(NotebookConfigDialog *nbconfig); + void notebook_config_dialog(void); diff --git a/application/store.c b/application/store.c index 5fb6980..ee274e5 100644 --- a/application/store.c +++ b/application/store.c @@ -1216,12 +1216,7 @@ static void uithr_execjob_finished(UiEvent *event, ExecJob *job) { #define NOTESTORE_COLLECTION_DELETE_ALL 1 static int qthr_delete_collection(ExecJob *job) { - if(job->flag == NOTESTORE_COLLECTION_DELETE_ALL) { - if(dbuSqlExecParamInt64(connection, SQL_RESOURCE_DELETE, job->id1)) { - job->error = 3; - return 0; - } - } else { + if(job->flag != NOTESTORE_COLLECTION_DELETE_ALL) { // only delete the resource when there are no children int64_t nchildren = note_store_count_children(job->id1); if(nchildren > 0) { @@ -1232,10 +1227,10 @@ static int qthr_delete_collection(ExecJob *job) { job->error = 2; // db error return 0; } - - if(dbuSqlExecParamInt64(connection, SQL_RESOURCE_DELETE, job->id1)) { - job->error = 3; - } + } + + if(dbuSqlExecParamInt64(connection, SQL_RESOURCE_DELETE, job->id1)) { + job->error = 3; } return 0; -- 2.47.3