Skip to content

Commit 4c334f4

Browse files
committed
Moved functions below body in source control views
1 parent 511346b commit 4c334f4

File tree

6 files changed

+118
-118
lines changed

6 files changed

+118
-118
lines changed

CodeEdit/Features/SourceControl/Views/SourceControlAddExistingRemoteView.swift

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,6 @@ struct SourceControlAddExistingRemoteView: View {
2121

2222
@FocusState private var focusedField: FocusedField?
2323

24-
func submit() {
25-
Task {
26-
do {
27-
try await sourceControlManager.addRemote(name: name, location: location)
28-
if sourceControlManager.pullSheetIsPresented || sourceControlManager.pushSheetIsPresented {
29-
sourceControlManager.operationRemote = sourceControlManager.remotes.first(
30-
where: { $0.name == name }
31-
)
32-
}
33-
name = ""
34-
location = ""
35-
dismiss()
36-
} catch {
37-
await sourceControlManager.showAlertForError(title: "Failed to add remote", error: error)
38-
}
39-
}
40-
}
41-
4224
var body: some View {
4325
VStack(spacing: 0) {
4426
Form {
@@ -76,4 +58,22 @@ struct SourceControlAddExistingRemoteView: View {
7658
}
7759
}
7860
}
61+
62+
func submit() {
63+
Task {
64+
do {
65+
try await sourceControlManager.addRemote(name: name, location: location)
66+
if sourceControlManager.pullSheetIsPresented || sourceControlManager.pushSheetIsPresented {
67+
sourceControlManager.operationRemote = sourceControlManager.remotes.first(
68+
where: { $0.name == name }
69+
)
70+
}
71+
name = ""
72+
location = ""
73+
dismiss()
74+
} catch {
75+
await sourceControlManager.showAlertForError(title: "Failed to add remote", error: error)
76+
}
77+
}
78+
}
7979
}

CodeEdit/Features/SourceControl/Views/SourceControlNavigatorNewBranchView.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,6 @@ struct SourceControlNavigatorNewBranchView: View {
1616
@State var name: String = ""
1717
let fromBranch: GitBranch?
1818

19-
func submit(_ branch: GitBranch) {
20-
Task {
21-
do {
22-
try await sourceControlManager.newBranch(name: name, from: branch)
23-
await MainActor.run {
24-
dismiss()
25-
}
26-
} catch {
27-
await sourceControlManager.showAlertForError(
28-
title: "Failed to create branch",
29-
error: error
30-
)
31-
}
32-
}
33-
}
34-
3519
var body: some View {
3620
if let branch = fromBranch ?? sourceControlManager.currentBranch {
3721
VStack(spacing: 0) {
@@ -69,4 +53,20 @@ struct SourceControlNavigatorNewBranchView: View {
6953
.frame(width: 500)
7054
}
7155
}
56+
57+
func submit(_ branch: GitBranch) {
58+
Task {
59+
do {
60+
try await sourceControlManager.newBranch(name: name, from: branch)
61+
await MainActor.run {
62+
dismiss()
63+
}
64+
} catch {
65+
await sourceControlManager.showAlertForError(
66+
title: "Failed to create branch",
67+
error: error
68+
)
69+
}
70+
}
71+
}
7272
}

CodeEdit/Features/SourceControl/Views/SourceControlNavigatorRenameBranchView.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,6 @@ struct SourceControlNavigatorRenameBranchView: View {
1717

1818
let fromBranch: GitBranch?
1919

20-
func submit(_ branch: GitBranch) {
21-
Task {
22-
do {
23-
try await sourceControlManager.renameBranch(oldName: branch.name, newName: name)
24-
await MainActor.run {
25-
dismiss()
26-
}
27-
} catch {
28-
await sourceControlManager.showAlertForError(
29-
title: "Failed to create branch",
30-
error: error
31-
)
32-
}
33-
}
34-
}
35-
3620
var body: some View {
3721
if let branch = fromBranch ?? sourceControlManager.currentBranch {
3822
VStack(spacing: 0) {
@@ -67,4 +51,20 @@ struct SourceControlNavigatorRenameBranchView: View {
6751
.frame(width: 500)
6852
}
6953
}
54+
55+
func submit(_ branch: GitBranch) {
56+
Task {
57+
do {
58+
try await sourceControlManager.renameBranch(oldName: branch.name, newName: name)
59+
await MainActor.run {
60+
dismiss()
61+
}
62+
} catch {
63+
await sourceControlManager.showAlertForError(
64+
title: "Failed to create branch",
65+
error: error
66+
)
67+
}
68+
}
69+
}
7070
}

CodeEdit/Features/SourceControl/Views/SourceControlPullView.swift

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,6 @@ struct SourceControlPullView: View {
1313

1414
@EnvironmentObject var sourceControlManager: SourceControlManager
1515

16-
func submit() {
17-
Task {
18-
do {
19-
if !sourceControlManager.changedFiles.isEmpty {
20-
sourceControlManager.stashSheetIsPresented = true
21-
} else {
22-
try await sourceControlManager.pull(
23-
remote: sourceControlManager.operationRemote?.name ?? nil,
24-
branch: sourceControlManager.operationBranch?.name ?? nil,
25-
rebase: sourceControlManager.operationRebase
26-
)
27-
dismiss()
28-
}
29-
} catch {
30-
await sourceControlManager.showAlertForError(title: "Failed to pull", error: error)
31-
}
32-
}
33-
}
34-
3516
var body: some View {
3617
VStack(spacing: 0) {
3718
Form {
@@ -71,4 +52,23 @@ struct SourceControlPullView: View {
7152
}
7253
.frame(minWidth: 500)
7354
}
55+
56+
func submit() {
57+
Task {
58+
do {
59+
if !sourceControlManager.changedFiles.isEmpty {
60+
sourceControlManager.stashSheetIsPresented = true
61+
} else {
62+
try await sourceControlManager.pull(
63+
remote: sourceControlManager.operationRemote?.name ?? nil,
64+
branch: sourceControlManager.operationBranch?.name ?? nil,
65+
rebase: sourceControlManager.operationRebase
66+
)
67+
dismiss()
68+
}
69+
} catch {
70+
await sourceControlManager.showAlertForError(title: "Failed to pull", error: error)
71+
}
72+
}
73+
}
7474
}

CodeEdit/Features/SourceControl/Views/SourceControlPushView.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,6 @@ struct SourceControlPushView: View {
1313

1414
@EnvironmentObject var sourceControlManager: SourceControlManager
1515

16-
func submit() {
17-
Task {
18-
do {
19-
try await sourceControlManager.push(
20-
remote: sourceControlManager.operationRemote?.name ?? nil,
21-
branch: sourceControlManager.operationBranch?.name ?? nil,
22-
setUpstream: sourceControlManager.currentBranch?.upstream == nil
23-
)
24-
dismiss()
25-
} catch {
26-
await sourceControlManager.showAlertForError(title: "Failed to push", error: error)
27-
}
28-
}
29-
}
30-
3116
var body: some View {
3217
VStack(spacing: 0) {
3318
Form {
@@ -68,4 +53,19 @@ struct SourceControlPushView: View {
6853
}
6954
.frame(minWidth: 500)
7055
}
56+
57+
func submit() {
58+
Task {
59+
do {
60+
try await sourceControlManager.push(
61+
remote: sourceControlManager.operationRemote?.name ?? nil,
62+
branch: sourceControlManager.operationBranch?.name ?? nil,
63+
setUpstream: sourceControlManager.currentBranch?.upstream == nil
64+
)
65+
dismiss()
66+
} catch {
67+
await sourceControlManager.showAlertForError(title: "Failed to push", error: error)
68+
}
69+
}
70+
}
7171
}

CodeEdit/Features/SourceControl/Views/SourceControlStashView.swift

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,40 +15,6 @@ struct SourceControlStashView: View {
1515
@State private var message: String = ""
1616
@State private var applyStashAfterOperation: Bool = false
1717

18-
func submit() {
19-
Task {
20-
do {
21-
try await sourceControlManager.stashChanges(message: message)
22-
message = ""
23-
24-
if sourceControlManager.pullSheetIsPresented {
25-
try await sourceControlManager.pull(
26-
remote: sourceControlManager.operationRemote?.name ?? nil,
27-
branch: sourceControlManager.operationBranch?.name ?? nil,
28-
rebase: sourceControlManager.operationRebase
29-
)
30-
if applyStashAfterOperation {
31-
guard let lastStashEntry = sourceControlManager.stashEntries.first else {
32-
throw NSError(
33-
domain: "SourceControl",
34-
code: 1,
35-
userInfo: [NSLocalizedDescriptionKey: "Could not find last stash"]
36-
)
37-
}
38-
try await sourceControlManager.applyStashEntry(stashEntry: lastStashEntry)
39-
}
40-
sourceControlManager.operationRemote = nil
41-
sourceControlManager.operationBranch = nil
42-
sourceControlManager.pullSheetIsPresented = false
43-
}
44-
45-
dismiss()
46-
} catch {
47-
await sourceControlManager.showAlertForError(title: "Failed to stash changes", error: error)
48-
}
49-
}
50-
}
51-
5218
var body: some View {
5319
VStack(spacing: 0) {
5420
Form {
@@ -96,4 +62,38 @@ struct SourceControlStashView: View {
9662
}
9763
.frame(width: 500)
9864
}
65+
66+
func submit() {
67+
Task {
68+
do {
69+
try await sourceControlManager.stashChanges(message: message)
70+
message = ""
71+
72+
if sourceControlManager.pullSheetIsPresented {
73+
try await sourceControlManager.pull(
74+
remote: sourceControlManager.operationRemote?.name ?? nil,
75+
branch: sourceControlManager.operationBranch?.name ?? nil,
76+
rebase: sourceControlManager.operationRebase
77+
)
78+
if applyStashAfterOperation {
79+
guard let lastStashEntry = sourceControlManager.stashEntries.first else {
80+
throw NSError(
81+
domain: "SourceControl",
82+
code: 1,
83+
userInfo: [NSLocalizedDescriptionKey: "Could not find last stash"]
84+
)
85+
}
86+
try await sourceControlManager.applyStashEntry(stashEntry: lastStashEntry)
87+
}
88+
sourceControlManager.operationRemote = nil
89+
sourceControlManager.operationBranch = nil
90+
sourceControlManager.pullSheetIsPresented = false
91+
}
92+
93+
dismiss()
94+
} catch {
95+
await sourceControlManager.showAlertForError(title: "Failed to stash changes", error: error)
96+
}
97+
}
98+
}
9999
}

0 commit comments

Comments
 (0)