Add cancel install button to context menu and info pane

This commit is contained in:
Brandon Evans 2021-01-07 19:14:15 -07:00
parent 482b32e4e0
commit 1a830dc9dc
No known key found for this signature in database
GPG key ID: D58A4B8DB64F8E93
3 changed files with 50 additions and 26 deletions

View file

@ -48,6 +48,23 @@ struct InstallButton: View {
}
}
struct CancelInstallButton: View {
@EnvironmentObject var appState: AppState
let xcode: Xcode?
var body: some View {
Button(action: cancelInstall) {
Text("Cancel")
.help("Cancel installation")
}
}
private func cancelInstall() {
guard let xcode = xcode else { return }
appState.cancelInstall(id: xcode.id)
}
}
struct SelectButton: View {
@EnvironmentObject var appState: AppState
let xcode: Xcode?

View file

@ -20,30 +20,34 @@ struct InfoPane: View {
.font(.title)
.frame(maxWidth: .infinity, alignment: .leading)
if let path = xcode.path {
HStack {
Text(path)
Button(action: { appState.reveal(id: xcode.id) }) {
Image(systemName: "arrow.right.circle.fill")
}
.buttonStyle(PlainButtonStyle())
.help("Reveal in Finder")
}
HStack {
SelectButton(xcode: xcode)
.disabled(xcode.selected)
.help("Selected")
OpenButton(xcode: xcode)
.help("Open")
Spacer()
UninstallButton(xcode: xcode)
}
} else {
switch xcode.installState {
case .notInstalled:
InstallButton(xcode: xcode)
.disabled(xcode.installState != .notInstalled)
case .installing:
CancelInstallButton(xcode: xcode)
case .installed:
if let path = xcode.path {
HStack {
Text(path)
Button(action: { appState.reveal(id: xcode.id) }) {
Image(systemName: "arrow.right.circle.fill")
}
.buttonStyle(PlainButtonStyle())
.help("Reveal in Finder")
}
HStack {
SelectButton(xcode: xcode)
.disabled(xcode.selected)
.help("Selected")
OpenButton(xcode: xcode)
.help("Open")
Spacer()
UninstallButton(xcode: xcode)
}
}
}
}

View file

@ -26,15 +26,18 @@ struct XcodeListViewRow: View {
installControl(for: xcode)
}
.contextMenu {
if xcode.installed {
switch xcode.installState {
case .notInstalled:
InstallButton(xcode: xcode)
case .installing:
CancelInstallButton(xcode: xcode)
case .installed:
SelectButton(xcode: xcode)
OpenButton(xcode: xcode)
RevealButton(xcode: xcode)
CopyPathButton(xcode: xcode)
Divider()
UninstallButton(xcode: xcode)
} else {
InstallButton(xcode: xcode)
}
}
}