]> uap-core.de Git - note.git/commitdiff
implement nbconfig_notebooklist_move_up/down
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 24 Jan 2026 14:59:03 +0000 (15:59 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 24 Jan 2026 14:59:03 +0000 (15:59 +0100)
application/nbconfig.c
application/nbconfig.h

index 2786593dfb22bbbce9bd7d45bc365871aeafcab9..8d11b80fc372965960bfd82649f812c43685f9f0 100644 (file)
@@ -402,12 +402,85 @@ static void nbconfig_notebooklist_delete(UiEvent *event, void *userdata) {
     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) {
index 414f35bf210beb0fef6aa96303acf0e7bde199d5..3b2c5e39c8b2e755a098f4c1531f3187dce462ad 100644 (file)
@@ -80,6 +80,9 @@ void nbconfig_update_lists(NotebookConfigDialog *wdata);
 
 void nbconfig_build_current_names_map(NotebookConfigDialog *wdata, Resource *res);
 
+Resource* nbconfig_notebooklist_find_prev(NotebookConfigDialog *wdata, Resource *res);
+Resource* nbconfig_notebooklist_find_next(NotebookConfigDialog *wdata, Resource *res);
+
 void nbconfig_notebook_save(NotebookConfigDialog *nbconfig);
 
 void notebook_config_dialog(void);