Skip to content

Commit a050dc5

Browse files
committed
Updated documentation and some coding style changes
1 parent 6778939 commit a050dc5

11 files changed

Lines changed: 37 additions & 65 deletions

CodeEdit/Features/CEWorkspace/Extensions/CEWorkspaceSettingsData+ProjectSettings.swift

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import SwiftUI
99

1010
extension CEWorkspaceSettingsData {
11-
/// The project setting
11+
/// Workspace settings for the project tab.
1212
struct ProjectSettings: Codable, Hashable, SearchableSettingsPage {
1313
var searchKeys: [String] {
1414
[
@@ -17,19 +17,14 @@ extension CEWorkspaceSettingsData {
1717
.map { NSLocalizedString($0, comment: "") }
1818
}
1919

20-
/// The project name
2120
var projectName: String = ""
2221

23-
/// Default initializer
2422
init() {}
2523

2624
/// Explicit decoder init for setting default values when key is not present in `JSON`
2725
init(from decoder: Decoder) throws {
2826
let container = try decoder.container(keyedBy: CodingKeys.self)
29-
self.projectName = try container.decodeIfPresent(
30-
String.self,
31-
forKey: .projectName
32-
) ?? ""
27+
self.projectName = try container.decodeIfPresent(String.self,forKey: .projectName) ?? ""
3328
}
3429
}
3530
}

CodeEdit/Features/CEWorkspace/Extensions/CEWorkspaceSettingsData+TasksSettings.swift

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Foundation
99
import Collections
1010

1111
extension CEWorkspaceSettingsData {
12-
/// The tasks setting
12+
/// Workspace settings for the tasks tab.
1313
struct TasksSettings: Codable, Hashable, SearchableSettingsPage {
1414
var items: [CETask] = []
1515

@@ -20,23 +20,16 @@ extension CEWorkspaceSettingsData {
2020
.map { NSLocalizedString($0, comment: "") }
2121
}
2222

23-
/// The tasks behavior of the app
23+
/// The tasks functionality behavior of the app
2424
var enabled: Bool = true
2525

26-
/// Default initializer
2726
init() {}
2827

2928
/// Explicit decoder init for setting default values when key is not present in `JSON`
3029
init(from decoder: Decoder) throws {
3130
let container = try decoder.container(keyedBy: CodingKeys.self)
32-
self.items = try container.decodeIfPresent(
33-
[CETask].self,
34-
forKey: .items
35-
) ?? []
36-
self.enabled = try container.decodeIfPresent(
37-
Bool.self,
38-
forKey: .enabled
39-
) ?? true
31+
self.items = try container.decodeIfPresent([CETask].self, forKey: .items) ?? []
32+
self.enabled = try container.decodeIfPresent(Bool.self, forKey: .enabled) ?? true
4033
}
4134
}
4235
}

CodeEdit/Features/CEWorkspace/Models/CETask.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@
77

88
import SwiftUI
99

10-
/// Represents a CodeEdit task that will be executed by the a
11-
/// task manager.
10+
/// CodeEdit task that will be executed by the task manager.
1211
struct CETask: Identifiable, Hashable, Codable {
1312
var id = UUID()
1413
var name: String = ""
1514
var target: String = ""
1615
var workingDirectory: String = ""
1716
var command: String = ""
18-
var env: [EnvironmentVariable] = []
17+
var environmentVariables: [EnvironmentVariable] = []
1918

2019
var isInvalid: Bool {
2120
name.isEmpty ||
@@ -29,14 +28,15 @@ struct CETask: Identifiable, Hashable, Codable {
2928
case target
3029
case workingDirectory
3130
case command
32-
case env
31+
case environmentVariables
3332
}
3433

3534
struct EnvironmentVariable: Identifiable, Hashable, Codable {
3635
var id = UUID()
3736
var name: String = ""
3837
var value: String = ""
3938

39+
/// Enables encoding the environment variables as a `name`:`value`pair.
4040
private struct CodingKeys: CodingKey {
4141
var stringValue: String
4242
var intValue: Int?
@@ -46,14 +46,14 @@ struct CETask: Identifiable, Hashable, Codable {
4646
self.intValue = nil
4747
}
4848

49+
/// Required by the CodingKey protocol but not being currently used.
4950
init?(intValue: Int) {
5051
self.stringValue = "\(intValue)"
5152
self.intValue = intValue
5253
}
5354
}
5455

55-
init() {
56-
}
56+
init() {}
5757

5858
init(from decoder: Decoder) throws {
5959
let container = try decoder.container(keyedBy: CodingKeys.self)

CodeEdit/Features/CEWorkspace/Models/CEWorkspaceSettings.swift

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// Created by Axel Martinez on 27/3/24.
66
//
77

8-
import Foundation
98
import SwiftUI
109
import Combine
1110

@@ -16,7 +15,7 @@ final class CEWorkspaceSettings: ObservableObject {
1615

1716
private var savedSettings = false
1817
private var storeTask: AnyCancellable!
19-
private let filemanager = FileManager.default
18+
private let fileManager = FileManager.default
2019

2120
private var folderURL: URL? {
2221
guard let workspaceURL = workspace.fileURL else {
@@ -40,33 +39,29 @@ final class CEWorkspaceSettings: ObservableObject {
4039

4140
self.storeTask = self.$preferences.throttle(for: 2, scheduler: RunLoop.main, latest: true).sink {
4241
if !self.savedSettings, let folderURL = self.folderURL {
43-
try? self.filemanager.createDirectory(at: folderURL, withIntermediateDirectories: false)
42+
try? self.fileManager.createDirectory(at: folderURL, withIntermediateDirectories: false)
4443
self.savedSettings = true
4544
}
4645

4746
try? self.savePreferences($0)
4847
}
4948
}
5049

51-
/// Load and construct ``Settings`` model from
52-
/// `.codeedit/settings.json`
50+
/// Load and construct ``CEWorkspaceSettings`` model from `.codeedit/settings.json`
5351
private func loadSettings() {
5452
if let settingsURL = settingsURL {
55-
if filemanager.fileExists(atPath: settingsURL.path) {
53+
if fileManager.fileExists(atPath: settingsURL.path) {
5654
guard let json = try? Data(contentsOf: settingsURL),
5755
let prefs = try? JSONDecoder().decode(CEWorkspaceSettingsData.self, from: json)
58-
else {
59-
return
60-
}
56+
else { return }
57+
6158
self.savedSettings = true
6259
self.preferences = prefs
6360
}
6461
}
65-
return
6662
}
6763

68-
/// Save``Settings`` model to
69-
/// `.codeedit/settings.json`
64+
/// Save``CEWorkspaceSettings`` model to `.codeedit/settings.json`
7065
private func savePreferences(_ data: CEWorkspaceSettingsData) throws {
7166
guard let settingsURL = settingsURL else { return }
7267

CodeEdit/Features/CEWorkspace/Models/CEWorkspaceSettingsData.swift

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,16 @@ import Foundation
1010

1111
/// # Workspace Settings
1212
///
13-
/// The model structure of the workspace settings for `CodeEdit`
14-
///
15-
/// A `JSON` representation is persisted in the workspace's `./codeedit/settings.json`. file
16-
///
17-
/// - Note: Make sure to implement the ``init(from:)`` initializer, decoding
18-
/// all properties with
19-
/// [`decodeIfPresent`](https://developer.apple.com/documentation/swift/keyeddecodingcontainer/2921389-decodeifpresent)
20-
/// and providing a default value. Otherwise all settings get overridden.
13+
/// The model of the workspace settings for `CodeEdit` that control the behavior of some functionality at the workspace level
14+
/// like the workspace name or defining tasks. A `JSON` representation is persisted in the workspace's
15+
/// `./codeedit/settings.json`. file
2116
struct CEWorkspaceSettingsData: Codable, Hashable {
2217
/// The project global settings
2318
var project: ProjectSettings = .init()
2419

2520
/// The tasks settings
2621
var tasks: TasksSettings = .init()
2722

28-
/// Default initializer
2923
init() {}
3024

3125
/// Explicit decoder init for setting default values when key is not present in `JSON`

CodeEdit/Features/CEWorkspace/Models/CEWorkspaceSettingsPage.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88
import Foundation
99
import SwiftUI
1010

11-
/// A struct for a workspace settings page
11+
/// Represents a workspace settings tab.
1212
struct CEWorkspaceSettingsPage: Hashable, Equatable, Identifiable {
13-
/// A struct for a sidebar icon, with a base color and SF Symbol
13+
/// Sidebar icon, with a base color and SF Symbol
1414
enum IconResource: Equatable, Hashable {
1515
case system(_ name: String)
1616
case symbol(_ name: String)
1717
case asset(_ name: String)
1818
}
1919

20-
/// An enum of all the settings pages
20+
/// All the workspace settings pages
2121
enum Name: String {
2222
case project = "Project"
2323
case tasks = "Tasks"
@@ -34,7 +34,6 @@ struct CEWorkspaceSettingsPage: Hashable, Equatable, Identifiable {
3434
}
3535
let icon: IconResource?
3636

37-
/// Default initializer
3837
init(
3938
_ name: Name,
4039
baseColor: Color? = nil,

CodeEdit/Features/CEWorkspace/Views/CETaskFormView.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct CETaskFormView: View {
3333
}
3434
Section(content: {
3535
List(selection: $selectedItemId) {
36-
ForEach($task.env) { env in
36+
ForEach($task.environmentVariables) { env in
3737
EnvironmentVariableListItem(
3838
item: env,
3939
selectedItemId: $selectedItemId,
@@ -43,14 +43,14 @@ struct CETaskFormView: View {
4343
}
4444
.frame(minHeight: 56)
4545
.overlay {
46-
if task.env.isEmpty {
46+
if task.environmentVariables.isEmpty {
4747
Text("No environment variables")
4848
.foregroundStyle(Color(.secondaryLabelColor))
4949
}
5050
}
5151
.actionBar {
5252
Button {
53-
self.task.env.append(CETask.EnvironmentVariable())
53+
self.task.environmentVariables.append(CETask.EnvironmentVariable())
5454
} label: {
5555
Image(systemName: "plus")
5656
}
@@ -72,7 +72,7 @@ struct CETaskFormView: View {
7272
}
7373

7474
func removeEnv(id: UUID) {
75-
self.task.env.removeAll(where: {
75+
self.task.environmentVariables.removeAll(where: {
7676
$0.id == id
7777
})
7878
}

CodeEdit/Features/CEWorkspace/Views/CEWorkspaceSettingsView.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@ import CodeEditSymbols
1010

1111
/// A struct for settings
1212
struct CEWorkspaceSettingsView: View {
13-
let workspace: WorkspaceDocument
14-
1513
@ObservedObject var settings: CEWorkspaceSettings
1614

1715
@StateObject var viewModel = SettingsViewModel()
1816
@State private var selectedPage: CEWorkspaceSettingsPage = Self.pages[0].page
1917
@State private var searchText: String = ""
2018

2119
let window: NSWindow?
20+
let workspace: WorkspaceDocument
2221

2322
static var pages: [PageAndCEWorkspaceSettings] = [
2423
.init(

CodeEdit/Features/CEWorkspace/Views/EnvironmentVariableListItem.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,16 @@
88
import SwiftUI
99

1010
struct EnvironmentVariableListItem: View {
11+
@FocusState private var isKeyFocused: Bool
12+
1113
@Binding var item: CETask.EnvironmentVariable
1214
@Binding var selectedItemId: UUID?
1315

14-
var delete: (UUID) -> Void
15-
16-
/// State variables added to prevent an exception when deleting
17-
/// the item in the onChange event
16+
/// State variables added to prevent an exception when deleting the item in the onChange event.
1817
@State var name: String
1918
@State var value: String
2019

21-
@FocusState private var isKeyFocused: Bool
20+
var delete: (UUID) -> Void
2221

2322
init(
2423
item: Binding<CETask.EnvironmentVariable>,

CodeEdit/Features/CEWorkspace/Views/Pages/ProjectCEWorkspaceSettingsView.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ struct ProjectCEWorkspaceSettingsView: View {
2323
/// The extension of the view with all the preferences
2424
private extension ProjectCEWorkspaceSettingsView {
2525
private var projectName: some View {
26-
TextField(text: $settings.projectName) {
27-
Text("Name")
28-
}
26+
TextField("Name", text: $settings.projectName)
2927
}
3028
}

0 commit comments

Comments
 (0)