save level files
authorJohn Tsiombikas <nuclear@member.fsf.org>
Sat, 28 Aug 2021 20:56:28 +0000 (23:56 +0300)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Sat, 28 Aug 2021 20:56:28 +0000 (23:56 +0300)
tools/dunger/src/main.c

index 847d00c..22932ec 100644 (file)
@@ -356,10 +356,22 @@ static void cb_save(utk_event *ev, void *data)
 
 static void cb_save_ok(utk_event *ev, void *data)
 {
+       char *errmsg = 0;
+       const char *path;
+
        utk_widget *dlg = utk_event_widget(ev);
-       printf("selected: %s\n", utk_file_dialog_file(dlg));
+       path = utk_file_dialog_path(dlg);
+       printf("selected: %s\n", path);
+       if(save_level(&lvl, path) == -1) {
+               errmsg = alloca(strlen(path) + 32);
+               sprintf(errmsg, "Failed to save level file: %s", path);
+       }
        utk_destroy_window(dlg);
        if(uigrab == dlg) uigrab = 0;
+
+       if(errmsg) {
+               uigrab = utk_message_dialog(errmsg, UTK_MSG_TYPE_ERROR, UTK_MSG_BN_OK, cb_cancel, 0);
+       }
 }
 
 static void cb_cancel(utk_event *ev, void *data)