]> uap-core.de Git - note.git/commitdiff
implement nbconfig notebooklist_add
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 25 Jul 2025 19:48:43 +0000 (21:48 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 25 Jul 2025 19:48:43 +0000 (21:48 +0200)
application/nbconfig.c

index 275d639ba20f2b038a629fc02bc168c02e28f463..429e4af748ad014113d8fa71378f96986119e5a3 100644 (file)
@@ -179,7 +179,46 @@ static void nbconfig_grouplist_name_changed(UiEvent *event, void *userdata) {
 }
 
 static void nbconfig_notebooklist_add(UiEvent *event, void *userdata) {
+    NotebookConfigDialog *wdata = event->window;
+    NoteStore *store = note_store_get();
+    
+    Resource *notebook = cxCalloc(store->mp->allocator, 1, sizeof(Resource));
+    notebook->notebook = cxCalloc(store->mp->allocator, 1, sizeof(Notebook));
+    
+    if(wdata->new_notebook) {
+        // TODO
+    }
     
+    wdata->new_notebook = notebook;
+    
+    ui_set(wdata->tab2_notebook_name, "");
+    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;
+    NoteStore *store = note_store_get();
+    
+    if(wdata->new_notebook) {
+        UiBool add_notebook = FALSE;
+        if(!wdata->new_notebook->nodename) {
+            add_notebook = TRUE;
+        } else {
+            cxFree(store->mp->allocator, wdata->new_notebook->nodename);
+        }
+        
+        wdata->new_notebook->nodename = cx_strdup_a(store->mp->allocator, cx_str(ui_get(wdata->tab2_notebook_name))).ptr;
+        
+        if(add_notebook) {
+            cxListAdd(wdata->notebooks, wdata->new_notebook);
+        }
+        nbconfig_update_lists(wdata); // TODO: update only single row
+    }
 }
 
 static void nbconfig_notebooklist_delete(UiEvent *event, void *userdata) {
@@ -297,7 +336,7 @@ void notebook_config_dialog(void) {
                         ui_newline(obj);
                         
                         ui_rlabel(obj, .label = "Name");
-                        ui_textfield(obj, .value = wdata->tab2_notebook_name);
+                        ui_textfield(obj, .value = wdata->tab2_notebook_name, .onchange = nbconfig_notebooklist_name_changed);
                         ui_newline(obj);
 
                         ui_rlabel(obj, .label = "Repository");