static void nbconfig_close(UiEvent *event, void *userdata) {
NotebookConfigDialog *wdata = event->window;
- //nbconfig_group_save(wdata);
- //nbconfig_notebook_save(wdata);
+ nbconfig_notebook_save(wdata);
}
static int nbconfig_list_activate_event(UiEvent *event, UiList *list, void **listelm) {
res->parent_id = parent->resource_id;
}
-
note_store_save_notebook_async(application_global_obj(), res, prev_parent_id, notebook_saved, res);
}
static void nbconfig_load_notebook(NotebookConfigDialog *wdata, Resource *res) {
Notebook *nb = res->notebook;
+ wdata->valuechange = TRUE;
ui_set(wdata->tab1_notebook_name, res->nodename);
if(res->parent_id != wdata->root_resource_id) {
UiContext *ctx = wdata->obj->ctx;
ui_free(ctx, wdata->selected_notebook_name);
wdata->selected_notebook_name = ui_strdup(ctx, res->nodename);
+
+ wdata->valuechange = FALSE;
}
static void nbconfig_notebooklist_onselect(UiEvent *event, void *userdata) {
nbconfig_build_current_names_map(wdata, res);
}
+static int get_notebook_insertpos(NotebookConfigDialog *wdata, int64_t parent_id) {
+ CxList *nblist = wdata->tab1_notebooks->data;
+ size_t insert_pos = 0;
+ int group_index = -1;
+ CxIterator i = cxListIterator(nblist);
+ cx_foreach(Resource *, res, i) {
+ if(group_index >= 0) {
+ if(res->parent_id != parent_id) {
+ break;
+ }
+ } else if(res->parent_id == parent_id) {
+ group_index = (int)i.index;
+ }
+ insert_pos = i.index;
+ }
+ insert_pos++;
+ return insert_pos;
+}
+
+static void nbconfig_group_onselect(UiEvent *event, void *userdata) {
+ NotebookConfigDialog *wdata = event->window;
+ if(wdata->valuechange || !wdata->selected_notebook) {
+ return;
+ }
+
+ Resource *newparent = ui_list_get(wdata->tab1_groups, event->intval);
+
+ CxList *nblist = wdata->tab1_notebooks->data;
+ size_t res_index = cxListFind(nblist, wdata->selected_notebook);
+
+ cxListRemove(nblist, res_index);
+ int new_insert_pos = get_notebook_insertpos(wdata, newparent->resource_id);
+ 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;
+}
+
static void nbconfig_tab_view_changed(UiEvent *event, void *userdata) {
}
NoteStore *store = note_store_get();
UiContext *ctx = wdata->obj->ctx;
+ nbconfig_notebook_save(wdata);
+
Resource *notebook = cxCalloc(store->mp->allocator, 1, sizeof(Resource));
notebook->notebook = cxCalloc(store->mp->allocator, 1, sizeof(Notebook));
notebook->parent_id = parent_id;
} else {
cxListAdd(wdata->notebooks, notebook);
CxList *nblist = wdata->tab1_notebooks->data;
- size_t insert_pos = 0;
- int group_index = -1;
- CxIterator i = cxListIterator(nblist);
- cx_foreach(Resource *, res, i) {
- if(group_index >= 0) {
- if(res->parent_id != parent_id) {
- break;
- }
- } else if(res->parent_id == parent_id) {
- group_index = (int)i.index;
- }
- insert_pos = i.index;
- }
- insert_pos++;
+ size_t insert_pos = get_notebook_insertpos(wdata, parent_id);
cxListInsert(nblist, insert_pos, notebook);
ui_list_update(wdata->tab1_notebooks);
- ui_list_update_row(wdata->tab1_groups, group_index);
+
+ int grouplist_index = -1;
+ CxIterator i = cxListIterator(wdata->groups);
+ cx_foreach(Resource *, res, i) {
+ if(res->resource_id == parent_id) {
+ grouplist_index = (int)i.index;
+ }
+ }
wdata->valuechange = TRUE;
+ ui_list_setselection(wdata->tab1_groups, grouplist_index);
ui_list_setselection(wdata->tab1_notebooks, insert_pos);
wdata->valuechange = FALSE;
}
static void nbconfig_notebooklist_add_notebook(UiEvent *event, void *userdata) {
NotebookConfigDialog *wdata = event->window;
- Resource *parent = cxListAt(wdata->groups, 0);
- if(!parent) {
- fprintf(stderr, "Error: cannot create a notebook without a group\n");
- return;
+ int64_t parent_resource_id;
+ if(wdata->selected_notebook) {
+ if(wdata->selected_notebook->parent_id == wdata->root_resource_id) {
+ // The currently selected notebook is a group
+ // A new notebook should be created in this group
+ parent_resource_id = wdata->selected_notebook->resource_id;
+ } else {
+ // Create a new notebook within the same parent as the
+ // currently selected notebook
+ parent_resource_id = wdata->selected_notebook->parent_id;
+ }
+ } else {
+ // no selected notebook, use the first group as parent
+ Resource *parent = cxListAt(wdata->groups, 0);
+ if(!parent) {
+ fprintf(stderr, "Error: cannot create a notebook without a group\n");
+ return;
+ }
+ parent_resource_id = parent->resource_id;
}
- add_notebook(wdata, parent->resource_id, "New");
+ add_notebook(wdata, parent_resource_id, "New");
}
static void notebook_count_children_result(UiEvent *event, int64_t num, int error, void *userdata) {
ui_grid(obj, .columnspacing = 10, .rowspacing = 10, .fill = TRUE, .def_vfill = TRUE) {
ui_rlabel(obj, .label = "Group");
- ui_dropdown(obj, .list = wdata->tab1_groups, .getvalue2 = reslist_getvalue, .getvalue2data = wdata);
+ ui_dropdown(obj, .list = wdata->tab1_groups, .getvalue2 = reslist_getvalue, .getvalue2data = wdata, .onactivate = nbconfig_group_onselect);
ui_newline(obj);
ui_rlabel(obj, .label = "Name");