From: Olaf Wintermann Date: Sun, 25 Jan 2026 15:28:32 +0000 (+0100) Subject: implement repo list selection + repo config loading X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=HEAD;p=note.git implement repo list selection + repo config loading --- diff --git a/application/nbconfig.c b/application/nbconfig.c index ce68838..a721983 100644 --- a/application/nbconfig.c +++ b/application/nbconfig.c @@ -275,9 +275,7 @@ static void nbconfig_group_onselect(UiEvent *event, void *userdata) { cxListInsert(nblist, new_insert_pos, wdata->selected_notebook); ui_list_update(wdata->tab1_notebooks); - wdata->valuechange = TRUE; - ui_list_setselection(wdata->tab1_notebooks, new_insert_pos); - wdata->valuechange = FALSE; + ui_list_setselection2(wdata->tab1_notebooks, new_insert_pos, FALSE); } static void nbconfig_tab_view_changed(UiEvent *event, void *userdata) { @@ -306,9 +304,7 @@ static void add_notebook(NotebookConfigDialog *wdata, int64_t parent_id, const c ui_list_update(wdata->tab1_notebooks); int n = ui_list_count(wdata->tab1_notebooks); - wdata->valuechange = TRUE; - ui_list_setselection(wdata->tab1_notebooks, n-1); - wdata->valuechange = FALSE; + ui_list_setselection2(wdata->tab1_notebooks, n-1, FALSE); n = ui_list_count(wdata->tab1_groups); ui_list_setselection(wdata->tab1_groups, n-1); @@ -328,10 +324,8 @@ static void add_notebook(NotebookConfigDialog *wdata, int64_t parent_id, const c } } - wdata->valuechange = TRUE; - ui_list_setselection(wdata->tab1_groups, grouplist_index); - ui_list_setselection(wdata->tab1_notebooks, insert_pos); - wdata->valuechange = FALSE; + ui_list_setselection2(wdata->tab1_groups, grouplist_index, FALSE); + ui_list_setselection2(wdata->tab1_notebooks, insert_pos, FALSE); } ui_set(wdata->tab1_notebook_name, name); @@ -502,6 +496,28 @@ static void nbconfig_notebooklist_name_changed(UiEvent *event, void *userdata) { // ---------------------------- Repo Config ----------------------------------- +void nbconfig_repository_save(NotebookConfigDialog *nbconfig) { + +} + +static void nbconfig_load_repository(NotebookConfigDialog *wdata, Repository *repo) { + wdata->valuechange = TRUE; + + ui_set(wdata->tab3_repo_name, repo->name); + ui_set(wdata->tab3_repo_local_path, repo->local_path); + ui_set(wdata->tab3_repo_url, repo->url); + ui_set(wdata->tab3_repo_isencrypted, repo->encryption); + // TODO: key + + wdata->selected_repository = repo; + // save repository name + UiContext *ctx = wdata->obj->ctx; + ui_free(ctx, wdata->selected_repository_name); + wdata->selected_repository_name = ui_strdup(ctx, repo->name); + + wdata->valuechange = FALSE; +} + static void nbconfig_repolist_add(UiEvent *event, void *userdata) { } @@ -514,6 +530,23 @@ static void nbconfig_repolist_name_changed(UiEvent *event, void *userdata) { } +static void nbconfig_repolist_onselect(UiEvent *event, void *userdata) { + NotebookConfigDialog *wdata = userdata; + if(wdata->valuechange) { + return; + } + + nbconfig_repository_save(wdata); + + Repository *repo; + if(nbconfig_list_activate_event(event, wdata->tab3_repositories, (void**)&repo)) { + return; + } + wdata->selected_repository = repo; + nbconfig_load_repository(wdata, repo); +} + + static void nbconfig_repolist_dir_selected(UiEvent *event, void *userdata) { NotebookConfigDialog *wdata = userdata; UiFileList *flist = event->eventdata; @@ -565,7 +598,7 @@ void notebook_config_dialog(void) { // fill data Resource *group1 = NULL; - Resource *notebook1 = NULL; + Repository *repo1 = NULL; CxIterator i = cxListIterator(store->root->children); cx_foreach(Resource *, res, i) { cxListAdd(wdata->groups, res); @@ -577,6 +610,15 @@ void notebook_config_dialog(void) { cxListAdd(wdata->notebooks, nb); } } + + i = cxListIterator(store->repositories); + cx_foreach(Repository *, repo, i) { + cxListAdd(wdata->repositories, repo); + if(!repo1) { + repo1 = repo; + } + } + nbconfig_update_lists(wdata); ui_list_append(wdata->tab1_types, "Notes"); @@ -637,7 +679,7 @@ void notebook_config_dialog(void) { ui_tab(obj, "Repositories") { ui_hbox(obj, .margin = 10, .spacing = 10, .fill = TRUE) { ui_vbox(obj) { - ui_listview(obj, .list = wdata->tab3_repositories, .getvalue = repolist_get_value, .fill = TRUE, .onactivate = NULL); + ui_listview(obj, .list = wdata->tab3_repositories, .getvalue = repolist_get_value, .fill = TRUE, .onselection = nbconfig_repolist_onselect); ui_hbox(obj) { ui_button(obj, .icon = UI_ICON_NEW_FOLDER, .onclick = nbconfig_repolist_add); ui_button(obj, .icon = UI_ICON_DELETE, .onclick = nbconfig_repolist_delete); @@ -646,23 +688,23 @@ void notebook_config_dialog(void) { ui_grid(obj, .columnspacing = 10, .rowspacing = 10, .fill = TRUE, .def_vfill = TRUE) { ui_rlabel(obj, .label = "Name"); - ui_textfield(obj, .value = wdata->tab3_repo_name, .onchange = nbconfig_repolist_name_changed); + ui_textfield(obj, .value = wdata->tab3_repo_name, .onchange = nbconfig_repolist_name_changed, .width = 300); ui_newline(obj); - ui_rlabel(obj, .label = "Local Path"); - ui_textfield(obj, .value = wdata->tab3_repo_local_path); + ui_rlabel(obj, .label = "Local path"); + ui_textfield(obj, .value = wdata->tab3_repo_local_path, .hfill = TRUE); ui_button(obj, .icon = "document-open", .onclick = nbconfig_repolist_open_dir); ui_newline(obj); - ui_rlabel(obj, .label = "URL"); - ui_textfield(obj, .value = wdata->tab3_repo_url); + ui_rlabel(obj, .label = "WebDAV URL"); + ui_textfield(obj, .value = wdata->tab3_repo_url, .hfill = TRUE); ui_newline(obj); - ui_checkbox(obj, .label = "Encryption", .colspan = 2); + ui_checkbox(obj, .label = "Enable encryption", .colspan = 2, .enable_state = NBCONFIG_STATE_REPOSITORY_ENCRYPTION); ui_newline(obj); - ui_rlabel(obj, .label = "Encryption Key"); - ui_dropdown(obj, .list = wdata->tab3_repo_encryption_key); + ui_rlabel(obj, .label = "Encryption key"); + ui_dropdown(obj, .list = wdata->tab3_repo_encryption_key, .states = UI_GROUPS(NBCONFIG_STATE_REPOSITORY_ENCRYPTION), .hfill = TRUE); } } @@ -671,10 +713,14 @@ void notebook_config_dialog(void) { } ui_list_setselection2(wdata->tab1_notebooks, 0, FALSE); + ui_list_setselection2(wdata->tab3_repositories, 0, FALSE); if(group1) { nbconfig_load_notebook(wdata, group1); } + if(repo1) { + nbconfig_load_repository(wdata, repo1); + } ui_show(obj); } diff --git a/application/nbconfig.h b/application/nbconfig.h index 3b2c5e3..eb4085d 100644 --- a/application/nbconfig.h +++ b/application/nbconfig.h @@ -37,6 +37,7 @@ extern "C" { #endif #define NBCONFIG_STATE_NOTEBOOK_SELECTED 10 +#define NBCONFIG_STATE_REPOSITORY_ENCRYPTION 21 typedef struct NotebookConfigDialog { MainWindow *parent; @@ -84,6 +85,7 @@ Resource* nbconfig_notebooklist_find_prev(NotebookConfigDialog *wdata, Resource Resource* nbconfig_notebooklist_find_next(NotebookConfigDialog *wdata, Resource *res); void nbconfig_notebook_save(NotebookConfigDialog *nbconfig); +void nbconfig_repository_save(NotebookConfigDialog *nbconfig); void notebook_config_dialog(void); diff --git a/ui/common/types.c b/ui/common/types.c index 32cb180..74b8190 100644 --- a/ui/common/types.c +++ b/ui/common/types.c @@ -508,7 +508,7 @@ void ui_string_set(UiString* s, const char* value) { if (s) { if (s->set) { ui_setop_enable(TRUE); - s->set(s, value); + s->set(s, value ? value : ""); ui_setop_enable(FALSE); } else { if(s->value.free) { @@ -538,7 +538,7 @@ void ui_text_set(UiText* s, const char* value) { if (s) { if (s->set) { ui_setop_enable(TRUE); - s->set(s, value); + s->set(s, value ? value : ""); ui_setop_enable(FALSE); } else { if(s->value.free) {