]> uap-core.de Git - note.git/commitdiff
implement repo list selection + repo config loading main
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 25 Jan 2026 15:28:32 +0000 (16:28 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 25 Jan 2026 15:28:32 +0000 (16:28 +0100)
application/nbconfig.c
application/nbconfig.h
ui/common/types.c

index ce688380e4f55afe08e6cf7f990854eb5d71adbd..a7219839ba0827e6fb2fc2eb57607b35826693ef 100644 (file)
@@ -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);
 }
index 3b2c5e39c8b2e755a098f4c1531f3187dce462ad..eb4085d27ae745eb26032facc7193318c01025a2 100644 (file)
@@ -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);
 
index 32cb180e716e128563f74b409b6459ec5b5d19e5..74b8190805ad475bb9c3233a6a84c8c1ba679a9f 100644 (file)
@@ -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) {