From 2f7d45c67ac5c8983abe28c7997f0f63025264dc Mon Sep 17 00:00:00 2001 From: Duong Thai Date: Sat, 14 Oct 2023 14:18:41 +0700 Subject: [PATCH] move the control section to `InfoPaneControls`, fix the layout to make it self-contain --- Xcodes.xcodeproj/project.pbxproj | 4 ++ Xcodes/Frontend/InfoPane/InfoPane.swift | 28 ++++----- .../Frontend/InfoPane/InfoPaneControls.swift | 62 +++++++++++++++++++ 3 files changed, 79 insertions(+), 15 deletions(-) create mode 100644 Xcodes/Frontend/InfoPane/InfoPaneControls.swift diff --git a/Xcodes.xcodeproj/project.pbxproj b/Xcodes.xcodeproj/project.pbxproj index f0e0f6d..c057546 100644 --- a/Xcodes.xcodeproj/project.pbxproj +++ b/Xcodes.xcodeproj/project.pbxproj @@ -20,6 +20,7 @@ B0403CF82AD991F800137C09 /* UnselectedView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0403CF72AD991F800137C09 /* UnselectedView.swift */; }; B0403CFA2AD9942A00137C09 /* NotInstalledStateButtons.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0403CF92AD9942A00137C09 /* NotInstalledStateButtons.swift */; }; B0403CFC2AD9A6BF00137C09 /* InstalledStateButtons.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0403CFB2AD9A6BF00137C09 /* InstalledStateButtons.swift */; }; + B0403CFE2ADA712C00137C09 /* InfoPaneControls.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0403CFD2ADA712C00137C09 /* InfoPaneControls.swift */; }; B0C6AD042AD6E65700E64698 /* ReleaseDateView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C6AD032AD6E65700E64698 /* ReleaseDateView.swift */; }; B0C6AD0B2AD9178E00E64698 /* IdenticalBuildView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C6AD0A2AD9178E00E64698 /* IdenticalBuildView.swift */; }; B0C6AD0D2AD91D7900E64698 /* IconView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C6AD0C2AD91D7900E64698 /* IconView.swift */; }; @@ -209,6 +210,7 @@ B0403CF72AD991F800137C09 /* UnselectedView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnselectedView.swift; sourceTree = ""; }; B0403CF92AD9942A00137C09 /* NotInstalledStateButtons.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotInstalledStateButtons.swift; sourceTree = ""; }; B0403CFB2AD9A6BF00137C09 /* InstalledStateButtons.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstalledStateButtons.swift; sourceTree = ""; }; + B0403CFD2ADA712C00137C09 /* InfoPaneControls.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfoPaneControls.swift; sourceTree = ""; }; B0C6AD032AD6E65700E64698 /* ReleaseDateView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReleaseDateView.swift; sourceTree = ""; }; B0C6AD0A2AD9178E00E64698 /* IdenticalBuildView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IdenticalBuildView.swift; sourceTree = ""; }; B0C6AD0C2AD91D7900E64698 /* IconView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IconView.swift; sourceTree = ""; }; @@ -640,6 +642,7 @@ B0403CF52AD9849E00137C09 /* CompilersView.swift */, B0403CF12AD934B600137C09 /* CompatibilityView.swift */, CAFBDC67259A308B003DCC5A /* InfoPane.swift */, + B0403CFD2ADA712C00137C09 /* InfoPaneControls.swift */, B0403CF72AD991F800137C09 /* UnselectedView.swift */, B0403CF92AD9942A00137C09 /* NotInstalledStateButtons.swift */, B0403CFB2AD9A6BF00137C09 /* InstalledStateButtons.swift */, @@ -895,6 +898,7 @@ 36741BFF291E50F500A85AAE /* FileError.swift in Sources */, CA9FF8872595607900E47BAF /* InstalledXcode.swift in Sources */, B0403CF22AD934B600137C09 /* CompatibilityView.swift in Sources */, + B0403CFE2ADA712C00137C09 /* InfoPaneControls.swift in Sources */, 53CBAB2C263DCC9100410495 /* XcodesAlert.swift in Sources */, CA42DD6E25AEA8B200BC0B0C /* Logger.swift in Sources */, CA61A6E0259835580008926E /* Xcode.swift in Sources */, diff --git a/Xcodes/Frontend/InfoPane/InfoPane.swift b/Xcodes/Frontend/InfoPane/InfoPane.swift index 6b038a4..a42a8f0 100644 --- a/Xcodes/Frontend/InfoPane/InfoPane.swift +++ b/Xcodes/Frontend/InfoPane/InfoPane.swift @@ -17,18 +17,7 @@ struct InfoPane: View { Text(verbatim: "Xcode \(xcode.description) \(xcode.version.buildMetadataIdentifiersDisplay)") .font(.title) - switch xcode.installState { - case .notInstalled: - NotInstalledStateButtons( - downloadFileSizeString: xcode.downloadFileSizeString, - id: xcode.id - ) - case let .installing(installationStep): - InstallationStepDetailView(installationStep: installationStep) - CancelInstallButton(xcode: xcode) - case .installed: - InstalledStateButtons(xcode: xcode) - } + InfoPaneControls(xcode: xcode) Divider() @@ -79,7 +68,7 @@ private struct WrapperView: View { var xcode: Xcode { xcodeDict[name]! } } -private enum PreviewName: String, CaseIterable, Identifiable { +enum PreviewName: String, CaseIterable, Identifiable { case Populated_Installed_Selected case Populated_Installed_Unselected case Populated_Uninstalled @@ -89,7 +78,7 @@ private enum PreviewName: String, CaseIterable, Identifiable { var id: PreviewName { self } } -private var xcodeDict: [PreviewName: Xcode] = [ +var xcodeDict: [PreviewName: Xcode] = [ .Populated_Installed_Selected: .init( version: _versionNoMeta, installState: .installed(Path(_path)!), @@ -130,7 +119,16 @@ private var xcodeDict: [PreviewName: Xcode] = [ ), .Basic_Installing: .init( version: _versionWithMeta, - installState: .installing(.downloading(progress: configure(Progress(totalUnitCount: 100)) { $0.completedUnitCount = 40; $0.throughput = 232_323_232; $0.fileCompletedCount = 2_323_004; $0.fileTotalCount = 1_193_939_393 })), + installState: .installing(.downloading( + progress: configure(Progress()) { + $0.kind = .file + $0.fileOperationKind = .downloading + $0.estimatedTimeRemaining = 123 + $0.totalUnitCount = 11_944_848_484 + $0.completedUnitCount = 848_444_920 + $0.throughput = 9_211_681 + } + )), selected: false, icon: nil, sdks: nil, diff --git a/Xcodes/Frontend/InfoPane/InfoPaneControls.swift b/Xcodes/Frontend/InfoPane/InfoPaneControls.swift new file mode 100644 index 0000000..fb88044 --- /dev/null +++ b/Xcodes/Frontend/InfoPane/InfoPaneControls.swift @@ -0,0 +1,62 @@ +// +// InfoPaneControls.swift +// Xcodes +// +// Created by Duong Thai on 14/10/2023. +// Copyright © 2023 Robots and Pencils. All rights reserved. +// + +import SwiftUI + +struct InfoPaneControls: View { + let xcode: Xcode + + var body: some View { + VStack (alignment: .leading) { + switch xcode.installState { + case .notInstalled: + NotInstalledStateButtons( + downloadFileSizeString: xcode.downloadFileSizeString, + id: xcode.id) + case .installing(let installationStep): + InstallationStepDetailView(installationStep: installationStep) + CancelInstallButton(xcode: xcode) + case .installed(_): + InstalledStateButtons(xcode: xcode) + } + } + } +} + +struct InfoPaneControls_Previews: PreviewProvider { + static var previews: some View { + WrapperView() + } +} + +private struct WrapperView: View { + @State var name: PreviewName = .Populated_Installed_Selected + + var body: some View { + VStack { + InfoPaneControls(xcode: xcode) + .environmentObject(configure(AppState()) { + $0.allXcodes = [xcode] + }) + .border(.red) + .frame(width: 300, height: 400) + Spacer() + Picker("Preview Name", selection: $name) { + ForEach(PreviewName.allCases) { + Text($0.rawValue).tag($0) + } + } + .pickerStyle(.inline) + + } + .frame(maxWidth: .infinity) + .padding() + } + + var xcode: Xcode { xcodeDict[name]! } +}