mirror of
https://github.com/insidegui/VirtualBuddy.git
synced 2026-12-04 22:50:05 +08:00
46 lines
1.2 KiB
Swift
46 lines
1.2 KiB
Swift
import SwiftUI
|
|
import VirtualCore
|
|
|
|
struct SavedStatePicker: View {
|
|
@EnvironmentObject private var controller: VMSavedStatesController
|
|
|
|
@Binding var selection: VBSavedStatePackage?
|
|
|
|
var body: some View {
|
|
Picker("State", selection: $selection) {
|
|
if controller.states.isEmpty {
|
|
Text("No Saved States")
|
|
.tag(Optional<VBSavedStatePackage>.none)
|
|
} else {
|
|
Text("Choose")
|
|
.tag(Optional<VBSavedStatePackage>.none)
|
|
}
|
|
|
|
ForEach(controller.states) { state in
|
|
Text(state.url.deletingPathExtension().lastPathComponent)
|
|
.tag(Optional<VBSavedStatePackage>.some(state))
|
|
}
|
|
}
|
|
.disabled(controller.states.isEmpty)
|
|
}
|
|
}
|
|
|
|
#if DEBUG
|
|
private struct _Preview: View {
|
|
@StateObject private var controller = VMSavedStatesController.preview
|
|
@State private var selectedState: VBSavedStatePackage?
|
|
|
|
var body: some View {
|
|
Form {
|
|
SavedStatePicker(selection: $selectedState)
|
|
.environmentObject(controller)
|
|
}
|
|
.formStyle(.grouped)
|
|
}
|
|
}
|
|
|
|
#Preview("SavedStatePicker") {
|
|
_Preview()
|
|
}
|
|
#endif
|