restores Helder in all its glory
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
import CoreGraphics
|
||||
import Foundation
|
||||
import HelderCore
|
||||
import Observation
|
||||
|
||||
/// The full-screen side-by-side diff: which file, which git half, and an optional line to centre.
|
||||
public struct DiffOverlayRequest: Equatable {
|
||||
public var path: String
|
||||
/// nil compares HEAD with disk; a click in Actual always does that.
|
||||
public var side: DiffSide?
|
||||
public var focusLine: Int?
|
||||
|
||||
public init(path: String, side: DiffSide?, focusLine: Int? = nil) {
|
||||
self.path = path
|
||||
self.side = side
|
||||
self.focusLine = focusLine
|
||||
}
|
||||
}
|
||||
|
||||
/// The pass-on prompt: a note field over the reference it will insert.
|
||||
public struct PassOnRequest: Equatable {
|
||||
public var reference: String
|
||||
/// Selected code, sent as a fenced block under the reference.
|
||||
public var code: String?
|
||||
/// Window coordinates the prompt anchors to.
|
||||
public var anchor: CGPoint
|
||||
|
||||
public init(reference: String, code: String? = nil, anchor: CGPoint) {
|
||||
self.reference = reference
|
||||
self.code = code
|
||||
self.anchor = anchor
|
||||
}
|
||||
}
|
||||
|
||||
public struct ContextMenuRequest: Equatable {
|
||||
public var target: ContextTarget
|
||||
public var header: String
|
||||
public var entries: [ContextMenuEntry]
|
||||
/// Row menus anchor to the column's right edge so they never cover the rows.
|
||||
public var anchor: CGPoint
|
||||
|
||||
public init(target: ContextTarget, header: String, entries: [ContextMenuEntry], anchor: CGPoint) {
|
||||
self.target = target
|
||||
self.header = header
|
||||
self.entries = entries
|
||||
self.anchor = anchor
|
||||
}
|
||||
}
|
||||
|
||||
/// The new-file, new-folder and rename prompt.
|
||||
public struct NamePromptRequest: Equatable {
|
||||
public enum Purpose: Equatable {
|
||||
case newFile(inDirectory: String)
|
||||
case newFolder(inDirectory: String)
|
||||
case rename(path: String, isDirectory: Bool)
|
||||
}
|
||||
|
||||
public var purpose: Purpose
|
||||
public var initialName: String
|
||||
public var anchor: CGPoint
|
||||
|
||||
public init(purpose: Purpose, initialName: String = "", anchor: CGPoint) {
|
||||
self.purpose = purpose
|
||||
self.initialName = initialName
|
||||
self.anchor = anchor
|
||||
}
|
||||
}
|
||||
|
||||
/// A destructive action waiting for a yes.
|
||||
public struct ConfirmRequest: Equatable {
|
||||
public var title: String
|
||||
public var body: String?
|
||||
public var confirmLabel: String
|
||||
public var action: ContextAction
|
||||
|
||||
public init(title: String, body: String? = nil, confirmLabel: String, action: ContextAction) {
|
||||
self.title = title
|
||||
self.body = body
|
||||
self.confirmLabel = confirmLabel
|
||||
self.action = action
|
||||
}
|
||||
}
|
||||
|
||||
/// Everything that floats over the workspace. Exactly one at a time: presenting one replaces the other.
|
||||
public enum Overlay: Equatable {
|
||||
case none
|
||||
/// ⌘F; the seed is the editor selection's first line.
|
||||
case search(seed: String)
|
||||
/// `?`: the keyboard reference.
|
||||
case shortcuts
|
||||
/// ⌘N: the project note.
|
||||
case note
|
||||
case diff(DiffOverlayRequest)
|
||||
/// ⇧⌘O: the other recent projects. The bare window's launcher is not an overlay.
|
||||
case launcher
|
||||
/// ⌘↑/⌘↓ from the editor: the recent-files navigator.
|
||||
case recentFiles(initialSelection: Int)
|
||||
case passOn(PassOnRequest)
|
||||
/// ⌘-click on a PHP class name.
|
||||
case symbol(name: String)
|
||||
case contextMenu(ContextMenuRequest)
|
||||
case namePrompt(NamePromptRequest)
|
||||
case confirm(ConfirmRequest)
|
||||
}
|
||||
|
||||
@Observable
|
||||
@MainActor
|
||||
public final class OverlayStore {
|
||||
public private(set) var current = Overlay.none
|
||||
/// Called with the old and new overlay on every change, however it happened, so closing
|
||||
/// behaviour (the note saves, the Diff restores the mode) runs even when another overlay takes over.
|
||||
@ObservationIgnored public var onChange: ((_ old: Overlay, _ new: Overlay) -> Void)?
|
||||
|
||||
public init() {}
|
||||
|
||||
public var isPresented: Bool { current != .none }
|
||||
|
||||
/// Shows an overlay, closing whatever was open.
|
||||
public func present(_ overlay: Overlay) {
|
||||
set(overlay)
|
||||
}
|
||||
|
||||
/// Esc: closes the one open overlay.
|
||||
public func dismiss() {
|
||||
set(.none)
|
||||
}
|
||||
|
||||
private func set(_ next: Overlay) {
|
||||
let old = current
|
||||
guard old != next else { return }
|
||||
current = next
|
||||
onChange?(old, next)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user