application/main.c

changeset 28
794a5c91c479
parent 27
77b09bb52ca0
child 29
c96169444d88
equal deleted inserted replaced
27:77b09bb52ca0 28:794a5c91c479
28 28
29 #include <stdio.h> 29 #include <stdio.h>
30 #include <stdlib.h> 30 #include <stdlib.h>
31 31
32 #include <ui/ui.h> 32 #include <ui/ui.h>
33 #include <ucx/buffer.h>
34 #include <ucx/utils.h>
33 35
34 typedef struct TestDocument { 36 typedef struct TestDocument {
35 UiInteger check1; 37 UiInteger check1;
36 } TestDocument; 38 } TestDocument;
37 39
53 55
54 void action_open(UiEvent *event, void *data) { 56 void action_open(UiEvent *event, void *data) {
55 //printf("check1: %s\n", event->intval ? "true" : "false"); 57 //printf("check1: %s\n", event->intval ? "true" : "false");
56 //printf("check1: %s\n", ui_getint(event->obj, "check1") ? "true" : "false"); 58 //printf("check1: %s\n", ui_getint(event->obj, "check1") ? "true" : "false");
57 TestDocument *doc = event->document; 59 TestDocument *doc = event->document;
60 TestWindowData *wd = event->window;
58 printf("check1: %s\n", ui_getval(doc->check1) ? "true" : "false"); 61 printf("check1: %s\n", ui_getval(doc->check1) ? "true" : "false");
62
63 char *path = ui_openfiledialog(event->obj);
64 if(path) {
65 UcxBuffer *buf = ucx_buffer_new(NULL, 4096, UCX_BUFFER_AUTOEXTEND);
66 FILE *file = fopen(path, "r");
67 if(file) {
68 ucx_stream_hcopy(file, buf, fread, ucx_buffer_write);
69 ucx_buffer_putc(buf, '\0');
70 ui_setval(wd->text, buf->space);
71 fclose(file);
72 }
73 ucx_buffer_free(buf);
74 }
59 } 75 }
60 76
61 void action_save(UiEvent *event, void *data) { 77 void action_save(UiEvent *event, void *data) {
62 TestWindowData *wd = event->window; 78 TestWindowData *wd = event->window;
63 printf("Text: {%s}\n", ui_getval(wd->text)); 79 printf("Text: {%s}\n", ui_getval(wd->text));

mercurial