ui_list_update(wdata->tab3_repositories);
}
+void nbconfig_build_current_names_map(NotebookConfigDialog *wdata, Resource *res) {
+ NoteStore *store = note_store_get();
+ Resource *parent = note_store_get_notebook_by_id(store, res->parent_id);
+ if(parent) {
+ cxMapClear(wdata->current_names);
+ CxIterator i = cxListIterator(parent->children);
+ cx_foreach(Resource *, child, i) {
+ if(child != res) {
+ cxMapPut(wdata->current_names, child->nodename, child);
+ }
+ }
+ cxMapRehash(wdata->current_names);
+ }
+}
+
static void nbconfig_tab1_load_group(NotebookConfigDialog *wdata, Resource *res) {
ui_set(wdata->tab1_group_name, res->nodename);
wdata->selected_group = res;
+ // save group name
+ UiContext *ctx = wdata->obj->ctx;
+ ui_free(ctx, wdata->selected_group_name);
+ wdata->selected_group_name = ui_strdup(ctx, res->nodename);
}
static void nbconfig_tab2_load_notebook(NotebookConfigDialog *wdata, Resource *res) {
}
wdata->selected_notebook = res;
+ // save notebook name
+ UiContext *ctx = wdata->obj->ctx;
+ ui_free(ctx, wdata->selected_notebook_name);
+ wdata->selected_notebook_name = ui_strdup(ctx, res->nodename);
}
static int nbconfig_list_activate_event(UiEvent *event, UiList *list, void **listelm) {
return;
}
+ Resource *dup = cxMapGet(nbconfig->current_names, res->nodename);
+ if(dup) {
+ fprintf(stderr, "Name %s already in use\n", res->nodename);
+ // TODO: show error in UI
+ // TODO: restore old name
+ return;
+ }
+
if(res->resource_id == 0) {
note_store_new_notebook_async(application_global_obj(), res, group_created, res);
} else {
nbconfig_group_save(wdata);
nbconfig_tab1_load_group(wdata, res);
wdata->selected_group = res;
+
+ nbconfig_build_current_names_map(wdata, res);
}
static void nbconfig_grouplist_add(UiEvent *event, void *userdata) {
wdata->valuechange = TRUE;
if(wdata->selected_group) {
+ char *input = ui_get(wdata->tab1_group_name);
+
cxFree(store->mp->allocator, wdata->selected_group->nodename);
- wdata->selected_group->nodename = cx_strdup_a(store->mp->allocator, cx_str(ui_get(wdata->tab1_group_name))).ptr;
+ wdata->selected_group->nodename = cx_strdup_a(store->mp->allocator, cx_str(input)).ptr;
UiListSelection sel = ui_list_getselection(wdata->tab1_groups);
nbconfig_update_lists(wdata); // TODO: update only single row
ui_list_setselection(wdata->tab1_groups, sel.rows[0]);
}
ui_listselection_free(sel);
+
+ Resource *dup = cxMapGet(wdata->current_names, input);
+ if(dup) {
+ fprintf(stderr, "Name %s already in use\n", input);
+ // TODO: show error in UI
+ }
}
wdata->valuechange = FALSE;
nbconfig_tab2_load_notebook(wdata, res);
wdata->selected_group = res;
+
+ nbconfig_build_current_names_map(wdata, res);
}
static void nbconfig_notebooklist_add(UiEvent *event, void *userdata) {
nbconfig_notebook_save(wdata);
}
+static void nbconfig_tab_view_changed(UiEvent *event, void *userdata) {
+ NotebookConfigDialog *wdata = event->window;
+
+ switch(event->intval) {
+ case 0: {
+ if(wdata->selected_group) {
+ nbconfig_build_current_names_map(wdata, wdata->selected_group);
+ }
+ break;
+ }
+ case 1: {
+ if(wdata->selected_notebook) {
+ nbconfig_build_current_names_map(wdata, wdata->selected_notebook);
+ }
+ break;
+ }
+ }
+}
+
void notebook_config_dialog(void) {
NoteStore *store = note_store_get();
// TODO: check store->root and show different dialog, when root is missing
wdata->notebooks = cxArrayListCreate(a, CX_STORE_POINTERS, 32);
wdata->notebook_parents = cxHashMapCreate(a, CX_STORE_POINTERS, 32);
+ wdata->current_names = cxHashMapCreate(a, CX_STORE_POINTERS, 16);
+
// fill data
Resource *group1 = NULL;
Resource *notebook1 = NULL;
// UI
ui_grid(obj, .margin = 10, .columnspacing = 10, .rowspacing = 10, .fill = TRUE) {
- ui_tabview(obj, .hfill = TRUE, .hexpand = TRUE, .vfill = TRUE, .vexpand = TRUE) {
+ ui_tabview(obj, .hfill = TRUE, .hexpand = TRUE, .vfill = TRUE, .vexpand = TRUE, .onchange = nbconfig_tab_view_changed) {
ui_tab(obj, "Groups") {
ui_hbox(obj, .margin = 10, .spacing = 10, .fill = TRUE) {
ui_vbox(obj, .fill = FALSE) {