]> uap-core.de Git - note.git/commitdiff
fix crash with gtk3 when switching and saving notes
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Tue, 18 Mar 2025 20:25:44 +0000 (21:25 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Tue, 18 Mar 2025 20:25:44 +0000 (21:25 +0100)
application/application.c
application/application.h
application/note.c
application/notebook.c
application/window.c
ui/common/types.c

index 745782b1fd89793a7177aa782bd1185b5bb01223..c6ebc214800b9e167562811b621c329c7c9ae9c6 100644 (file)
@@ -153,4 +153,4 @@ void action_note_delete(UiEvent *event, void *data) {
             .closebutton_label = "Cancel",
             .result = delete_result);
     free(msg.ptr);
-}
\ No newline at end of file
+}
index 00a06fc080e5e0f141258e782aa647aa951b075c..6269728afa1cfde7811e99c4fe4b66e26066d24f 100644 (file)
@@ -117,6 +117,12 @@ struct NotebookModel {
      */
     Note *current_note;
     
+    /*
+     * some actions might trigger unwanted selection events
+     * if this is true, selection events for the notes list are not handled
+     */
+    UiBool disable_selection_events;
+    
     /*
      * The mempool used to allocate the current list of notes
      */
index 52f0b7e2cca0c31ee4928bf33c5fc5eca3d4f764..b05b98ad6fe8e45f3b96961a63a763764bfa6be6 100644 (file)
@@ -129,8 +129,10 @@ void note_save(UiObject *obj, NotebookModel *notebook, Note *note) {
     if(note->note_id == 0) {
         // new note
         note_store_new_note_async(obj, note, NULL, NULL);
+        notebook->disable_selection_events = TRUE;
         ui_list_append(notebook->notes, note);
         ui_list_update(notebook->notes);
+        notebook->disable_selection_events = FALSE;
     } else {
         note_store_save_note_async(obj, note, NULL, NULL);
     }
index b2ba83184c056489bc0548f5bffeaf439a4b159e..85d76d5305ccf1b3594b48ff9ad4d5704b053002 100644 (file)
@@ -151,15 +151,16 @@ void notebookmodel_attach_note(NotebookModel *model, Note *note) {
 
 void notebookmodel_detach_current_note(NotebookModel *model) {
     if(model->current_note) {
+        Note *current_note = model->current_note;
         // TODO: model->modified doesnt work yet, remove || 1 when it works
-        if(model->current_note->model->modified || 1) {
+        if(current_note->model->modified || 1) {
             note_save(model->window->obj, model, model->current_note);
         }
         // TODO: in theory ui_detach_document2 should save the state
         //       of all vars, but it seems this doesn't work
         //       without note_save, the content is not saved (internally)
-        if(model->current_note->model) {
-            ui_detach_document2(model->ctx, model->current_note->model);
+        if(current_note->model) {
+            ui_detach_document2(model->ctx, current_note->model);
         }
         model->current_note = NULL;
     }
index a1da5c9d2cddac812176fbf284b460ea10b88ff7..3d8ec1de7bef0f7a3f69097d02e289667b246d21 100644 (file)
@@ -276,6 +276,10 @@ static int select_note(UiEvent *event) {
         return 0; // should not happen
     }
     
+    if(notebook->disable_selection_events) {
+        return 0;
+    }
+    
     if(sel->count != 1) {
         notebookmodel_detach_current_note(notebook);
         return 0;
index dc8d5c3fca3551f49b9e57cbbd58979ea744d126..ab04faafca7a88b8f738e4e17d97bf87ee602596 100644 (file)
@@ -162,7 +162,9 @@ void ui_list_clear(UiList *list) {
 
 UIEXPORT void ui_list_update(UiList *list) {
     if(list->update) {
-        list->update(list, 0);
+        ui_setop_enable(TRUE);
+        list->update(list, -1);
+        ui_setop_enable(FALSE);
     }
 }