application/main.c

changeset 28
794a5c91c479
parent 27
77b09bb52ca0
child 29
c96169444d88
--- a/application/main.c	Sat Apr 05 18:41:30 2014 +0200
+++ b/application/main.c	Sun Apr 06 13:21:37 2014 +0200
@@ -30,6 +30,8 @@
 #include <stdlib.h>
 
 #include <ui/ui.h>
+#include <ucx/buffer.h>
+#include <ucx/utils.h>
 
 typedef struct TestDocument {
     UiInteger check1;
@@ -55,7 +57,21 @@
     //printf("check1: %s\n", event->intval ? "true" : "false");
     //printf("check1: %s\n", ui_getint(event->obj, "check1") ? "true" : "false");
     TestDocument *doc = event->document;
+    TestWindowData *wd = event->window;
     printf("check1: %s\n", ui_getval(doc->check1) ? "true" : "false");
+    
+    char *path = ui_openfiledialog(event->obj);
+    if(path) {
+        UcxBuffer *buf = ucx_buffer_new(NULL, 4096, UCX_BUFFER_AUTOEXTEND);
+        FILE *file = fopen(path, "r");
+        if(file) {
+            ucx_stream_hcopy(file, buf, fread, ucx_buffer_write);
+            ucx_buffer_putc(buf, '\0');
+            ui_setval(wd->text, buf->space);
+            fclose(file);
+        }
+        ucx_buffer_free(buf);
+    }
 }
 
 void action_save(UiEvent *event, void *data) {

mercurial