]> uap-core.de Git - note.git/commitdiff
save notes when closing a window
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Thu, 12 Feb 2026 14:54:05 +0000 (15:54 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Thu, 12 Feb 2026 14:54:05 +0000 (15:54 +0100)
application/note.c
application/note.h
application/notebook.c
application/window.c
ui/cocoa/toolkit.m
ui/gtk/toolkit.c
ui/gtk/window.c
ui/motif/toolkit.c
ui/qt/toolkit.cpp
ui/ui/toolkit.h
ui/win32/toolkit.c

index f6c028f124c2734b8af6f5c692983c5e43473ba6..19fdabd3bbdba3175ae4ff2774824ea04443e8b0 100644 (file)
@@ -184,7 +184,7 @@ void note_add_attachment(Note *note, Attachment *attachment) {
     cxListAdd(note->resource->attachments, attachment);
 }
 
-void note_save(UiObject *obj, NotebookModel *notebook, Note *note) {
+void note_save(UiObject *obj, NotebookModel *notebook, Note *note, execresult_func result, void *userdata) {
     NoteModel *m = note->model;
     
     char *title = ui_get(m->title);
@@ -202,9 +202,9 @@ void note_save(UiObject *obj, NotebookModel *notebook, Note *note) {
     
     if(note->resource_id == 0) {
         // new note
-        note_store_new_note_async(obj, note, NULL, NULL);
+        note_store_new_note_async(obj, note, result, userdata);
     } else {
-        note_store_update_note_async(obj, note, NULL, NULL);
+        note_store_update_note_async(obj, note, result, userdata);
     }
     
     if(note->resource->attachments) {
index 48645c821c305c80eb15a4b93334601cfda5fada..11cf3357c64ad6ea5cabc728dd76fa82663ccc18 100644 (file)
@@ -31,6 +31,7 @@
 
 #include "application.h"
 #include "editor.h"
+#include "store.h"
 
 #include <regex.h>
 
@@ -53,7 +54,7 @@ void note_load_content(UiObject *obj, NotebookModel *notebook, Note *note);
 
 void note_add_attachment(Note *note, Attachment *attachment);
 
-void note_save(UiObject *obj, NotebookModel *notebook, Note *note);
+void note_save(UiObject *obj, NotebookModel *notebook, Note *note, execresult_func result, void *userdata);
 
 void note_update_current_style(NoteModel *note, MDActiveStyles *style);
 
index 6cf0d8b555fd5bf184d704fe8214d6505003abf0..7946556623d2c435d3328e5384a6600bcfbea4fb 100644 (file)
@@ -80,7 +80,7 @@ void notebookmodel_detach(NotebookModel *model) {
     if(model->current_note) {
         // TODO: model->modified doesnt work yet, remove || 1 when it works
         if(model->current_note->model->modified ||  1) {
-            note_save(model->window->obj, model, model->current_note);
+            note_save(model->window->obj, model, model->current_note, NULL, NULL);
         }
         
         // TODO: workaround for a toolkit bug, that reattaching a document
@@ -169,7 +169,7 @@ void notebookmodel_detach_current_note(NotebookModel *model) {
         Note *current_note = model->current_note;
         // TODO: model->modified doesnt work yet, remove || 1 when it works
         if(current_note->model->modified || 1) {
-            note_save(model->window->obj, model, model->current_note);
+            note_save(model->window->obj, model, model->current_note, NULL, NULL);
         }
         // TODO: in theory ui_detach_document2 should save the state
         //       of all vars, but it seems this doesn't work
index 884d8ab16baa6c6b69f60b78b1a623bbdbd7fbda..4059c6ee9146e882da4fd6b14f9478e4bd800afd 100644 (file)
 #include <cx/array_list.h>
 #include <cx/hash_map.h>
 
+static void note_saved(UiEvent *event, int error, void *userdata) {
+    ui_app_unref();
+}
+
 static void window_closed(UiEvent *event, MainWindow *wdata) {
+    // save current note
+    NotebookModel *notebook = wdata->current_notebook;
+    if(notebook && notebook->current_note && notebook->current_note->model) {
+        Note *note = notebook->current_note;
+        //if(note->model->modified) {
+            note_save(application_global_obj(), notebook, note, note_saved, NULL);
+            ui_app_ref();
+        //}
+    }
+    
     note_store_remove_listener(wdata);
 }
 
index ae6f4c724f72ceb57e3068a8c2efab805931ceae..e2ef998613551d0c7fa4d670e6d2db5d278f57d0 100644 (file)
@@ -120,6 +120,14 @@ void ui_main(void) {
     }
 }
 
+void ui_app_ref(void) {
+    // TODO
+}
+
+void ui_app_unref(void) {
+    // TODO
+}
+
 /* ------------------- Window Visibility functions ------------------- */
 
 void ui_show(UiObject *obj) {
index 9009bcaa5268a721d8defd9a29e2b9a246a9e40d..f974baea12e5f0c8f8fac6efedaf0ca1e897f41b 100644 (file)
@@ -135,6 +135,24 @@ void ui_main() {
     }
 }
 
+
+void ui_app_ref(void) {
+#ifdef UI_APPLICATION
+    g_application_hold(G_APPLICATION(app));
+#else
+    // TODO
+#endif
+}
+
+void ui_app_unref(void) {
+#ifdef UI_APPLICATION
+    g_application_release(G_APPLICATION(app));
+#else
+    // TODO
+#endif
+}
+
+
 #ifndef UI_GTK2
 void ui_app_quit() {
     g_application_quit(G_APPLICATION(app)); // TODO: fix, does not work
index c9d7eb421d32a2438fa2d4062c8cdfbd64c146d1..58af741ff25051a9a9ae334b9b42b2a7f1ff0a6a 100644 (file)
@@ -166,6 +166,25 @@ static UiObject* create_window(const char *title, UiBool sidebar, UiBool splitvi
     obj->widget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
 #endif
     
+#if GTK_MAJOR_VERSION < 4
+    const char *window_pos = ui_get_property("ui.gtk.window.position");
+    GtkWindowPosition wpos = GTK_WIN_POS_CENTER;
+    if(window_pos) {
+        if(!strcmp(window_pos, "none")) {
+            wpos = GTK_WIN_POS_NONE;
+        } else if(!strcmp(window_pos, "center")) {
+            //wpos = GTK_WIN_POS_CENTER;
+        } else if(!strcmp(window_pos, "mouse")) {
+            wpos = GTK_WIN_POS_MOUSE;
+        } else if(!strcmp(window_pos, "center_always")) {
+            wpos = GTK_WIN_POS_CENTER_ALWAYS;
+        } else {
+            fprintf(stderr, "Error: unknown value '%s' for property ui.gtk.window.positionhint", window_pos);
+        }
+    }
+    gtk_window_set_position(GTK_WINDOW(obj->widget), wpos);
+#endif
+    
 #if GTK_CHECK_VERSION(4, 0, 0)
     obj->ctx->action_map = G_ACTION_MAP(obj->widget);
 #endif
index d70c25f80e3a456f93b810e0efc47fec06f022e5..a9d605e2d2d546297b87970a7c12f0ca566e1a07 100644 (file)
@@ -142,6 +142,14 @@ void ui_main() {
     }
 }
 
+void ui_app_ref(void) {
+    // TODO
+}
+
+void ui_app_unref(void) {
+    // TODO
+}
+
 void ui_app_quit() {
     XtAppSetExitFlag(app);
 }
index bc355d08c56c25b36d66ee5752c2f221b0846746..91bc4ed1013747e7eae7196dd8166d658aae5d39 100644 (file)
@@ -83,6 +83,14 @@ void ui_main() {
     }
 }
 
+void ui_app_ref(void) {
+    // TODO
+}
+
+void ui_app_unref(void) {
+    // TODO
+}
+
 void ui_show(UiObject *obj) {
     obj->widget->show();
 }
index 8833f90f3eadd0f741aae379937445a988b691e4..b798e664b7d53699edf528a3e38b9c2b9ff32d63 100644 (file)
@@ -738,6 +738,9 @@ UIEXPORT void ui_list_class_set_iter(UiList *list, void *iter);
 UIEXPORT void ui_object_set(UiObject *obj, const char *key, void *data);
 UIEXPORT void* ui_object_get(UiObject *obj, const char *key);
 
+UIEXPORT void ui_app_ref(void);
+UIEXPORT void ui_app_unref(void);
+
 #ifdef __cplusplus
 }
 #endif
index 24346f06d1c99fe90b05db1fa64171b3d53defd6..a692aec44ce54ccf67e68ecdeebbe5d145287c7b 100644 (file)
@@ -99,6 +99,14 @@ void ui_main() {
     uic_store_app_properties();
 }
 
+void ui_app_ref(void) {
+    // TODO
+}
+
+void ui_app_unref(void) {
+    // TODO
+}
+
 void ui_show(UiObject *obj) {
     ui_set_visible(obj->widget, TRUE);
 }