Files

35 lines
1.2 KiB
Swift

import AppKit
import SwiftUI
/// The root view of one window: owns the WorkspaceModel and wires it to the NSWindow and the menus.
public struct WorkspaceWindow: View {
@State private var model: WorkspaceModel
public init(root: URL?) {
_model = State(initialValue: WorkspaceModel(root: root, app: .live))
}
public var body: some View {
WorkspaceView(model: model)
.frame(minWidth: Metrics.minimumWindow.width, minHeight: Metrics.minimumWindow.height)
.background(Palette.editor)
.background(WindowBridge(model: model, title: model.title, hasProject: model.root != nil,
fullScreenViewOpen: model.layout.isGitViewOpen || model.layout.isSchemaViewOpen))
.preferredColorScheme(.dark)
.focusedSceneValue(\.workspace, model)
.task { await model.start() }
}
}
struct WorkspaceFocusKey: FocusedValueKey {
typealias Value = WorkspaceModel
}
extension FocusedValues {
/// The key window's workspace, for menu commands.
var workspace: WorkspaceModel? {
get { self[WorkspaceFocusKey.self] }
set { self[WorkspaceFocusKey.self] = newValue }
}
}