]> uap-core.de Git - note.git/commitdiff
implement nbconfig grouplist move up/down
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Mon, 28 Jul 2025 19:17:56 +0000 (21:17 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Mon, 28 Jul 2025 19:17:56 +0000 (21:17 +0200)
application/nbconfig.c

index 213dbbd0ecc369cb7c6995b4e80469d8c75b46bb..62f5139ce7f2d6500f42ee8cd2d6553646fccaef 100644 (file)
 #include "store.h"
 #include "notebook.h"
 
+static UiBool notebooklist_move_inprogress = FALSE;
+static int notebooklist_move_pos0 = 0;
+static int notebooklist_move_pos1 = 0;
+
 static void* reslist_getvalue(void *data, int col) {
     Resource *resource = data;
     switch(col) {
@@ -146,12 +150,53 @@ static void nbconfig_grouplist_delete(UiEvent *event, void *userdata) {
     
 }
 
+static void nbconfig_grouplist_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_grouplist_move_up(UiEvent *event, void *userdata) {
+    if(notebooklist_move_inprogress) {
+        return;
+    }
     
+    NotebookConfigDialog *wdata = event->window;
+    UiListSelection sel = ui_list_getselection(wdata->tab1_groups);
+    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->groups, notebooklist_move_pos0);
+        Resource *r1 = cxListAt(wdata->groups, notebooklist_move_pos1);
+        note_store_notebook_swap_position_async(event->obj, r0->notebook, r1->notebook, nbconfig_grouplist_move_result, NULL);
+        notebooklist_move_inprogress = TRUE;
+    }
+    ui_listselection_free(sel);
 }
 
 static void nbconfig_grouplist_move_down(UiEvent *event, void *userdata) {
+    if(notebooklist_move_inprogress) {
+        return;
+    }
     
+    NotebookConfigDialog *wdata = event->window;
+    UiListSelection sel = ui_list_getselection(wdata->tab1_groups);
+    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->groups, notebooklist_move_pos0);
+        Resource *r1 = cxListAt(wdata->groups, notebooklist_move_pos1);
+        note_store_notebook_swap_position_async(event->obj, r0->notebook, r1->notebook, nbconfig_grouplist_move_result, NULL);
+        notebooklist_move_inprogress = TRUE;
+    }
+    ui_listselection_free(sel);
 }
 
 static void nbconfig_grouplist_name_changed(UiEvent *event, void *userdata) {
@@ -234,10 +279,6 @@ 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) {