adds nice git interface

This commit is contained in:
2026-10-30 13:21:45 +01:00
parent b9c03a7637
commit caec81e762
107 changed files with 6466 additions and 3992 deletions
@@ -7,13 +7,16 @@ public struct GroupItem {
case toggle(isOn: Bool)
}
/// Keeps a button's identity while its label changes, as `Git 3` does.
var id: String
var label: String
var keys: String?
var kind: Kind
var tip: Text
var action: () -> Void
public init(_ label: String, keys: String? = nil, kind: Kind, tip: Text, action: @escaping () -> Void) {
public init(_ label: String, id: String? = nil, keys: String? = nil, kind: Kind, tip: Text, action: @escaping () -> Void) {
self.id = id ?? label
self.label = label
self.keys = keys
self.kind = kind
@@ -34,7 +37,7 @@ public struct ButtonGroup: View {
public var body: some View {
HStack(spacing: 0) {
ForEach(Array(items.enumerated()), id: \.element.label) { index, item in
ForEach(Array(items.enumerated()), id: \.element.id) { index, item in
GroupButton(item: item, isFirst: index == 0, isLast: index == items.count - 1)
.tip(item.tip, edge: tipEdge)
}
@@ -50,15 +50,17 @@ public struct ContextMenuRow: View {
var shortcut: String?
var isHighlighted: Bool
var isDestructive: Bool
var isEmphasized: Bool
public init(_ label: String, systemImage: String? = nil, iconTint: Color? = nil, shortcut: String? = nil,
isHighlighted: Bool, isDestructive: Bool = false) {
isHighlighted: Bool, isDestructive: Bool = false, isEmphasized: Bool = false) {
self.label = label
self.systemImage = systemImage
self.iconTint = iconTint
self.shortcut = shortcut
self.isHighlighted = isHighlighted
self.isDestructive = isDestructive
self.isEmphasized = isEmphasized
}
/// Pass as `systemImage` for the pass-on spark, which has no SF Symbol.
@@ -77,7 +79,7 @@ public struct ContextMenuRow: View {
.foregroundStyle(iconColor)
.frame(width: 15)
}
Text(label).typeRole(isHighlighted ? Typography.menuItemHighlighted : Typography.menuItem)
Text(label).typeRole(labelRole)
.foregroundStyle(labelColor)
Spacer(minLength: 8)
if let shortcut {
@@ -95,6 +97,11 @@ public struct ContextMenuRow: View {
.pointerHand()
}
private var labelRole: TypeRole {
if isEmphasized { return Typography.menuItemEmphasized }
return isHighlighted ? Typography.menuItemHighlighted : Typography.menuItem
}
private var labelColor: Color {
if isDestructive { return Palette.removedText }
return isHighlighted ? Palette.text1 : Palette.text3
+18 -22
View File
@@ -1,12 +1,11 @@
import SwiftUI
/// The frame every overlay sits in: a flat ink scrim (no blur) and a `panel` card with a hairline border,
/// radius 8 and the overlay shadow. `.inset` fills the window minus 34pt, up to 1200pt wide; `.sized` centres a fixed-width card
/// at the top. A click on the scrim calls `onDismiss`.
/// The frame every overlay sits in. `.sized` puts a top-aligned `panel` card on a flat ink scrim, and a click
/// on the scrim calls `onDismiss`; `.fullScreen` fills the window edge to edge on the slate page, like the Git view.
public struct OverlayShell<Content: View>: View {
public enum Placement {
/// Search, Diff: the whole window minus the 34pt inset, at most `insetOverlayMaxWidth` wide.
case inset
/// Search: the whole window, title bar and status bar included, with no scrim to click.
case fullScreen
/// A card of this width, top-aligned inside the inset.
case sized(width: CGFloat)
}
@@ -15,31 +14,28 @@ public struct OverlayShell<Content: View>: View {
var onDismiss: () -> Void
var content: Content
public init(_ placement: Placement = .inset, onDismiss: @escaping () -> Void, @ViewBuilder content: () -> Content) {
public init(_ placement: Placement, onDismiss: @escaping () -> Void, @ViewBuilder content: () -> Content) {
self.placement = placement
self.onDismiss = onDismiss
self.content = content()
}
public var body: some View {
ZStack(alignment: .top) {
Palette.scrim
.contentShape(Rectangle())
.onTapGesture(perform: onDismiss)
card
.padding(Metrics.overlayInset)
}
}
@ViewBuilder
private var card: some View {
switch placement {
case .inset:
OverlayCard { content }
.frame(maxWidth: Metrics.insetOverlayMaxWidth, maxHeight: .infinity)
case .fullScreen:
content
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Palette.editor)
.contentShape(Rectangle())
case let .sized(width):
OverlayCard { content }
.frame(width: width)
ZStack(alignment: .top) {
Palette.scrim
.contentShape(Rectangle())
.onTapGesture(perform: onDismiss)
OverlayCard { content }
.frame(width: width)
.padding(Metrics.overlayInset)
}
}
}
}
+1 -1
View File
@@ -22,7 +22,7 @@ public struct PanelLabel: View {
}
/// A column's header bar: the panel label left, optional trailing content, hairline below.
/// Use it at the top of Explorer, Source Control groups and code panels.
/// Use it at the top of Explorer and code panels.
public struct PanelHeader<Trailing: View>: View {
var title: String
var height: CGFloat
@@ -196,9 +196,10 @@ extension PointerPolicy {
scheduleUpdate(in: window)
}
/// The Git view counts as an overlay: it covers every column and its own views sit on the overlay layer.
static func isOverlayOpen(in window: NSWindow?) -> Bool {
guard let window else { return false }
return WorkspaceRegistry.model(for: window)?.overlay.isPresented ?? false
guard let window, let model = WorkspaceRegistry.model(for: window) else { return false }
return model.overlay.isPresented || model.layout.isGitViewOpen
}
/// Re-reads the pointer for a mouse that has not moved, once SwiftUI has applied the change that asked for it.
@@ -420,7 +421,7 @@ final class PointerTracker: NSResponder {
}
extension EnvironmentValues {
/// The overlay host sets `.overlay`, so the regions inside it keep their pointer while the columns lose theirs.
/// The overlay host and the Git view set `.overlay`, so the regions inside them keep their pointer while the columns lose theirs.
@Entry var pointerLayer = PointerLayer.workspace
/// False under `disabledLook`, whose hit-testing switch SwiftUI does not expose.
@Entry var allowsPointerHand = true