ui_listselection_free(sel);
}
+Resource* nbconfig_notebooklist_find_prev(NotebookConfigDialog *wdata, Resource *res) {
+ Resource *prev = NULL;
+ CxIterator i = cxListIterator(wdata->tab1_notebooks->data);
+ cx_foreach(Resource *, nb, i) {
+ if(res == nb && res->parent_id == prev->parent_id) {
+ return prev;
+ }
+ prev = nb;
+ }
+ return NULL;
+}
+
+Resource* nbconfig_notebooklist_find_next(NotebookConfigDialog *wdata, Resource *res) {
+ CxIterator i = cxListIterator(wdata->tab1_notebooks->data);
+ int res_found = 0;
+ cx_foreach(Resource *, nb, i) {
+ if(res == nb) {
+ res_found = 1;
+ } else if(res_found) {
+ if(nb->parent_id == res->parent_id) {
+ return nb;
+ }
+ }
+ }
+ return NULL;
+}
+
+static void swap_result(UiEvent *event, int error, void *userdata) {
+ if(error == 0) {
+ note_store_groups_updated();
+ } else {
+ fprintf(stderr, "Error: cannot wrap notebook positions\n");
+ }
+}
+
static void nbconfig_notebooklist_move_up(UiEvent *event, void *userdata) {
+ NotebookConfigDialog *wdata = event->window;
+ CxList *nblist = wdata->tab1_notebooks->data;
+ if(!wdata->selected_notebook) {
+ return;
+ }
+
+ Resource *prev = nbconfig_notebooklist_find_prev(wdata, wdata->selected_notebook);
+ if(prev) {
+ note_store_notebook_swap_position_async(wdata->obj, prev->notebook, wdata->selected_notebook->notebook, swap_result, wdata);
+
+ // update UI
+ size_t prev_index = cxListFind(nblist, prev);
+ size_t res_index = cxListFind(nblist, wdata->selected_notebook);
+ cxListSwap(nblist, prev_index, res_index);
+ ui_list_update(wdata->tab1_notebooks);
+ wdata->valuechange = TRUE;
+ ui_list_setselection(wdata->tab1_notebooks, prev_index);
+ wdata->valuechange = FALSE;
+ }
}
static void nbconfig_notebooklist_move_down(UiEvent *event, void *userdata) {
+ NotebookConfigDialog *wdata = event->window;
+ CxList *nblist = wdata->tab1_notebooks->data;
+ if(!wdata->selected_notebook) {
+ return;
+ }
+
+ Resource *next = nbconfig_notebooklist_find_next(wdata, wdata->selected_notebook);
+ if(next) {
+ note_store_notebook_swap_position_async(wdata->obj, next->notebook, wdata->selected_notebook->notebook, swap_result, wdata);
+
+ // update UI
+ size_t next_index = cxListFind(nblist, next);
+ size_t res_index = cxListFind(nblist, wdata->selected_notebook);
+ cxListSwap(nblist, next_index, res_index);
+ ui_list_update(wdata->tab1_notebooks);
+ wdata->valuechange = TRUE;
+ ui_list_setselection(wdata->tab1_notebooks, next_index);
+ wdata->valuechange = FALSE;
+ }
}
static void nbconfig_notebooklist_name_changed(UiEvent *event, void *userdata) {