]> uap-core.de Git - note.git/commitdiff
implement nbconfig notebook list move up/down
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 27 Jul 2025 16:34:53 +0000 (18:34 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 27 Jul 2025 16:34:53 +0000 (18:34 +0200)
application/nbconfig.c

index 15c69bad446fe7220b2469af17a915bf56ec29ab..213dbbd0ecc369cb7c6995b4e80469d8c75b46bb 100644 (file)
@@ -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);
 }