}
}
+static void action_nnd_button(UiEvent *event, void *userdata) {
+ if(event->intval == 1) {
+ // add
+ } // 4: cancel
+ ui_close(event->obj);
+}
+
+static void* nnd_group_value(void *elm, int unused) {
+ Resource *res = elm;
+ return res->displayname ? res->displayname : res->nodename;
+}
+
void action_notebook_add(UiEvent *event, void *userdata) {
UiObject *obj = ui_dialog_window(event->obj,
.modal = UI_ON,
.title = "Add Notebook",
.lbutton1 = "Add",
.rbutton4 = "Cancel",
- .default_button = 1);
+ .default_button = 1,
+ .onclick = action_nnd_button);
ui_set_group(obj->ctx, NEWNOTEBOOK_DIALOG_STATE_SELECT_GROUP);
NewNotebookDialog *wdata = ui_malloc(obj->ctx, sizeof(NewNotebookDialog));
wdata->new_group = 0;
obj->window = wdata;
+ // Dialog UI
ui_grid(obj, .margin = 10, .columnspacing = 10, .rowspacing = 10, .def_vfill = TRUE, .fill = UI_ON) {
UIWIDGET gs_label = ui_rlabel(obj, .label = "Group");
- UIWIDGET gs_list = ui_combobox(obj, .varname = "notebook_groups", .hexpand = TRUE, .hfill = TRUE);
+ UIWIDGET gs_list = ui_combobox(obj, .list = wdata->groups, .getvalue = nnd_group_value, .hexpand = TRUE, .hfill = TRUE);
UIWIDGET gs_button = ui_togglebutton(obj, .label = "New Group", .value = wdata->gs_new_group, .onchange = action_nnd_new_group);
ui_newline(obj);
ui_widget_set_groups(obj->ctx, gs_label, (ui_enablefunc)ui_set_visible, NEWNOTEBOOK_DIALOG_STATE_SELECT_GROUP, -1);
ui_textfield(obj, .varname = "notebook_name", .colspan = 2, .hfill = TRUE);
}
+ // Dialog Data
+ NoteStore *notestore = note_store_get();
+ if(notestore->root) {
+ if(notestore->root->children) {
+ CxIterator i = cxListIterator(notestore->root->children);
+ cx_foreach(Resource *, group, i) {
+ ui_list_append(wdata->groups, group);
+ }
+ ui_list_update(wdata->groups);
+ } else {
+ // if no notebooks are available, show the textfield for new groups
+ ui_set(wdata->gs_new_group, 1);
+ ui_set_group(event->obj->ctx, NEWNOTEBOOK_DIALOG_STATE_NEW_GROUP);
+ ui_unset_group(event->obj->ctx, NEWNOTEBOOK_DIALOG_STATE_SELECT_GROUP);
+ }
+ }
+
+
ui_show(obj);
}