application/window.c

changeset 78
ad7ced6cf00b
parent 77
5de33c2d94c6
child 80
1a908b060122
--- a/application/window.c	Mon Nov 11 20:45:34 2024 +0100
+++ b/application/window.c	Mon Nov 11 22:42:09 2024 +0100
@@ -129,6 +129,16 @@
     UiObject *win = ui_simple_window(name, NULL);
     ui_window_size(win, 600, 600);
     
+    // TODO: when properties can be modified, always add the headerbar
+    if(type == DAV_RESOURCE_VIEW_TEXT) {
+        ui_headerbar(win, .showtitle = TRUE) {
+            ui_headerbar_start(win) {
+                ui_button(win, .label = "Save", .style_class = "suggested-action", .onclick = action_resourceviewer_save, .groups = UI_GROUPS(RESOURCEVIEWER_STATE_MODIFIED));
+            }
+        }
+    }
+    
+    
     DavResourceViewer *doc = dav_resourceviewer_create(browser->sn, path, type);
     ui_attach_document(win->ctx, doc);
     ui_context_closefunc(win->ctx, resourceviewer_close, doc);
@@ -147,7 +157,7 @@
             ui_tabview0(win) {
                 if(type == DAV_RESOURCE_VIEW_TEXT) {
                     ui_tab(win, "Content") {
-                        ui_textarea(win, .varname = "text");
+                        ui_textarea(win, .varname = "text", .onchange = action_resourceviewer_text_modified);
                     }
                 } else if(type == DAV_RESOURCE_VIEW_IMAGE) {
                     ui_tab(win, "Preview") {
@@ -405,3 +415,18 @@
 
     davbrowser_upload_files(event->obj, event->document, files);
 }
+
+
+/* ------------------------ resource viewer actions ------------------------ */
+
+void action_resourceviewer_text_modified(UiEvent *event, void *data) {
+    DavResourceViewer *doc = event->document;
+    if(doc->loaded) {
+        ui_set_group(event->obj->ctx, RESOURCEVIEWER_STATE_MODIFIED);
+    }
+}
+
+void action_resourceviewer_save(UiEvent *event, void *data) {
+    DavResourceViewer *doc = event->document;
+    dav_resourceviewer_save(event->obj, doc);
+}

mercurial