]> uap-core.de Git - note.git/commitdiff
save resource in the New Notebook dialog
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 10 May 2025 05:45:26 +0000 (07:45 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 10 May 2025 05:45:26 +0000 (07:45 +0200)
application/window.c

index 4f4d893d78342d89cd48b94781f76c8924ce171a..bb1e251cdb4da0b8a3cd08e14e3cfa524b8f9f7b 100644 (file)
@@ -276,9 +276,54 @@ static void action_nnd_new_group(UiEvent *event, void *userdata) {
     }
 }
 
+struct NotebookCreatedResult {
+    Resource *parent;
+    Resource *notebook;
+};
+
+static void notebook_created(UiEvent *event, int64_t newid, int error, void *userdata) {
+    struct NotebookCreatedResult *result = userdata;
+    cxListAdd(result->parent->children, result->notebook);
+    free(result);
+    
+    // TODO: update windows
+}
+
 static void action_nnd_button(UiEvent *event, void *userdata) {
+    NewNotebookDialog *wdata = event->window;
     if(event->intval == 1) {
+        char *nodename = ui_get(wdata->notebook_name);
+        cxstring name = cx_str(nodename);
+        if(name.length == 0) {
+            return; // TODO: error
+        }
+        
         // add
+        NoteStore *store = note_store_get();
+        
+        UiListSelection sel = ui_list_getselection(wdata->groups);
+        if(sel.count == 0) {
+            fprintf(stderr, "Error: no group selected\n");
+            return; // TODO: error
+        }
+        Resource *parent = ui_list_get(wdata->groups, sel.rows[0]);
+        ui_listselection_free(sel);
+        
+        if(!parent) {
+            fprintf(stderr, "Error: no parent found\n");
+            return; // TODO: error
+        }
+        
+        Resource *notebook = cxCalloc(store->mp->allocator, 1, sizeof(Resource));
+        notebook->parent_id = parent->resource_id;
+        notebook->nodename = cx_strdup_a(store->mp->allocator, name).ptr;
+        
+        struct NotebookCreatedResult *result = malloc(sizeof(struct NotebookCreatedResult));
+        result->parent = parent;
+        result->notebook = notebook;
+        
+        
+        note_store_new_notebook_async(event->obj, notebook, notebook_created, result);
         
     } // 4: cancel
     ui_close(event->obj);
@@ -298,7 +343,8 @@ void action_notebook_add(UiEvent *event, void *userdata) {
             .rbutton4 = "Cancel",
             .default_button = 1,
             .onclick = action_nnd_button);
-    ui_set_group(obj->ctx, NEWNOTEBOOK_DIALOG_STATE_SELECT_GROUP);
+    // TODO: enable when creating new groups is implemented
+    //ui_set_group(obj->ctx, NEWNOTEBOOK_DIALOG_STATE_SELECT_GROUP);
     
     NewNotebookDialog *wdata = ui_malloc(obj->ctx, sizeof(NewNotebookDialog));
     wdata->groups = ui_list_new(obj->ctx, NULL);