parse_uri_list Experimental
Parses a text/uri-list formatted string and returns all valid URIs found in it.
fun parse_uri_list(_ uri_list: String) -> ([URI])
import { parse_uri_list } from uri
info
Lines starting with # are treated as comments and ignored. Empty lines are also ignored.
Parameters
_ uri_list: String Required
A text/uri-list formatted string. Entries are separated by \r\n. Both Windows and macOS conform to this when providing text/uri-list drag data.
Example
A common use case is loading sample or MIDI files by dragging them from Finder (macOS) or Explorer (Windows) onto the instrument UI. When the user drops files from the OS, the system automatically provides their locations as text/uri-list data. The drop target uses parse_uri_list to extract the individual file paths:
import { Rectangle, Frame, Overlay, Drop, Text } from ui
import { parse_uri_list } from uri
export component Main {
dropped_paths: String = "Drop files here"
contains_drop: Bool = false
Rectangle(color: self.contains_drop ? Color(0xFF50A0C0) : Color(0xFF80C0D0)) with {
Frame(width: 400, height: 80)
Overlay {
Text(self.dropped_paths)
}
Drop(
of: ["text/uri-list"],
enter: fun (event) { self.contains_drop = true },
exit: fun () { self.contains_drop = false },
perform: fun (event, action) {
var uris = parse_uri_list(event.data(format: "text/uri-list"))
var paths: [String] = []
for uri in uris {
paths.append(uri.path)
}
self.dropped_paths = paths.joined(separator: "\n")
self.contains_drop = false
return true
},
)
}
}
export var main = Main()