Files
2026-10-30 11:27:44 +01:00

101 lines
3.2 KiB
Swift

import HelderCore
import SwiftUI
/// Column C: the bar and the pane for the open file.
public struct EditorColumn: View {
let model: WorkspaceModel
public init(model: WorkspaceModel) {
self.model = model
}
public var body: some View {
Group {
if let editor = model.editor {
EditorWorkspace(model: model, editor: editor)
} else {
VStack(spacing: 0) {
EditorBar()
EditorEmptyState()
}
}
}
.background(Palette.editor)
}
}
private struct EditorWorkspace: View {
let model: WorkspaceModel
let editor: EditorStore
var body: some View {
VStack(spacing: 0) {
if let path = editor.activePath {
let presentation = editor.presentation(for: path)
EditorBar(editor: editor, presentation: presentation)
EditorPane(editor: editor, presentation: presentation, fontScale: model.layout.textScale,
isColumnShown: model.layout.isVisible(.editor))
} else {
EditorBar()
EditorEmptyState()
}
}
.overlay { TooBigFlash(notice: editor.tooBig) }
}
}
/// What the column shows with no file open: only what works without one.
struct EditorEmptyState: View {
private let keys: [(String, String)] = [
("Open folder", "⌘O"), ("Recent projects", "⇧⌘O"), ("Search files & content", "⌘F"),
]
var body: some View {
VStack(spacing: 18) {
Text("No file open")
.typeRole(Typography.body)
.foregroundStyle(Palette.text4)
VStack(spacing: 6) {
ForEach(keys, id: \.0) { label, key in
HStack {
Text(label).typeRole(Typography.row).foregroundStyle(Palette.text2)
Spacer(minLength: 14)
Keycap(key)
}
.frame(width: 260)
.padding(.vertical, 2)
}
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Palette.editor)
}
}
/// "Too big." for 1.6 seconds when a file like `composer.lock` is refused.
private struct TooBigFlash: View {
let notice: TooBigNotice?
@State private var visible: UUID?
var body: some View {
ZStack {
if let notice, visible == notice.id {
Text("Too big.")
.typeRole(Typography.path)
.foregroundStyle(Palette.amber)
.padding(.horizontal, 16)
.padding(.vertical, 10)
.background(Palette.panel, in: RoundedRectangle(cornerRadius: 4))
.overlay(RoundedRectangle(cornerRadius: 4).stroke(Palette.raised, lineWidth: Metrics.hairline))
}
}
.allowsHitTesting(false)
.task(id: notice?.id) {
guard let id = notice?.id else { return }
visible = id
try? await Task.sleep(for: .milliseconds(1600))
if visible == id { visible = nil }
}
}
}