adds nice git interface
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
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.
|
||||
private 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user