From 0876d65f2194b685cd5d8c0f8428ba5c40f75aa8 Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Sun, 27 Jul 2025 18:34:53 +0200 Subject: [PATCH] implement nbconfig notebook list move up/down --- application/nbconfig.c | 47 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/application/nbconfig.c b/application/nbconfig.c index 15c69ba..213dbbd 100644 --- a/application/nbconfig.c +++ b/application/nbconfig.c @@ -234,12 +234,59 @@ static void nbconfig_notebooklist_delete(UiEvent *event, void *userdata) { ui_listselection_free(sel); } +static UiBool notebooklist_move_inprogress = FALSE; +static int notebooklist_move_pos0 = 0; +static int notebooklist_move_pos1 = 0; + +static void nbconfig_notebooklist_move_result(UiEvent *event, int error, void *userdata) { + notebooklist_move_inprogress = FALSE; + if(!error) { + NotebookConfigDialog *wdata = event->window; + cxListSwap(wdata->notebooks, notebooklist_move_pos0, notebooklist_move_pos1); + nbconfig_update_lists(wdata); + } else { + printf("nbconfig_notebooklist_move_up_result: error %d\n", error); + } +} + + static void nbconfig_notebooklist_move_up(UiEvent *event, void *userdata) { + if(notebooklist_move_inprogress) { + return; + } + NotebookConfigDialog *wdata = event->window; + UiListSelection sel = ui_list_getselection(wdata->tab2_notebooks); + if(sel.count == 1 && sel.rows[0] > 0) { + int row = sel.rows[0]; + notebooklist_move_pos0 = row; + notebooklist_move_pos1 = row-1; + Resource *r0 = cxListAt(wdata->notebooks, notebooklist_move_pos0); + Resource *r1 = cxListAt(wdata->notebooks, notebooklist_move_pos1); + note_store_notebook_swap_position_async(event->obj, r0->notebook, r1->notebook, nbconfig_notebooklist_move_result, NULL); + notebooklist_move_inprogress = TRUE; + } + ui_listselection_free(sel); } static void nbconfig_notebooklist_move_down(UiEvent *event, void *userdata) { + if(notebooklist_move_inprogress) { + return; + } + NotebookConfigDialog *wdata = event->window; + UiListSelection sel = ui_list_getselection(wdata->tab2_notebooks); + size_t sz = cxListSize(wdata->notebooks); + if(sel.count == 1 && sel.rows[0]+1 < sz) { + int row = sel.rows[0]; + notebooklist_move_pos0 = row; + notebooklist_move_pos1 = row+1; + Resource *r0 = cxListAt(wdata->notebooks, notebooklist_move_pos0); + Resource *r1 = cxListAt(wdata->notebooks, notebooklist_move_pos1); + note_store_notebook_swap_position_async(event->obj, r0->notebook, r1->notebook, nbconfig_notebooklist_move_result, NULL); + notebooklist_move_inprogress = TRUE; + } + ui_listselection_free(sel); } -- 2.47.3