restores Helder in all its glory

This commit is contained in:
2026-09-28 11:34:49 +02:00
parent c2b38b853c
commit 1d29d0952d
280 changed files with 29205 additions and 7 deletions
@@ -0,0 +1,170 @@
import HelderCore
import SwiftUI
/// Column B: the file tree, flattened to its visible rows so thousands of files stay lazy.
public struct ExplorerColumn: View {
let model: WorkspaceModel
@State private var columnFrame = CGRect.zero
/// A cursor that follows the pointer must not scroll the list under it.
@State private var hoveredPath: String?
public init(model: WorkspaceModel) {
self.model = model
}
public var body: some View {
VStack(alignment: .leading, spacing: 0) {
header
if let store = model.explorer {
tree(store)
} else {
Spacer()
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Palette.column(.explorer, active: isActive))
.background(GlobalFrameReader(frame: $columnFrame))
.simultaneousGesture(TapGesture().onEnded { model.pointerFocused(.explorer) })
}
private var isActive: Bool { model.layout.activePanel == .explorer }
private var showHidden: Bool { model.layout.showHidden }
private var header: some View {
HStack(spacing: 8) {
Text("Explorer").typeRole(Typography.panelLabel).foregroundStyle(Palette.text4)
Spacer(minLength: 8)
Text(model.name)
.typeRole(Typography.panelLabel)
.foregroundStyle(Palette.text4)
.lineLimit(1)
.truncationMode(.middle)
}
.padding(.horizontal, 12)
.frame(height: Metrics.panelHeader)
.hairline(.bottom)
}
private func tree(_ store: ExplorerStore) -> some View {
let statuses = model.sourceControl?.fileStatuses ?? [:]
return GeometryReader { viewport in
ScrollViewReader { proxy in
ScrollView {
LazyVStack(alignment: .leading, spacing: 0) {
ForEach(store.rows(showHidden: showHidden), id: \.path) { row in
TreeRowView(
row: row,
isOpen: store.expanded.contains(row.path),
selected: isSelected(row, store),
status: row.kind == .file ? statuses[row.path] : nil,
onClick: { click(row, store) },
onHover: { hoveredPath = row.path; store.selectedPath = row.path },
onContextMenu: { point in showMenu(for: ExplorerStore.target(for: row), at: point, store) }
)
.reportsRowFrame(.tree(row.path), to: model)
.id(row.path)
}
}
.padding(.top, 6)
.padding(.bottom, 14)
.frame(minHeight: viewport.size.height, alignment: .top)
// The bare space under the rows is the project folder itself.
.background(RightClickArea { point in showMenu(for: .projectRoot, at: point, store) })
}
.onChange(of: store.selectedPath) { _, path in
guard let path, path != hoveredPath else { return }
proxy.scrollTo(path)
}
}
}
.task { await store.loadIfNeeded() }
}
/// The open file, the keyboard cursor, or the row whose menu is open.
private func isSelected(_ row: TreeRow, _ store: ExplorerStore) -> Bool {
if case let .contextMenu(request) = model.overlay.current, request.target == ExplorerStore.target(for: row) {
return true
}
if isActive && store.selectedPath == row.path { return true }
return row.kind == .file && model.editor?.activePath == row.path
}
private func click(_ row: TreeRow, _ store: ExplorerStore) {
store.selectedPath = row.path
if row.kind == .directory {
store.toggle(row.path)
} else {
model.perform(.open(row.path, OpenOptions()))
}
}
/// Rows anchor the menu to the column's right edge; the empty space under them anchors it at the click.
private func showMenu(for target: ContextTarget, at point: CGPoint, _ store: ExplorerStore) {
model.pointerFocused(.explorer)
if target != .projectRoot { store.selectedPath = target.path }
let anchor = target == .projectRoot ? point : CGPoint(x: columnFrame.maxX, y: point.y)
model.perform(.showContextMenu(target, anchor: anchor))
}
}
/// One tree row: indent, chevron, folder glyph or type badge, name, change letter.
private struct TreeRowView: View {
let row: TreeRow
let isOpen: Bool
let selected: Bool
let status: GitStatus?
let onClick: () -> Void
let onHover: () -> Void
let onContextMenu: (CGPoint) -> Void
@State private var hovered = false
private var isDirectory: Bool { row.kind == .directory }
var body: some View {
HStack(spacing: 7) {
Group {
if isDirectory {
ChevronGlyph(open: isOpen).foregroundStyle(isOpen ? Palette.amber : Palette.text4)
} else {
Color.clear
}
}
.frame(width: 10, height: 10)
if isDirectory {
FolderGlyph(open: isOpen).frame(width: 16, height: 16)
} else {
TypeBadge(path: row.path)
}
Text(PathUtils.basename(row.path))
.typeRole(selected ? Typography.rowSelected : Typography.row)
.strikethrough(status == .deleted, color: Palette.text4)
.foregroundStyle(labelColor)
.lineLimit(1)
.truncationMode(.tail)
Spacer(minLength: 0)
if let status {
Text(status.rawValue)
.typeRole(RowStyle.changeLetterRole)
.foregroundStyle(status == .deleted ? Palette.amberDeep : Palette.addedText)
.padding(.leading, 8)
}
}
.padding(.leading, Metrics.explorerBaseIndent + CGFloat(row.depth) * Metrics.explorerIndent)
.padding(.trailing, 12)
.frame(height: Metrics.explorerRow)
.selectableRow(isSelected: selected, isHovered: hovered)
.contentShape(Rectangle())
.onTapGesture(perform: onClick)
.onHover { inside in
hovered = inside
if inside { onHover() }
}
.overlay(RightClickArea(onRightClick: onContextMenu))
.help(isDirectory ? "" : row.path)
}
private var labelColor: Color {
if status == .deleted { return Palette.text4 }
return selected || (isDirectory && isOpen) ? Palette.text1 : Palette.text3
}
}
+209
View File
@@ -0,0 +1,209 @@
// Pieces shared by the Source Control and Explorer rows.
import AppKit
import HelderCore
import SwiftUI
enum RowStyle {
static let folderFill = Color(hex: 0x7A838C, alpha: 0.12)
static let openFolderFill = Color(hex: 0x7A838C, alpha: 0.16)
static let openFolderFrontFill = Color(hex: 0x7A838C, alpha: 0.22)
static let changeLetterRole = TypeRole(.monoSemiBold, 10)
static let gitLetterRole = TypeRole(.monoSemiBold, 11)
static let dirHeadRole = TypeRole(.monoRegular, 11)
static let groupLabelRole = Typography.panelLabel
}
// MARK: Glyphs (drawn on 16-unit grids)
struct ChevronGlyph: View {
let open: Bool
var body: some View {
Path { p in
p.move(to: CGPoint(x: 3.5, y: 2))
p.addLine(to: CGPoint(x: 7, y: 5))
p.addLine(to: CGPoint(x: 3.5, y: 8))
}
.stroke(style: StrokeStyle(lineWidth: 1.4, lineCap: .round, lineJoin: .round))
.frame(width: 10, height: 10)
.scaleEffect(0.9)
.rotationEffect(.degrees(open ? 90 : 0))
}
}
struct FolderGlyph: View {
let open: Bool
var size: CGFloat = 14
var body: some View {
Canvas { context, canvas in
let k = canvas.width / 16
func pt(_ x: CGFloat, _ y: CGFloat) -> CGPoint { CGPoint(x: x * k, y: y * k) }
let line = StrokeStyle(lineWidth: 1.1, lineJoin: .round)
if open {
var back = Path()
back.move(to: pt(2, 12.5)); back.addLine(to: pt(2, 4.5)); back.addLine(to: pt(5.6, 4.5))
back.addLine(to: pt(6.8, 5.9)); back.addLine(to: pt(13.5, 5.9)); back.addLine(to: pt(13.5, 7.4))
context.fill(back, with: .color(RowStyle.openFolderFill))
context.stroke(back, with: .color(Palette.text4), style: line)
var front = Path()
front.move(to: pt(1.4, 12.6)); front.addLine(to: pt(3.3, 7.5)); front.addLine(to: pt(14.7, 7.5))
front.addLine(to: pt(12.8, 12.6)); front.closeSubpath()
context.fill(front, with: .color(RowStyle.openFolderFrontFill))
context.stroke(front, with: .color(Palette.text4), style: line)
} else {
var shape = Path()
shape.move(to: pt(1.5, 4.5)); shape.addLine(to: pt(5.5, 4.5)); shape.addLine(to: pt(6.7, 5.9))
shape.addLine(to: pt(14, 5.9)); shape.addLine(to: pt(14, 13)); shape.addLine(to: pt(1.5, 13))
shape.closeSubpath()
context.fill(shape, with: .color(RowStyle.folderFill))
context.stroke(shape, with: .color(Palette.text4), style: line)
}
}
.frame(width: size, height: size)
}
}
/// The plus, minus, push and arrow-up icons.
enum IconGlyph {
case plus, minus, push, arrowUp
func path(in size: CGFloat) -> Path {
switch self {
case .plus:
let k = size / 14
var p = Path()
p.move(to: CGPoint(x: 7 * k, y: 2.5 * k)); p.addLine(to: CGPoint(x: 7 * k, y: 11.5 * k))
p.move(to: CGPoint(x: 2.5 * k, y: 7 * k)); p.addLine(to: CGPoint(x: 11.5 * k, y: 7 * k))
return p
case .minus:
let k = size / 14
var p = Path()
p.move(to: CGPoint(x: 2.5 * k, y: 7 * k)); p.addLine(to: CGPoint(x: 11.5 * k, y: 7 * k))
return p
case .push:
let k = size / 16
var p = Path()
p.move(to: CGPoint(x: 8 * k, y: 13 * k)); p.addLine(to: CGPoint(x: 8 * k, y: 4 * k))
p.move(to: CGPoint(x: 4.5 * k, y: 7.5 * k)); p.addLine(to: CGPoint(x: 8 * k, y: 4 * k))
p.addLine(to: CGPoint(x: 11.5 * k, y: 7.5 * k))
p.move(to: CGPoint(x: 3.5 * k, y: 2.5 * k)); p.addLine(to: CGPoint(x: 12.5 * k, y: 2.5 * k))
return p
case .arrowUp:
let k = size / 16
var p = Path()
p.move(to: CGPoint(x: 8 * k, y: 13 * k)); p.addLine(to: CGPoint(x: 8 * k, y: 3.5 * k))
p.move(to: CGPoint(x: 4.5 * k, y: 7 * k)); p.addLine(to: CGPoint(x: 8 * k, y: 3.5 * k))
p.addLine(to: CGPoint(x: 11.5 * k, y: 7 * k))
return p
}
}
}
struct IconView: View {
let glyph: IconGlyph
var size: CGFloat = 13
var body: some View {
glyph.path(in: size)
.stroke(style: StrokeStyle(lineWidth: glyph == .push || glyph == .arrowUp ? 1.4 : 1.5, lineCap: .round, lineJoin: .round))
.frame(width: size, height: size)
}
}
/// A borderless icon button that turns amber under the pointer.
struct QuickActionButton: View {
let glyph: IconGlyph
let help: String
let action: () -> Void
@State private var hovered = false
var body: some View {
Button(action: action) {
IconView(glyph: glyph)
.foregroundStyle(hovered ? Palette.amber : Palette.text4)
.frame(width: 18, height: 18)
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.onHover { hovered = $0 }
.help(help)
}
}
// MARK: Right click
/// Reports a right click (or control-click) with its point in window coordinates, top-left origin.
/// It only claims right clicks, so left clicks and hover still reach the SwiftUI row beneath.
struct RightClickArea: NSViewRepresentable {
let onRightClick: (CGPoint) -> Void
func makeNSView(context: Context) -> CatcherView {
let view = CatcherView()
view.onRightClick = onRightClick
return view
}
func updateNSView(_ view: CatcherView, context: Context) {
view.onRightClick = onRightClick
}
final class CatcherView: NSView {
var onRightClick: ((CGPoint) -> Void)?
override func hitTest(_ point: NSPoint) -> NSView? {
guard let event = NSApp.currentEvent, Self.isContextClick(event) else { return nil }
return super.hitTest(point)
}
override func rightMouseDown(with event: NSEvent) { report(event) }
override func mouseDown(with event: NSEvent) {
if Self.isContextClick(event) { report(event) } else { super.mouseDown(with: event) }
}
private func report(_ event: NSEvent) {
guard let content = window?.contentView else { return }
let p = content.convert(event.locationInWindow, from: nil)
onRightClick?(CGPoint(x: p.x, y: content.isFlipped ? p.y : content.bounds.height - p.y))
}
private static func isContextClick(_ event: NSEvent) -> Bool {
event.type == .rightMouseDown || (event.type == .leftMouseDown && event.modifierFlags.contains(.control))
}
}
}
/// Reads a view's frame in window coordinates, for anchoring menus to a column's right edge.
struct GlobalFrameReader: View {
@Binding var frame: CGRect
var body: some View {
GeometryReader { proxy in
Color.clear
.onAppear { frame = proxy.frame(in: .global) }
.onChange(of: proxy.frame(in: .global)) { _, new in frame = new }
}
}
}
/// Tells the model where a list row sits in the window, for the ⌘→ menu; nil once the row is gone.
private struct RowFrameReporter: ViewModifier {
let key: RowKey
let model: WorkspaceModel
func body(content: Content) -> some View {
content.background(GeometryReader { proxy in
Color.clear
.onAppear { model.rowFrameChanged(key, proxy.frame(in: .global)) }
.onChange(of: proxy.frame(in: .global)) { _, frame in model.rowFrameChanged(key, frame) }
.onDisappear { model.rowFrameChanged(key, nil) }
})
}
}
extension View {
func reportsRowFrame(_ key: RowKey, to model: WorkspaceModel) -> some View {
modifier(RowFrameReporter(key: key, model: model))
}
}