]> uap-core.de Git - note.git/commitdiff
implement moving notebooks to other groups main
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Thu, 22 Jan 2026 21:06:41 +0000 (22:06 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Thu, 22 Jan 2026 21:06:41 +0000 (22:06 +0100)
application/nbconfig.c
application/nbconfig.h

index d5c77c0ff4bf9ae7bc6f4eee0615061253dbc089..03ab7f209eaf0a58572403a9051bf6e27209e516 100644 (file)
@@ -134,8 +134,7 @@ void nbconfig_build_current_names_map(NotebookConfigDialog *wdata, Resource *res
 
 static void nbconfig_close(UiEvent *event, void *userdata) {
     NotebookConfigDialog *wdata = event->window;
 
 static void nbconfig_close(UiEvent *event, void *userdata) {
     NotebookConfigDialog *wdata = event->window;
-    //nbconfig_group_save(wdata);
-    //nbconfig_notebook_save(wdata);
+    nbconfig_notebook_save(wdata);
 }
 
 static int nbconfig_list_activate_event(UiEvent *event, UiList *list, void **listelm) {
 }
 
 static int nbconfig_list_activate_event(UiEvent *event, UiList *list, void **listelm) {
@@ -192,12 +191,12 @@ void nbconfig_notebook_save(NotebookConfigDialog *nbconfig) {
         res->parent_id = parent->resource_id;
     }
     
         res->parent_id = parent->resource_id;
     }
     
-    
     note_store_save_notebook_async(application_global_obj(), res, prev_parent_id, notebook_saved, res);
 }
 
 static void nbconfig_load_notebook(NotebookConfigDialog *wdata, Resource *res) {
     Notebook *nb = res->notebook;
     note_store_save_notebook_async(application_global_obj(), res, prev_parent_id, notebook_saved, res);
 }
 
 static void nbconfig_load_notebook(NotebookConfigDialog *wdata, Resource *res) {
     Notebook *nb = res->notebook;
+    wdata->valuechange = TRUE;
     
     ui_set(wdata->tab1_notebook_name, res->nodename);
     if(res->parent_id != wdata->root_resource_id) {
     
     ui_set(wdata->tab1_notebook_name, res->nodename);
     if(res->parent_id != wdata->root_resource_id) {
@@ -217,6 +216,8 @@ static void nbconfig_load_notebook(NotebookConfigDialog *wdata, Resource *res) {
     UiContext *ctx = wdata->obj->ctx;
     ui_free(ctx, wdata->selected_notebook_name);
     wdata->selected_notebook_name = ui_strdup(ctx, res->nodename);
     UiContext *ctx = wdata->obj->ctx;
     ui_free(ctx, wdata->selected_notebook_name);
     wdata->selected_notebook_name = ui_strdup(ctx, res->nodename);
+    
+    wdata->valuechange = FALSE;
 }
 
 static void nbconfig_notebooklist_onselect(UiEvent *event, void *userdata) {
 }
 
 static void nbconfig_notebooklist_onselect(UiEvent *event, void *userdata) {
@@ -237,6 +238,46 @@ static void nbconfig_notebooklist_onselect(UiEvent *event, void *userdata) {
     nbconfig_build_current_names_map(wdata, res);
 }
 
     nbconfig_build_current_names_map(wdata, res);
 }
 
+static int get_notebook_insertpos(NotebookConfigDialog *wdata, int64_t parent_id) {
+    CxList *nblist = wdata->tab1_notebooks->data;
+    size_t insert_pos = 0;
+    int group_index = -1;
+    CxIterator i = cxListIterator(nblist);
+    cx_foreach(Resource *, res, i) {
+        if(group_index >= 0) {
+            if(res->parent_id != parent_id) {
+                break;
+            }
+        } else if(res->parent_id == parent_id) {
+            group_index = (int)i.index;
+        }
+        insert_pos = i.index;
+    }
+    insert_pos++;
+    return insert_pos;
+}
+
+static void nbconfig_group_onselect(UiEvent *event, void *userdata) {
+    NotebookConfigDialog *wdata = event->window;
+    if(wdata->valuechange || !wdata->selected_notebook) {
+        return;
+    }
+    
+    Resource *newparent = ui_list_get(wdata->tab1_groups, event->intval);
+    
+    CxList *nblist = wdata->tab1_notebooks->data;
+    size_t res_index = cxListFind(nblist, wdata->selected_notebook);
+    
+    cxListRemove(nblist, res_index);
+    int new_insert_pos = get_notebook_insertpos(wdata, newparent->resource_id);
+    cxListInsert(nblist, new_insert_pos, wdata->selected_notebook);
+    ui_list_update(wdata->tab1_notebooks);
+    
+    wdata->valuechange = TRUE;
+    ui_list_setselection(wdata->tab1_notebooks, new_insert_pos);
+    wdata->valuechange = FALSE;
+}
+
 static void nbconfig_tab_view_changed(UiEvent *event, void *userdata) {
     
 }
 static void nbconfig_tab_view_changed(UiEvent *event, void *userdata) {
     
 }
@@ -245,6 +286,8 @@ static void add_notebook(NotebookConfigDialog *wdata, int64_t parent_id, const c
     NoteStore *store = note_store_get();
     UiContext *ctx = wdata->obj->ctx;
     
     NoteStore *store = note_store_get();
     UiContext *ctx = wdata->obj->ctx;
     
+    nbconfig_notebook_save(wdata);
+    
     Resource *notebook = cxCalloc(store->mp->allocator, 1, sizeof(Resource));
     notebook->notebook = cxCalloc(store->mp->allocator, 1, sizeof(Notebook));
     notebook->parent_id = parent_id;
     Resource *notebook = cxCalloc(store->mp->allocator, 1, sizeof(Resource));
     notebook->notebook = cxCalloc(store->mp->allocator, 1, sizeof(Notebook));
     notebook->parent_id = parent_id;
@@ -270,26 +313,21 @@ static void add_notebook(NotebookConfigDialog *wdata, int64_t parent_id, const c
     } else {
         cxListAdd(wdata->notebooks, notebook);
         CxList *nblist = wdata->tab1_notebooks->data;
     } else {
         cxListAdd(wdata->notebooks, notebook);
         CxList *nblist = wdata->tab1_notebooks->data;
-        size_t insert_pos = 0;
-        int group_index = -1;
-        CxIterator i = cxListIterator(nblist);
-        cx_foreach(Resource *, res, i) {
-            if(group_index >= 0) {
-                if(res->parent_id != parent_id) {
-                    break;
-                }
-            } else if(res->parent_id == parent_id) {
-                group_index = (int)i.index;
-            }
-            insert_pos = i.index;
-        }
-        insert_pos++;
+        size_t insert_pos = get_notebook_insertpos(wdata, parent_id);
         
         cxListInsert(nblist, insert_pos, notebook);
         ui_list_update(wdata->tab1_notebooks);
         
         cxListInsert(nblist, insert_pos, notebook);
         ui_list_update(wdata->tab1_notebooks);
-        ui_list_update_row(wdata->tab1_groups, group_index);
+        
+        int grouplist_index = -1;
+        CxIterator i = cxListIterator(wdata->groups);
+        cx_foreach(Resource *, res, i) {
+            if(res->resource_id == parent_id) {
+                grouplist_index = (int)i.index;
+            }
+        }
         
         wdata->valuechange = TRUE;
         
         wdata->valuechange = TRUE;
+        ui_list_setselection(wdata->tab1_groups, grouplist_index);
         ui_list_setselection(wdata->tab1_notebooks, insert_pos);
         wdata->valuechange = FALSE;
     }
         ui_list_setselection(wdata->tab1_notebooks, insert_pos);
         wdata->valuechange = FALSE;
     }
@@ -307,12 +345,27 @@ static void nbconfig_notebooklist_add_group(UiEvent *event, void *userdata) {
 
 static void nbconfig_notebooklist_add_notebook(UiEvent *event, void *userdata) {
     NotebookConfigDialog *wdata = event->window;
 
 static void nbconfig_notebooklist_add_notebook(UiEvent *event, void *userdata) {
     NotebookConfigDialog *wdata = event->window;
-    Resource *parent = cxListAt(wdata->groups, 0);
-    if(!parent) {
-        fprintf(stderr, "Error: cannot create a notebook without a group\n");
-        return;
+    int64_t parent_resource_id;
+    if(wdata->selected_notebook) {
+        if(wdata->selected_notebook->parent_id == wdata->root_resource_id) {
+            // The currently selected notebook is a group
+            // A new notebook should be created in this group
+            parent_resource_id = wdata->selected_notebook->resource_id;
+        } else {
+            // Create a new notebook within the same parent as the
+            // currently selected notebook
+            parent_resource_id = wdata->selected_notebook->parent_id;
+        }
+    } else {
+        // no selected notebook, use the first group as parent
+        Resource *parent = cxListAt(wdata->groups, 0);
+        if(!parent) {
+            fprintf(stderr, "Error: cannot create a notebook without a group\n");
+            return;
+        }
+        parent_resource_id = parent->resource_id;
     }
     }
-    add_notebook(wdata, parent->resource_id, "New");
+    add_notebook(wdata, parent_resource_id, "New");
 }
 
 static void notebook_count_children_result(UiEvent *event, int64_t num, int error, void *userdata) {
 }
 
 static void notebook_count_children_result(UiEvent *event, int64_t num, int error, void *userdata) {
@@ -488,7 +541,7 @@ void notebook_config_dialog(void) {
                     
                     ui_grid(obj, .columnspacing = 10, .rowspacing = 10, .fill = TRUE, .def_vfill = TRUE) {
                         ui_rlabel(obj, .label = "Group");
                     
                     ui_grid(obj, .columnspacing = 10, .rowspacing = 10, .fill = TRUE, .def_vfill = TRUE) {
                         ui_rlabel(obj, .label = "Group");
-                        ui_dropdown(obj, .list = wdata->tab1_groups, .getvalue2 = reslist_getvalue, .getvalue2data = wdata);
+                        ui_dropdown(obj, .list = wdata->tab1_groups, .getvalue2 = reslist_getvalue, .getvalue2data = wdata, .onactivate = nbconfig_group_onselect);
                         ui_newline(obj);
 
                         ui_rlabel(obj, .label = "Name");
                         ui_newline(obj);
 
                         ui_rlabel(obj, .label = "Name");
index a24da0afb8dea7b373c24bcbffba44674bf815ad..6f4197442f19f69e81253aa2742ff39c2a1f9436 100644 (file)
@@ -61,7 +61,7 @@ typedef struct NotebookConfigDialog {
     Resource *selected_notebook;
     Repository *selected_repository;
     char *selected_notebook_name;
     Resource *selected_notebook;
     Repository *selected_repository;
     char *selected_notebook_name;
-    cchar *selected_repository_name;
+    char *selected_repository_name;
     
     // a map of all used names in the current context
     // (all resource names in selected_group -> parent -> children)
     
     // a map of all used names in the current context
     // (all resource names in selected_group -> parent -> children)