Skip to content

Commit d406972

Browse files
committed
move and fix the InstalledStateButtons
1 parent 9e787f9 commit d406972

6 files changed

Lines changed: 98 additions & 33 deletions

File tree

Xcodes.xcodeproj/project.pbxproj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
B0403CF42AD9381D00137C09 /* SDKsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0403CF32AD9381D00137C09 /* SDKsView.swift */; };
1919
B0403CF62AD9849E00137C09 /* CompilersView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0403CF52AD9849E00137C09 /* CompilersView.swift */; };
2020
B0403CF82AD991F800137C09 /* UnselectedView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0403CF72AD991F800137C09 /* UnselectedView.swift */; };
21-
B0403CFA2AD9942A00137C09 /* NotInstalledStateButtonsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0403CF92AD9942A00137C09 /* NotInstalledStateButtonsView.swift */; };
21+
B0403CFA2AD9942A00137C09 /* NotInstalledStateButtons.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0403CF92AD9942A00137C09 /* NotInstalledStateButtons.swift */; };
22+
B0403CFC2AD9A6BF00137C09 /* InstalledStateButtons.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0403CFB2AD9A6BF00137C09 /* InstalledStateButtons.swift */; };
2223
B0C6AD042AD6E65700E64698 /* ReleaseDateView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C6AD032AD6E65700E64698 /* ReleaseDateView.swift */; };
2324
B0C6AD0B2AD9178E00E64698 /* IdenticalBuildView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C6AD0A2AD9178E00E64698 /* IdenticalBuildView.swift */; };
2425
B0C6AD0D2AD91D7900E64698 /* IconView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C6AD0C2AD91D7900E64698 /* IconView.swift */; };
@@ -206,7 +207,8 @@
206207
B0403CF32AD9381D00137C09 /* SDKsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SDKsView.swift; sourceTree = "<group>"; };
207208
B0403CF52AD9849E00137C09 /* CompilersView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompilersView.swift; sourceTree = "<group>"; };
208209
B0403CF72AD991F800137C09 /* UnselectedView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnselectedView.swift; sourceTree = "<group>"; };
209-
B0403CF92AD9942A00137C09 /* NotInstalledStateButtonsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotInstalledStateButtonsView.swift; sourceTree = "<group>"; };
210+
B0403CF92AD9942A00137C09 /* NotInstalledStateButtons.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotInstalledStateButtons.swift; sourceTree = "<group>"; };
211+
B0403CFB2AD9A6BF00137C09 /* InstalledStateButtons.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstalledStateButtons.swift; sourceTree = "<group>"; };
210212
B0C6AD032AD6E65700E64698 /* ReleaseDateView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReleaseDateView.swift; sourceTree = "<group>"; };
211213
B0C6AD0A2AD9178E00E64698 /* IdenticalBuildView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IdenticalBuildView.swift; sourceTree = "<group>"; };
212214
B0C6AD0C2AD91D7900E64698 /* IconView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IconView.swift; sourceTree = "<group>"; };
@@ -639,7 +641,8 @@
639641
B0403CF12AD934B600137C09 /* CompatibilityView.swift */,
640642
CAFBDC67259A308B003DCC5A /* InfoPane.swift */,
641643
B0403CF72AD991F800137C09 /* UnselectedView.swift */,
642-
B0403CF92AD9942A00137C09 /* NotInstalledStateButtonsView.swift */,
644+
B0403CF92AD9942A00137C09 /* NotInstalledStateButtons.swift */,
645+
B0403CFB2AD9A6BF00137C09 /* InstalledStateButtons.swift */,
643646
E8E98A9525D863D700EC89A0 /* InstallationStepDetailView.swift */,
644647
B0C6AD032AD6E65700E64698 /* ReleaseDateView.swift */,
645648
B0C6AD0A2AD9178E00E64698 /* IdenticalBuildView.swift */,
@@ -888,6 +891,7 @@
888891
CAA1CB45255A5B60003FD669 /* SignIn2FAView.swift in Sources */,
889892
CABFA9C52592EEEA00380FEE /* FileManager+.swift in Sources */,
890893
CABFA9CD2592EEEA00380FEE /* Foundation.swift in Sources */,
894+
B0403CFC2AD9A6BF00137C09 /* InstalledStateButtons.swift in Sources */,
891895
36741BFF291E50F500A85AAE /* FileError.swift in Sources */,
892896
CA9FF8872595607900E47BAF /* InstalledXcode.swift in Sources */,
893897
B0403CF22AD934B600137C09 /* CompatibilityView.swift in Sources */,
@@ -928,7 +932,7 @@
928932
CABFA9CF2592EEEA00380FEE /* Process.swift in Sources */,
929933
CAFFFED8259CDA5000903F81 /* XcodeListViewRow.swift in Sources */,
930934
CABFA9C72592EEEA00380FEE /* Entry+.swift in Sources */,
931-
B0403CFA2AD9942A00137C09 /* NotInstalledStateButtonsView.swift in Sources */,
935+
B0403CFA2AD9942A00137C09 /* NotInstalledStateButtons.swift in Sources */,
932936
CAE424B4259A764700B8B246 /* AppState+Install.swift in Sources */,
933937
CAE42487259A68A300B8B246 /* XcodeListCategory.swift in Sources */,
934938
CAA858C425A2BE4E00ACF8C0 /* Downloader.swift in Sources */,

Xcodes/Backend/AppState.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,10 +541,10 @@ class AppState: ObservableObject {
541541
)
542542
}
543543

544-
func reveal(xcode: Xcode) {
544+
func reveal(_ path: Path?) {
545545
// TODO: show error if not
546-
guard let installedXcodePath = xcode.installedPath else { return }
547-
NSWorkspace.shared.activateFileViewerSelecting([installedXcodePath.url])
546+
guard let path = path else { return }
547+
NSWorkspace.shared.activateFileViewerSelecting([path.url])
548548
}
549549

550550
func reveal(path: String) {

Xcodes/Backend/XcodeCommands.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ struct RevealButton: View {
151151

152152
private func reveal() {
153153
guard let xcode = xcode else { return }
154-
appState.reveal(xcode: xcode)
154+
appState.reveal(xcode.installedPath)
155155
}
156156
}
157157

Xcodes/Frontend/InfoPane/InfoPane.swift

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,16 @@ struct InfoPane: View {
2121

2222
switch xcode.installState {
2323
case .notInstalled:
24-
NotInstalledStateButtonsView(
24+
NotInstalledStateButtons(
2525
downloadFileSizeString: xcode.downloadFileSizeString,
2626
id: xcode.id
2727
)
2828
case let .installing(installationStep):
2929
InstallationStepDetailView(installationStep: installationStep)
3030
.fixedSize(horizontal: false, vertical: true)
3131
CancelInstallButton(xcode: xcode)
32-
case let .installed(path):
33-
HStack {
34-
Text(path.string)
35-
Button(action: { appState.reveal(xcode: xcode) }) {
36-
Image(systemName: "arrow.right.circle.fill")
37-
}
38-
.buttonStyle(PlainButtonStyle())
39-
.help("RevealInFinder")
40-
}
41-
42-
HStack {
43-
SelectButton(xcode: xcode)
44-
.disabled(xcode.selected)
45-
.help("Selected")
46-
47-
OpenButton(xcode: xcode)
48-
.help("Open")
49-
50-
Spacer()
51-
UninstallButton(xcode: xcode)
52-
}
32+
case .installed:
33+
InstalledStateButtons(xcode: xcode)
5334
}
5435

5536
Divider()
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
//
2+
// InstallingStateButtons.swift
3+
// Xcodes
4+
//
5+
// Created by Duong Thai on 13/10/2023.
6+
// Copyright © 2023 Robots and Pencils. All rights reserved.
7+
//
8+
9+
import SwiftUI
10+
import Version
11+
import XCModel
12+
import Path
13+
14+
struct InstalledStateButtons: View {
15+
let xcode: Xcode
16+
17+
@EnvironmentObject var appState: AppState
18+
19+
var body: some View {
20+
VStack(alignment: .leading) {
21+
HStack {
22+
Text(xcode.installedPath?.string ?? "")
23+
Button(action: { appState.reveal(xcode.installedPath) }) {
24+
Image(systemName: "arrow.right.circle.fill")
25+
}
26+
.buttonStyle(PlainButtonStyle())
27+
.help("RevealInFinder")
28+
}
29+
30+
HStack {
31+
SelectButton(xcode: xcode)
32+
.disabled(xcode.selected)
33+
.help("Selected")
34+
35+
OpenButton(xcode: xcode)
36+
.help("Open")
37+
38+
Spacer()
39+
UninstallButton(xcode: xcode)
40+
}
41+
42+
}
43+
}
44+
}
45+
46+
struct InstalledStateButtons_Preview: PreviewProvider {
47+
static var previews: some View {
48+
InstalledStateButtons(xcode: Self.xcode)
49+
.environmentObject(configure(AppState()) {
50+
$0.allXcodes = [Self.xcode]
51+
})
52+
.padding()
53+
.frame(width: 300)
54+
}
55+
56+
static private let xcode = Xcode(
57+
version: Version(major: 12, minor: 3, patch: 0),
58+
installState: .installed(Path("/Applications/Xcode-12.3.0.app")!),
59+
selected: true,
60+
icon: NSWorkspace.shared.icon(forFile: "/Applications/Xcode-12.3.0.app"),
61+
requiredMacOSVersion: "10.15.4",
62+
releaseNotesURL: URL(string: "https://developer.apple.com/documentation/xcode-release-notes/xcode-12_3-release-notes/")!,
63+
releaseDate: Date(),
64+
sdks: SDKs(
65+
macOS: .init(number: "11.1"),
66+
iOS: .init(number: "14.3"),
67+
watchOS: .init(number: "7.3"),
68+
tvOS: .init(number: "14.3")
69+
),
70+
compilers: Compilers(
71+
gcc: .init(number: "4"),
72+
llvm_gcc: .init(number: "213"),
73+
llvm: .init(number: "2.3"),
74+
clang: .init(number: "7.3"),
75+
swift: .init(number: "5.3.2")
76+
),
77+
downloadFileSize: 242342424
78+
)
79+
}
80+

Xcodes/Frontend/InfoPane/NotInstalledStateButtonsView.swift renamed to Xcodes/Frontend/InfoPane/NotInstalledStateButtons.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import SwiftUI
1010
import Version
1111

12-
struct NotInstalledStateButtonsView: View {
12+
struct NotInstalledStateButtons: View {
1313
let downloadFileSizeString: String?
1414
let id: Version
1515

@@ -35,7 +35,7 @@ struct NotInstalledStateButtonsView: View {
3535
}
3636
}
3737

38-
struct NotInstalledStateButtonsView_Preview: PreviewProvider {
38+
struct NotInstalledStateButtons_Preview: PreviewProvider {
3939
static var previews: some View {
4040
WrapperView()
4141
}
@@ -52,7 +52,7 @@ private struct WrapperView: View {
5252

5353
var body: some View {
5454
VStack {
55-
NotInstalledStateButtonsView(
55+
NotInstalledStateButtons(
5656
downloadFileSizeString: downloadFileSizeString,
5757
id: Version(major: 12, minor: 3, patch: 0)
5858
)

0 commit comments

Comments
 (0)