}
}
+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);
.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);