Files
luma/Luma/ErrorPresenter.swift
Ole André Vadla Ravnås 380ecf67d9 address-insight: Reuse insights, show jump errors
Move address insight creation policy into Workspace and add a
getOrCreateInsight API to reuse existing insights instead of
creating duplicates.

Require an attached process to resolve anchors and throw
invalidOperation when jumping or opening memory/disassembly
while detached.

Surface these failures in the UI via errorPresenter, showing
anchored popovers for context menu and disassembly jump actions.

Refactor disassembly jump handling so mouse and keyboard jumps
share the same row-level path, ensuring consistent behavior and
popover placement.
2025-12-21 21:13:11 +01:00

55 lines
1.5 KiB
Swift

import SwiftUI
struct UIError: Identifiable {
let id = UUID()
let title: String
let message: String
}
struct ErrorPresenter {
var present: (_ title: String, _ message: String) -> Void
}
private struct ErrorPresenterKey: EnvironmentKey {
static let defaultValue = ErrorPresenter(present: { _, _ in })
}
extension EnvironmentValues {
var errorPresenter: ErrorPresenter {
get { self[ErrorPresenterKey.self] }
set { self[ErrorPresenterKey.self] = newValue }
}
}
struct ErrorPopoverHost: ViewModifier {
@State private var uiError: UIError?
func body(content: Content) -> some View {
content
.environment(
\.errorPresenter,
ErrorPresenter { title, message in
uiError = UIError(title: title, message: message)
}
)
.popover(item: $uiError, arrowEdge: .top) { err in
VStack(alignment: .leading, spacing: 8) {
Text(err.title).font(.headline)
Text(err.message).foregroundStyle(.secondary)
Divider()
HStack {
Spacer()
Button("OK") { uiError = nil }
.keyboardShortcut(.defaultAction)
}
}
.padding()
.frame(width: 360)
}
}
}
extension View {
func errorPopoverHost() -> some View { modifier(ErrorPopoverHost()) }
}