application/window.c

changeset 78
ad7ced6cf00b
parent 77
5de33c2d94c6
child 80
1a908b060122
equal deleted inserted replaced
77:5de33c2d94c6 78:ad7ced6cf00b
127 void resourceviewer_new(DavBrowser *browser, const char *path, DavResourceViewType type) { 127 void resourceviewer_new(DavBrowser *browser, const char *path, DavResourceViewType type) {
128 const char *name = util_resource_name(path); 128 const char *name = util_resource_name(path);
129 UiObject *win = ui_simple_window(name, NULL); 129 UiObject *win = ui_simple_window(name, NULL);
130 ui_window_size(win, 600, 600); 130 ui_window_size(win, 600, 600);
131 131
132 // TODO: when properties can be modified, always add the headerbar
133 if(type == DAV_RESOURCE_VIEW_TEXT) {
134 ui_headerbar(win, .showtitle = TRUE) {
135 ui_headerbar_start(win) {
136 ui_button(win, .label = "Save", .style_class = "suggested-action", .onclick = action_resourceviewer_save, .groups = UI_GROUPS(RESOURCEVIEWER_STATE_MODIFIED));
137 }
138 }
139 }
140
141
132 DavResourceViewer *doc = dav_resourceviewer_create(browser->sn, path, type); 142 DavResourceViewer *doc = dav_resourceviewer_create(browser->sn, path, type);
133 ui_attach_document(win->ctx, doc); 143 ui_attach_document(win->ctx, doc);
134 ui_context_closefunc(win->ctx, resourceviewer_close, doc); 144 ui_context_closefunc(win->ctx, resourceviewer_close, doc);
135 145
136 ui_tabview(win, .tabview = UI_TABVIEW_INVISIBLE, .varname = "tabview") { 146 ui_tabview(win, .tabview = UI_TABVIEW_INVISIBLE, .varname = "tabview") {
145 /* preview tab */ 155 /* preview tab */
146 ui_tab(win, NULL) { 156 ui_tab(win, NULL) {
147 ui_tabview0(win) { 157 ui_tabview0(win) {
148 if(type == DAV_RESOURCE_VIEW_TEXT) { 158 if(type == DAV_RESOURCE_VIEW_TEXT) {
149 ui_tab(win, "Content") { 159 ui_tab(win, "Content") {
150 ui_textarea(win, .varname = "text"); 160 ui_textarea(win, .varname = "text", .onchange = action_resourceviewer_text_modified);
151 } 161 }
152 } else if(type == DAV_RESOURCE_VIEW_IMAGE) { 162 } else if(type == DAV_RESOURCE_VIEW_IMAGE) {
153 ui_tab(win, "Preview") { 163 ui_tab(win, "Preview") {
154 ui_imageviewer(win, .varname = "image"); 164 ui_imageviewer(win, .varname = "image");
155 } 165 }
403 UiDnD *dnd = listdnd->dnd; 413 UiDnD *dnd = listdnd->dnd;
404 UiFileList files = ui_selection_geturis(dnd); 414 UiFileList files = ui_selection_geturis(dnd);
405 415
406 davbrowser_upload_files(event->obj, event->document, files); 416 davbrowser_upload_files(event->obj, event->document, files);
407 } 417 }
418
419
420 /* ------------------------ resource viewer actions ------------------------ */
421
422 void action_resourceviewer_text_modified(UiEvent *event, void *data) {
423 DavResourceViewer *doc = event->document;
424 if(doc->loaded) {
425 ui_set_group(event->obj->ctx, RESOURCEVIEWER_STATE_MODIFIED);
426 }
427 }
428
429 void action_resourceviewer_save(UiEvent *event, void *data) {
430 DavResourceViewer *doc = event->document;
431 dav_resourceviewer_save(event->obj, doc);
432 }

mercurial