mirror of
https://github.com/insidegui/VirtualBuddy.git
synced 2026-12-02 00:50:32 +08:00
* Redesign settings screen with more traditional tabs and layout * Add subtle rounded border around lists in settings, align first list item title with label
66 lines
1.8 KiB
Swift
66 lines
1.8 KiB
Swift
import SwiftUI
|
|
import AppKit
|
|
import BuddyUI
|
|
import VirtualCore
|
|
import UniformTypeIdentifiers
|
|
|
|
struct FileSystemPathFormControl: View {
|
|
var url: URL
|
|
var contentTypes: Set<UTType>
|
|
var defaultDirectoryKey: String
|
|
var setURL: (URL) -> ()
|
|
|
|
@State private var isDraggingURL = false
|
|
|
|
var body: some View {
|
|
HStack(spacing: 8) {
|
|
Text(url.path)
|
|
.lineLimit(1)
|
|
.truncationMode(.middle)
|
|
.textSelection(.enabled)
|
|
.help(url.path)
|
|
|
|
Button {
|
|
NSWorkspace.shared.activateFileViewerSelecting([url])
|
|
} label: {
|
|
Image(systemName: "arrow.right.circle")
|
|
}
|
|
.buttonStyle(.borderless)
|
|
.accessibilityLabel("Reveal in Finder")
|
|
.help("Reveal in Finder")
|
|
|
|
Button("Choose…", action: showOpenPanel)
|
|
.fixedSize()
|
|
}
|
|
.dropDestination(for: URL.self) { items, _ in
|
|
guard items.count == 1 else { return false }
|
|
guard let type = FilePath(items[0]).contentType else { return false }
|
|
guard contentTypes.contains(where: { type.conforms(to: $0) }) else { return false }
|
|
|
|
setURL(items[0])
|
|
|
|
return true
|
|
} isTargeted: {
|
|
isDraggingURL = $0
|
|
}
|
|
.background {
|
|
if isDraggingURL {
|
|
Color.accentColor
|
|
.clipShape(RoundedRectangle(cornerRadius: 4))
|
|
.padding(-10)
|
|
.opacity(0.4)
|
|
}
|
|
}
|
|
}
|
|
|
|
private func showOpenPanel() {
|
|
guard let newURL = NSOpenPanel.run(accepting: contentTypes, directoryURL: url, defaultDirectoryKey: defaultDirectoryKey) else {
|
|
return
|
|
}
|
|
|
|
guard newURL != url else { return }
|
|
|
|
setURL(newURL)
|
|
}
|
|
}
|