63 lines
2.5 KiB
Swift
63 lines
2.5 KiB
Swift
import HelderCore
|
|
import SwiftUI
|
|
|
|
/// `[ git ]`, the branch and its place against origin, then Pull, Push and Close.
|
|
struct GitTopBar: View {
|
|
let model: WorkspaceModel
|
|
let store: SourceControlStore
|
|
|
|
var body: some View {
|
|
let state = store.state
|
|
HStack(spacing: 14) {
|
|
Text("[ git ]").typeRole(Typography.gitLabel).foregroundStyle(Palette.textMuted).fixedSize()
|
|
HStack(spacing: 6) {
|
|
GitIconView(icon: .gitBranch, size: 13)
|
|
Text(state.branch).typeRole(Typography.branch).lineLimit(1).truncationMode(.tail)
|
|
}
|
|
.foregroundStyle(Palette.amber)
|
|
Text(store.syncLabel).typeRole(Typography.path).foregroundStyle(Palette.textMuted).lineLimit(1).fixedSize()
|
|
Spacer(minLength: 0)
|
|
GitBarButton(icon: .arrowDownToLine, label: store.busy == .pull ? "Pulling…" : "Pull",
|
|
trailing: state.behind > 0 ? "↓\(state.behind)" : nil) { model.perform(.pull) }
|
|
GitBarButton(icon: .arrowUpFromLine, label: store.busy == .push ? "Pushing…" : "Push",
|
|
trailing: state.ahead > 0 ? "↑\(state.ahead)" : nil) { model.perform(.push) }
|
|
GitBarButton(icon: .minimize, label: "Close", trailing: "⌘G") { model.perform(.closeGitView) }
|
|
}
|
|
.padding(.horizontal, 14)
|
|
.frame(height: GitMetrics.topBar)
|
|
.background(Palette.panel)
|
|
.hairline(.bottom)
|
|
}
|
|
}
|
|
|
|
/// A 28pt bordered button with an icon, a label and an amber mono count or key hint.
|
|
struct GitBarButton: View {
|
|
let icon: GitIcon
|
|
let label: String
|
|
let trailing: String?
|
|
let action: () -> Void
|
|
@State private var isHovered = false
|
|
|
|
var body: some View {
|
|
Button(action: action) {
|
|
HStack(spacing: 7) {
|
|
GitIconView(icon: icon, size: 14)
|
|
Text(label).typeRole(Typography.button)
|
|
if let trailing {
|
|
Text(trailing).typeRole(Typography.gitCount).foregroundStyle(Palette.amber)
|
|
}
|
|
}
|
|
.foregroundStyle(isHovered ? Palette.text1 : Palette.text3)
|
|
.padding(.horizontal, 11)
|
|
.frame(height: GitMetrics.topButton)
|
|
.overlay(RoundedRectangle(cornerRadius: Metrics.radiusSmall)
|
|
.strokeBorder(isHovered ? Palette.text5 : Palette.raised, lineWidth: Metrics.hairline))
|
|
.contentShape(Rectangle())
|
|
}
|
|
.buttonStyle(.plain)
|
|
.fixedSize()
|
|
.pointerHand()
|
|
.tracksHover($isHovered)
|
|
}
|
|
}
|