application/window.c

changeset 90
f501f0efc9a8
parent 89
2fbb3cac05a5
child 92
43aee6c8c166
--- a/application/window.c	Tue Nov 26 11:38:10 2024 +0100
+++ b/application/window.c	Wed Nov 27 13:27:30 2024 +0100
@@ -100,6 +100,8 @@
             .model = model,
             .onselection = action_list_selection,
             .onactivate = action_list_activate,
+            .ondragstart = action_dnd_start,
+            .ondragcomplete = action_dnd_end,
             .ondrop = action_dnd_drop,
             .varname = "reslist",
             .multiselection = TRUE,
@@ -139,6 +141,17 @@
     ui_set(win->progress, on);
 }
 
+void action_dnd_start(UiEvent *event, void *data) {
+    //ui_selection_settext(event->eventdata, "hello world", -1);
+    char *uri = "file:///export/home/olaf/test.txt";
+    ui_selection_seturis(event->eventdata, &uri, 1);
+}
+
+void action_dnd_end(UiEvent *event, void *data) {
+    
+}
+
+
 
 
 static void resourceviewer_close(UiEvent *event, void *data) {
@@ -467,10 +480,37 @@
     }
 }
 
+static int filelist_uri2path(UiFileList *files) {
+    for(int i=0;i<files->nfiles;i++) {
+        char *uri = files->files[i];
+        if(uri[0] == '/') {
+            continue;
+        }
+        
+        cxstring uri_s = cx_str(uri);
+        if(!cx_strprefix(uri_s, CX_STR("file://"))) {
+            return 1;
+        }
+        
+        files->files[i] = cx_strdup(cx_strsubs(uri_s, 7)).ptr;
+        free(uri);
+    }
+    
+    return 0;
+}
+
 void action_dnd_drop(UiEvent *event, void *data) {
-    UiListDnd *listdnd = event->eventdata;
-    UiDnD *dnd = listdnd->dnd;
+    UiDnD *dnd = event->eventdata;
     UiFileList files = ui_selection_geturis(dnd);
+    if(files.nfiles == 0) {
+        return;
+    }
+    
+    if(filelist_uri2path(&files)) {
+        ui_dnd_accept(dnd, FALSE);
+        ui_filelist_free(files);
+        return;
+    }
 
     davbrowser_upload_files(event->obj, event->document, files);
 }

mercurial