SRC += note.c
SRC += editor.c
SRC += attachment.c
+SRC += nbconfig.c
SRC += $(APP_PLATFORM_SRC)
OBJ = $(SRC:%.c=../build/application/%$(OBJ_EXT))
--- /dev/null
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2025 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "nbconfig.h"
+
+#include <cx/array_list.h>
+#include <cx/hash_map.h>
+
+#include "store.h"
+#include "notebook.h"
+
+static void* reslist_getvalue(void *data, int col) {
+ Resource *resource = data;
+ switch(col) {
+ case 0: {
+ return resource->displayname ? resource->displayname : resource->nodename;
+ }
+ case 1: {
+ //return note->lastmodified ? strdup(note->lastmodified) : NULL;
+ return NULL; // TODO
+ }
+ }
+
+ return NULL;
+}
+
+void nbconfig_update_lists(NotebookConfigDialog *wdata) {
+ ui_list_clear(wdata->tab1_groups);
+ ui_list_clear(wdata->tab2_groups);
+ CxIterator i = cxListIterator(wdata->groups);
+ cx_foreach(Resource *, res, i) {
+ ui_list_append(wdata->tab1_groups, res);
+ ui_list_append(wdata->tab2_groups, res);
+ }
+
+ ui_list_clear(wdata->tab2_notebooks);
+ i = cxListIterator(wdata->notebooks);
+ cx_foreach(Resource *, res, i) {
+ ui_list_append(wdata->tab2_notebooks, res);
+ }
+
+ i = cxListIterator(wdata->repositories);
+ //
+
+ ui_list_update(wdata->tab1_groups);
+ ui_list_update(wdata->tab1_repositories);
+ ui_list_update(wdata->tab2_groups);
+ ui_list_update(wdata->tab2_notebooks);
+ ui_list_update(wdata->tab2_repositories);
+}
+
+static void nbconfig_tab1_load_group(NotebookConfigDialog *wdata, Resource *res) {
+ Notebook *nb = res->notebook;
+
+ ui_set(wdata->tab1_group_name, res->nodename);
+}
+
+static void nbconfig_tab2_load_notebook(NotebookConfigDialog *wdata, Resource *res) {
+ Notebook *nb = res->notebook;
+ CxHashKey key = cx_hash_key(&res->resource_id, sizeof(res->resource_id));
+ Resource *parent = cxMapGet(wdata->notebook_parents, key);
+
+ ui_set(wdata->tab2_notebook_name, res->nodename);
+ if(parent) {
+ size_t index = cxListFind(wdata->groups, parent);
+ ui_list_setselection(wdata->tab2_groups, index);
+ }
+}
+
+static int nbconfig_list_activate_event(UiEvent *event, UiList *list, void **listelm) {
+ NotebookConfigDialog *wdata = event->window;
+ UiListSelection *sel = event->eventdata;
+ if(sel->count != 1) {
+ return 1; // should not happen
+ }
+
+ *listelm = ui_list_get(list, sel->rows[0]);
+ return 0;
+}
+
+static void nbconfig_grouplist_activate(UiEvent *event, void *userdata) {
+ NotebookConfigDialog *wdata = event->window;
+ Resource *res;
+ if(nbconfig_list_activate_event(event, wdata->tab1_groups, (void**)&res)) {
+ return;
+ }
+ nbconfig_tab1_load_group(wdata, res);
+ // TODO: check for empty new group and discard it in that case
+ wdata->new_group = NULL;
+}
+
+static void nbconfig_notebooklist_activate(UiEvent *event, void *userdata) {
+ NotebookConfigDialog *wdata = event->window;
+ Resource *res;
+ if(nbconfig_list_activate_event(event, wdata->tab2_notebooks, (void**)&res)) {
+ return;
+ }
+ nbconfig_tab2_load_notebook(wdata, res);
+}
+
+static void nbconfig_grouplist_add(UiEvent *event, void *userdata) {
+ NotebookConfigDialog *wdata = event->window;
+ NoteStore *store = note_store_get();
+
+ Resource *group = cxCalloc(store->mp->allocator, 1, sizeof(Resource));
+ group->parent_id = store->root->resource_id;
+ group->notebook = cxCalloc(store->mp->allocator, 1, sizeof(Notebook));
+
+ if(wdata->new_group) {
+ // TODO
+ }
+
+ wdata->new_group = group;
+
+ ui_set(wdata->tab1_group_name, "");
+ ui_list_setselection(wdata->tab1_repositories, 0);
+ ui_list_setselection(wdata->tab1_types, 0);
+}
+
+static void nbconfig_grouplist_delete(UiEvent *event, void *userdata) {
+
+}
+
+static void nbconfig_grouplist_move_up(UiEvent *event, void *userdata) {
+
+}
+
+static void nbconfig_grouplist_move_down(UiEvent *event, void *userdata) {
+
+}
+
+static void nbconfig_grouplist_name_changed(UiEvent *event, void *userdata) {
+ if(event->set) {
+ return;
+ }
+ NotebookConfigDialog *wdata = event->window;
+ NoteStore *store = note_store_get();
+
+ if(wdata->new_group) {
+ UiBool add_group = FALSE;
+ if(!wdata->new_group->nodename) {
+ add_group = TRUE;
+ } else {
+ cxFree(store->mp->allocator, wdata->new_group->nodename);
+ }
+
+ wdata->new_group->nodename = cx_strdup_a(store->mp->allocator, cx_str(ui_get(wdata->tab1_group_name))).ptr;
+
+ if(add_group) {
+ cxListAdd(wdata->groups, wdata->new_group);
+ }
+ nbconfig_update_lists(wdata); // TODO: update only single row
+ }
+}
+
+static void nbconfig_notebooklist_add(UiEvent *event, void *userdata) {
+
+}
+
+static void nbconfig_notebooklist_delete(UiEvent *event, void *userdata) {
+
+}
+
+static void nbconfig_notebooklist_move_up(UiEvent *event, void *userdata) {
+
+}
+
+static void nbconfig_notebooklist_move_down(UiEvent *event, void *userdata) {
+
+}
+
+
+void notebook_config_dialog(void) {
+ NoteStore *store = note_store_get();
+ // TODO: check store->root and show different dialog, when root is missing
+
+ UiObject *obj = ui_simple_window("Notebooks", NULL);
+ const CxAllocator *a = ui_allocator(obj->ctx);
+
+ NotebookConfigDialog *wdata = ui_malloc(obj->ctx, sizeof(NotebookConfigDialog));
+ memset(wdata, 0, sizeof(NotebookConfigDialog));
+ obj->window = wdata;
+
+ wdata->tab1_groups = ui_list_new(obj->ctx, NULL);
+ wdata->tab1_group_name = ui_string_new(obj->ctx, NULL);
+ wdata->tab1_types = ui_list_new(obj->ctx, NULL);
+ wdata->tab1_repositories = ui_list_new(obj->ctx, NULL);
+ wdata->tab2_notebooks = ui_list_new(obj->ctx, NULL);
+ wdata->tab2_groups = ui_list_new(obj->ctx, NULL);
+ wdata->tab2_notebook_name = ui_string_new(obj->ctx, NULL);
+ wdata->tab2_types = ui_list_new(obj->ctx, NULL);
+ wdata->tab2_repositories = ui_list_new(obj->ctx, NULL);
+
+ wdata->repositories = cxArrayListCreate(a, NULL, CX_STORE_POINTERS, 32);
+ wdata->groups = cxArrayListCreate(a, NULL, CX_STORE_POINTERS, 32);
+ wdata->notebooks = cxArrayListCreate(a, NULL, CX_STORE_POINTERS, 32);
+ wdata->notebook_parents = cxHashMapCreate(a, CX_STORE_POINTERS, 32);
+
+ // fill data
+ Resource *group1 = NULL;
+ Resource *notebook1 = NULL;
+ CxIterator i = cxListIterator(store->root->children);
+ cx_foreach(Resource *, res, i) {
+ cxListAdd(wdata->groups, res);
+ if(!group1) {
+ group1 = res;
+ }
+ CxIterator k = cxListIterator(res->children);
+ cx_foreach(Resource *, nb, k) {
+ cxListAdd(wdata->notebooks, nb);
+ CxHashKey key = cx_hash_key(&nb->resource_id, sizeof(nb->resource_id));
+ cxMapPut(wdata->notebook_parents, key, res);
+ if(!notebook1) {
+ notebook1 = nb;
+ }
+ }
+ }
+ nbconfig_update_lists(wdata);
+
+ ui_list_append(wdata->tab1_types, "Notes");
+ ui_list_append(wdata->tab1_types, "Feed");
+
+ ui_list_append(wdata->tab2_types, "Notes");
+ ui_list_append(wdata->tab2_types, "Feed");
+
+
+ // UI
+ ui_grid(obj, .margin = 10, .columnspacing = 10, .rowspacing = 10, .fill = UI_ON) {
+ ui_tabview(obj, .hfill = TRUE, .hexpand = TRUE, .vfill = TRUE, .vexpand = TRUE) {
+ ui_tab(obj, "Groups") {
+ ui_hbox(obj, .margin = 10, .spacing = 10, .fill = UI_ON) {
+ ui_vbox(obj, .fill = UI_OFF) {
+ ui_listview(obj, .list = wdata->tab1_groups, .getvalue = reslist_getvalue, .fill = UI_ON, .onactivate = nbconfig_grouplist_activate);
+ ui_hbox(obj, .fill = UI_OFF) {
+ ui_button(obj, .icon = UI_ICON_NEW_FOLDER, .onclick = nbconfig_grouplist_add);
+ ui_button(obj, .icon = UI_ICON_DELETE, .onclick = nbconfig_grouplist_delete);
+ ui_button(obj, .icon = UI_ICON_GO_UP, .onclick = nbconfig_grouplist_move_up);
+ ui_button(obj, .icon = UI_ICON_GO_DOWN, .onclick = nbconfig_grouplist_move_down);
+ }
+ }
+
+ ui_grid(obj, .columnspacing = 10, .rowspacing = 10, .fill = UI_ON, .def_vfill = TRUE) {
+ ui_rlabel(obj, .label = "Name");
+ ui_textfield(obj, .value = wdata->tab1_group_name, .onchange = nbconfig_grouplist_name_changed);
+ ui_newline(obj);
+
+ ui_rlabel(obj, .label = "Default Repository");
+ ui_combobox(obj, .list = wdata->tab1_repositories);
+ ui_newline(obj);
+
+ ui_rlabel(obj, .label = "Default Notebook Type");
+ ui_combobox(obj, .list = wdata->tab1_types);
+ ui_newline(obj);
+ }
+ }
+ }
+ ui_tab(obj, "Notebooks") {
+ ui_hbox(obj, .margin = 10, .spacing = 10, .fill = UI_ON) {
+ ui_vbox(obj, .fill = UI_OFF) {
+ ui_listview(obj, .list = wdata->tab2_notebooks, .getvalue = reslist_getvalue, .fill = UI_ON, .onactivate = nbconfig_notebooklist_activate);
+ ui_hbox(obj, .fill = UI_OFF) {
+ ui_button(obj, .icon = UI_ICON_NEW_FOLDER, .onclick = nbconfig_notebooklist_add);
+ ui_button(obj, .icon = UI_ICON_DELETE, .onclick = nbconfig_notebooklist_delete);
+ ui_button(obj, .icon = UI_ICON_GO_UP, .onclick = nbconfig_notebooklist_move_up);
+ ui_button(obj, .icon = UI_ICON_GO_DOWN, .onclick = nbconfig_notebooklist_move_down);
+ }
+ }
+
+ ui_grid(obj, .columnspacing = 10, .rowspacing = 10, .fill = UI_ON, .def_vfill = TRUE) {
+ ui_rlabel(obj, .label = "Group");
+ ui_combobox(obj, .list = wdata->tab2_groups, .getvalue = reslist_getvalue);
+ ui_newline(obj);
+
+ ui_rlabel(obj, .label = "Name");
+ ui_textfield(obj, .value = wdata->tab2_notebook_name);
+ ui_newline(obj);
+
+ ui_rlabel(obj, .label = "Repository");
+ ui_combobox(obj, .list = wdata->tab1_repositories);
+ ui_newline(obj);
+
+ ui_rlabel(obj, .label = "Type");
+ ui_combobox(obj, .list = wdata->tab2_types);
+ ui_newline(obj);
+ }
+ }
+ }
+ ui_tab(obj, "Repositories") {
+
+ }
+ }
+ }
+
+ ui_list_setselection(wdata->tab1_groups, 0);
+ ui_list_setselection(wdata->tab2_notebooks, 0);
+
+ if(group1) {
+ nbconfig_tab1_load_group(wdata, group1);
+ }
+ if(notebook1) {
+ nbconfig_tab2_load_notebook(wdata, notebook1);
+ }
+
+ ui_show(obj);
+}
--- /dev/null
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2025 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef NBCONFIG_H
+#define NBCONFIG_H
+
+#include <ui/ui.h>
+#include "application.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct NotebookConfigDialog {
+ MainWindow *parent;
+
+ CxList *repositories;
+ CxList *groups;
+ CxList *notebooks;
+ CxMap *notebook_parents;
+
+ UiList *tab1_groups;
+ UiString *tab1_group_name;
+ UiList *tab1_types;
+ UiList *tab1_repositories;
+ UiList *tab2_notebooks;
+ UiList *tab2_groups;
+ UiString *tab2_notebook_name;
+ UiList *tab2_types;
+ UiList *tab2_repositories;
+
+ Resource *new_group;
+ Resource *new_notebook;
+} NotebookConfigDialog;
+
+void nbconfig_update_lists(NotebookConfigDialog *wdata);
+
+void notebook_config_dialog(void);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* NBCONFIG_H */
+
#include "note.h"
#include "menu.h"
#include "attachment.h"
+#include "nbconfig.h"
#include <cx/array_list.h>
#include <cx/hash_map.h>
ui_show(obj);
}
-static void* reslist_getvalue(void *data, int col) {
- Resource *resource = data;
- switch(col) {
- case 0: {
- return resource->displayname ? resource->displayname : resource->nodename;
- }
- case 1: {
- //return note->lastmodified ? strdup(note->lastmodified) : NULL;
- return NULL; // TODO
- }
- }
-
- return NULL;
-}
-
-void nbconfig_update_lists(NotebookConfigDialog *wdata) {
- ui_list_clear(wdata->tab1_groups);
- ui_list_clear(wdata->tab2_groups);
- CxIterator i = cxListIterator(wdata->groups);
- cx_foreach(Resource *, res, i) {
- ui_list_append(wdata->tab1_groups, res);
- ui_list_append(wdata->tab2_groups, res);
- }
-
- ui_list_clear(wdata->tab2_notebooks);
- i = cxListIterator(wdata->notebooks);
- cx_foreach(Resource *, res, i) {
- ui_list_append(wdata->tab2_notebooks, res);
- }
-
- i = cxListIterator(wdata->repositories);
- //
-
- ui_list_update(wdata->tab1_groups);
- ui_list_update(wdata->tab1_repositories);
- ui_list_update(wdata->tab2_groups);
- ui_list_update(wdata->tab2_notebooks);
- ui_list_update(wdata->tab2_repositories);
-}
-
-static void nbconfig_tab1_load_group(NotebookConfigDialog *wdata, Resource *res) {
- Notebook *nb = res->notebook;
-
- ui_set(wdata->tab1_group_name, res->nodename);
-}
-
-static void nbconfig_tab2_load_notebook(NotebookConfigDialog *wdata, Resource *res) {
- Notebook *nb = res->notebook;
- CxHashKey key = cx_hash_key(&res->resource_id, sizeof(res->resource_id));
- Resource *parent = cxMapGet(wdata->notebook_parents, key);
-
- ui_set(wdata->tab2_notebook_name, res->nodename);
- if(parent) {
- size_t index = cxListFind(wdata->groups, parent);
- ui_list_setselection(wdata->tab2_groups, index);
- }
-}
-
-static int nbconfig_list_activate_event(UiEvent *event, UiList *list, void **listelm) {
- NotebookConfigDialog *wdata = event->window;
- UiListSelection *sel = event->eventdata;
- if(sel->count != 1) {
- return 1; // should not happen
- }
-
- *listelm = ui_list_get(list, sel->rows[0]);
- return 0;
-}
-
-static void nbconfig_grouplist_activate(UiEvent *event, void *userdata) {
- NotebookConfigDialog *wdata = event->window;
- Resource *res;
- if(nbconfig_list_activate_event(event, wdata->tab1_groups, (void**)&res)) {
- return;
- }
- nbconfig_tab1_load_group(wdata, res);
- // TODO: check for empty new group and discard it in that case
- wdata->new_group = NULL;
-}
-
-static void nbconfig_notebooklist_activate(UiEvent *event, void *userdata) {
- NotebookConfigDialog *wdata = event->window;
- Resource *res;
- if(nbconfig_list_activate_event(event, wdata->tab2_notebooks, (void**)&res)) {
- return;
- }
- nbconfig_tab2_load_notebook(wdata, res);
-}
-
-static void nbconfig_grouplist_add(UiEvent *event, void *userdata) {
- NotebookConfigDialog *wdata = event->window;
- NoteStore *store = note_store_get();
-
- Resource *group = cxCalloc(store->mp->allocator, 1, sizeof(Resource));
- group->parent_id = store->root->resource_id;
- group->notebook = cxCalloc(store->mp->allocator, 1, sizeof(Notebook));
-
- if(wdata->new_group) {
- // TODO
- }
-
- wdata->new_group = group;
-
- ui_set(wdata->tab1_group_name, "");
- ui_list_setselection(wdata->tab1_repositories, 0);
- ui_list_setselection(wdata->tab1_types, 0);
-}
-
-static void nbconfig_grouplist_delete(UiEvent *event, void *userdata) {
-
-}
-
-static void nbconfig_grouplist_move_up(UiEvent *event, void *userdata) {
-
-}
-
-static void nbconfig_grouplist_move_down(UiEvent *event, void *userdata) {
-
-}
-
-static void nbconfig_grouplist_name_changed(UiEvent *event, void *userdata) {
- if(event->set) {
- return;
- }
- NotebookConfigDialog *wdata = event->window;
- NoteStore *store = note_store_get();
-
- if(wdata->new_group) {
- UiBool add_group = FALSE;
- if(!wdata->new_group->nodename) {
- add_group = TRUE;
- } else {
- cxFree(store->mp->allocator, wdata->new_group->nodename);
- }
-
- wdata->new_group->nodename = cx_strdup_a(store->mp->allocator, cx_str(ui_get(wdata->tab1_group_name))).ptr;
-
- if(add_group) {
- cxListAdd(wdata->groups, wdata->new_group);
- }
- nbconfig_update_lists(wdata); // TODO: update only single row
- }
-}
-
-static void nbconfig_notebooklist_add(UiEvent *event, void *userdata) {
-
-}
-
-static void nbconfig_notebooklist_delete(UiEvent *event, void *userdata) {
-
-}
-
-static void nbconfig_notebooklist_move_up(UiEvent *event, void *userdata) {
-
-}
-
-static void nbconfig_notebooklist_move_down(UiEvent *event, void *userdata) {
-
-}
-
-
void action_notebook_config(UiEvent *event, void *userdata) {
- NoteStore *store = note_store_get();
- // TODO: check store->root and show different dialog, when root is missing
-
- UiObject *obj = ui_simple_window("Notebooks", NULL);
- const CxAllocator *a = ui_allocator(obj->ctx);
-
- NotebookConfigDialog *wdata = ui_malloc(obj->ctx, sizeof(NotebookConfigDialog));
- memset(wdata, 0, sizeof(NotebookConfigDialog));
- obj->window = wdata;
-
- wdata->tab1_groups = ui_list_new(obj->ctx, NULL);
- wdata->tab1_group_name = ui_string_new(obj->ctx, NULL);
- wdata->tab1_types = ui_list_new(obj->ctx, NULL);
- wdata->tab1_repositories = ui_list_new(obj->ctx, NULL);
- wdata->tab2_notebooks = ui_list_new(obj->ctx, NULL);
- wdata->tab2_groups = ui_list_new(obj->ctx, NULL);
- wdata->tab2_notebook_name = ui_string_new(obj->ctx, NULL);
- wdata->tab2_types = ui_list_new(obj->ctx, NULL);
- wdata->tab2_repositories = ui_list_new(obj->ctx, NULL);
-
- wdata->repositories = cxArrayListCreate(a, NULL, CX_STORE_POINTERS, 32);
- wdata->groups = cxArrayListCreate(a, NULL, CX_STORE_POINTERS, 32);
- wdata->notebooks = cxArrayListCreate(a, NULL, CX_STORE_POINTERS, 32);
- wdata->notebook_parents = cxHashMapCreate(a, CX_STORE_POINTERS, 32);
-
- // fill data
- Resource *group1 = NULL;
- Resource *notebook1 = NULL;
- CxIterator i = cxListIterator(store->root->children);
- cx_foreach(Resource *, res, i) {
- cxListAdd(wdata->groups, res);
- if(!group1) {
- group1 = res;
- }
- CxIterator k = cxListIterator(res->children);
- cx_foreach(Resource *, nb, k) {
- cxListAdd(wdata->notebooks, nb);
- CxHashKey key = cx_hash_key(&nb->resource_id, sizeof(nb->resource_id));
- cxMapPut(wdata->notebook_parents, key, res);
- if(!notebook1) {
- notebook1 = nb;
- }
- }
- }
- nbconfig_update_lists(wdata);
-
- ui_list_append(wdata->tab1_types, "Notes");
- ui_list_append(wdata->tab1_types, "Feed");
-
- ui_list_append(wdata->tab2_types, "Notes");
- ui_list_append(wdata->tab2_types, "Feed");
-
-
- // UI
- ui_grid(obj, .margin = 10, .columnspacing = 10, .rowspacing = 10, .fill = UI_ON) {
- ui_tabview(obj, .hfill = TRUE, .hexpand = TRUE, .vfill = TRUE, .vexpand = TRUE) {
- ui_tab(obj, "Groups") {
- ui_hbox(obj, .margin = 10, .spacing = 10, .fill = UI_ON) {
- ui_vbox(obj, .fill = UI_OFF) {
- ui_listview(obj, .list = wdata->tab1_groups, .getvalue = reslist_getvalue, .fill = UI_ON, .onactivate = nbconfig_grouplist_activate);
- ui_hbox(obj, .fill = UI_OFF) {
- ui_button(obj, .icon = UI_ICON_NEW_FOLDER, .onclick = nbconfig_grouplist_add);
- ui_button(obj, .icon = UI_ICON_DELETE, .onclick = nbconfig_grouplist_delete);
- ui_button(obj, .icon = UI_ICON_GO_UP, .onclick = nbconfig_grouplist_move_up);
- ui_button(obj, .icon = UI_ICON_GO_DOWN, .onclick = nbconfig_grouplist_move_down);
- }
- }
-
- ui_grid(obj, .columnspacing = 10, .rowspacing = 10, .fill = UI_ON, .def_vfill = TRUE) {
- ui_rlabel(obj, .label = "Name");
- ui_textfield(obj, .value = wdata->tab1_group_name, .onchange = nbconfig_grouplist_name_changed);
- ui_newline(obj);
-
- ui_rlabel(obj, .label = "Default Repository");
- ui_combobox(obj, .list = wdata->tab1_repositories);
- ui_newline(obj);
-
- ui_rlabel(obj, .label = "Default Notebook Type");
- ui_combobox(obj, .list = wdata->tab1_types);
- ui_newline(obj);
- }
- }
- }
- ui_tab(obj, "Notebooks") {
- ui_hbox(obj, .margin = 10, .spacing = 10, .fill = UI_ON) {
- ui_vbox(obj, .fill = UI_OFF) {
- ui_listview(obj, .list = wdata->tab2_notebooks, .getvalue = reslist_getvalue, .fill = UI_ON, .onactivate = nbconfig_notebooklist_activate);
- ui_hbox(obj, .fill = UI_OFF) {
- ui_button(obj, .icon = UI_ICON_NEW_FOLDER, .onclick = nbconfig_notebooklist_add);
- ui_button(obj, .icon = UI_ICON_DELETE, .onclick = nbconfig_notebooklist_delete);
- ui_button(obj, .icon = UI_ICON_GO_UP, .onclick = nbconfig_notebooklist_move_up);
- ui_button(obj, .icon = UI_ICON_GO_DOWN, .onclick = nbconfig_notebooklist_move_down);
- }
- }
-
- ui_grid(obj, .columnspacing = 10, .rowspacing = 10, .fill = UI_ON, .def_vfill = TRUE) {
- ui_rlabel(obj, .label = "Group");
- ui_combobox(obj, .list = wdata->tab2_groups, .getvalue = reslist_getvalue);
- ui_newline(obj);
-
- ui_rlabel(obj, .label = "Name");
- ui_textfield(obj, .value = wdata->tab2_notebook_name);
- ui_newline(obj);
-
- ui_rlabel(obj, .label = "Repository");
- ui_combobox(obj, .list = wdata->tab1_repositories);
- ui_newline(obj);
-
- ui_rlabel(obj, .label = "Type");
- ui_combobox(obj, .list = wdata->tab2_types);
- ui_newline(obj);
- }
- }
- }
- ui_tab(obj, "Repositories") {
-
- }
- }
- }
-
- ui_list_setselection(wdata->tab1_groups, 0);
- ui_list_setselection(wdata->tab2_notebooks, 0);
-
- if(group1) {
- nbconfig_tab1_load_group(wdata, group1);
- }
- if(notebook1) {
- nbconfig_tab2_load_notebook(wdata, notebook1);
- }
-
- ui_show(obj);
+ notebook_config_dialog();
}
void action_notebook_selected(UiEvent *event, void *userdata) {
UiString *notebook_name;
} NewNotebookDialog;
-typedef struct NotebookConfigDialog {
- MainWindow *parent;
-
- CxList *repositories;
- CxList *groups;
- CxList *notebooks;
- CxMap *notebook_parents;
-
- UiList *tab1_groups;
- UiString *tab1_group_name;
- UiList *tab1_types;
- UiList *tab1_repositories;
- UiList *tab2_notebooks;
- UiList *tab2_groups;
- UiString *tab2_notebook_name;
- UiList *tab2_types;
- UiList *tab2_repositories;
-
- Resource *new_group;
- Resource *new_notebook;
-} NotebookConfigDialog;
void window_create();
void* window_notelist_getvalue(void *data, int col);
-void nbconfig_update_lists(NotebookConfigDialog *wdata);
-
void action_notebook_add(UiEvent *event, void *userdata);
void action_notebook_config(UiEvent *event, void *userdata);