From: Olaf Wintermann Date: Mon, 26 Jan 2026 17:11:12 +0000 (+0100) Subject: implement button for adding new repositories X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=3ee561891c49ed6b0cc279aa597d57c741f13e95;p=note.git implement button for adding new repositories --- diff --git a/application/nbconfig.c b/application/nbconfig.c index a721983..5f04251 100644 --- a/application/nbconfig.c +++ b/application/nbconfig.c @@ -87,6 +87,13 @@ void nbconfig_update_notebooklist(NotebookConfigDialog *wdata, Resource *res) { ui_list_update_row(wdata->tab1_notebooks, index); } +void nbconfig_update_repositorylist(NotebookConfigDialog *wdata, Repository *repo) { + CxList *rplist = wdata->tab3_repositories->data; + size_t index = cxListFind(rplist, repo); + ui_list_update_row(wdata->tab3_repositories, index); + ui_list_update(wdata->tab1_repositories); +} + void nbconfig_update_lists(NotebookConfigDialog *wdata) { ui_list_clear(wdata->tab1_groups); ui_list_clear(wdata->tab1_repositories); @@ -135,6 +142,7 @@ void nbconfig_build_current_names_map(NotebookConfigDialog *wdata, Resource *res static void nbconfig_close(UiEvent *event, void *userdata) { NotebookConfigDialog *wdata = event->window; nbconfig_notebook_save(wdata); + nbconfig_repository_save(wdata); } static int nbconfig_list_activate_event(UiEvent *event, UiList *list, void **listelm) { @@ -496,8 +504,40 @@ static void nbconfig_notebooklist_name_changed(UiEvent *event, void *userdata) { // ---------------------------- Repo Config ----------------------------------- +static void repository_saved(UiEvent *event, int error, void *userdata) { + if(error != 0) { + fprintf(stderr, "Error: note_store_save_repository_async failed\n"); + } +} + void nbconfig_repository_save(NotebookConfigDialog *nbconfig) { + if(!nbconfig->selected_repository) { + return; + } + + Repository *repo = nbconfig->selected_repository; + + NoteStore *store = note_store_get(); + const CxAllocator *a = store->mp->allocator; + + char *prev_name = repo->name; + char *prev_local_path = repo->local_path; + char *prev_url = repo->url; + char *prev_default_key = repo->default_key; + + // TODO: check changes and prepare migration + + repo->name = cx_strdup_a(a, ui_get(nbconfig->tab3_repo_name)).ptr; + repo->local_path = cx_strdup_a(a, ui_get(nbconfig->tab3_repo_local_path)).ptr; + repo->url = cx_strdup_a(a, ui_get(nbconfig->tab3_repo_url)).ptr; + repo->default_key = NULL; + cxFree(a, prev_name); + cxFree(a, prev_local_path); + cxFree(a, prev_url); + cxFree(a, prev_default_key); + + note_store_save_repository_async(application_global_obj(), repo, repository_saved, nbconfig); } static void nbconfig_load_repository(NotebookConfigDialog *wdata, Repository *repo) { @@ -519,7 +559,26 @@ static void nbconfig_load_repository(NotebookConfigDialog *wdata, Repository *re } static void nbconfig_repolist_add(UiEvent *event, void *userdata) { + NotebookConfigDialog *wdata = event->window; + NoteStore *store = note_store_get(); + UiContext *ctx = wdata->obj->ctx; + + nbconfig_repository_save(wdata); + + Repository *repo = cxZalloc(store->mp->allocator, sizeof(Repository)); + wdata->selected_repository = repo; + cxListAdd(wdata->repositories, repo); + nbconfig_update_lists(wdata); + + size_t nrepos = cxListSize(wdata->repositories); + ui_list_setselection2(wdata->tab3_repositories, nrepos-1, FALSE); + + nbconfig_load_repository(wdata, repo); + + ui_free(ctx, wdata->selected_repository_name); + wdata->selected_repository_name = ui_strdup(ctx, "New"); + ui_set(wdata->tab3_repo_name, wdata->selected_repository_name); // override name textfield } static void nbconfig_repolist_delete(UiEvent *event, void *userdata) { @@ -531,7 +590,7 @@ static void nbconfig_repolist_name_changed(UiEvent *event, void *userdata) { } static void nbconfig_repolist_onselect(UiEvent *event, void *userdata) { - NotebookConfigDialog *wdata = userdata; + NotebookConfigDialog *wdata = event->window; if(wdata->valuechange) { return; } diff --git a/application/store.c b/application/store.c index cadcc67..f1cea5e 100644 --- a/application/store.c +++ b/application/store.c @@ -140,7 +140,7 @@ #define SQL_REPOSITORY_NEW \ "insert into repositories(name, url, encryption, default_key, authmethod, local_path) " \ - "values (?, ?, ?, ?, ?, ?) repository_id;" + "values (?, ?, ?, ?, ?, ?) returning repository_id;" #define SQL_REPOSITORY_SAVE \ "update repositories set " \ @@ -1420,7 +1420,7 @@ static int qthr_store_save_repository(SaveRepositoryJob *job) { } else { dbuQuerySetParamNull(q, 2); } - dbuQuerySetParamInt(q, 4, repo->encryption); + dbuQuerySetParamInt(q, 3, repo->encryption); if(repo->url) { dbuQuerySetParamString(q, 4, cx_str(repo->default_key)); } else {