Files
VirtualBuddy/VirtualUI/Source/Session/Components/SavedStatePicker.swift
2025-02-26 12:33:56 -03:00

48 lines
1.2 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import SwiftUI
import VirtualCore
struct SavedStatePicker: View {
@EnvironmentObject private var controller: VMSavedStatesController
@Binding var selectedStateURL: URL?
var body: some View {
Picker("State", selection: $selectedStateURL) {
if controller.states.isEmpty {
Text("No Saved States")
.tag(Optional<URL>.none)
} else {
Text("Don’t Restore")
.tag(Optional<URL>.none)
Divider()
}
ForEach(controller.states) { state in
Text(state.url.deletingPathExtension().lastPathComponent)
.tag(Optional<URL>.some(state.url))
}
}
.disabled(controller.states.isEmpty)
}
}
#if DEBUG
private struct _Preview: View {
@StateObject private var controller = VMSavedStatesController.preview
@State private var selectedStateURL: URL?
var body: some View {
Form {
SavedStatePicker(selectedStateURL: $selectedStateURL)
.environmentObject(controller)
}
.formStyle(.grouped)
}
}
#Preview("SavedStatePicker") {
_Preview()
}
#endif