|
8 | 8 | import SwiftUI |
9 | 9 | import TableProPluginKit |
10 | 10 |
|
11 | | -// MARK: - Footer |
| 11 | +// MARK: - Toolbar |
12 | 12 |
|
13 | 13 | extension ConnectionFormView { |
14 | | - var footer: some View { |
15 | | - VStack(alignment: .leading, spacing: 8) { |
16 | | - HStack { |
17 | | - // Test connection |
18 | | - Button(action: testConnection) { |
19 | | - HStack(spacing: 6) { |
20 | | - if isTesting { |
21 | | - ProgressView() |
22 | | - .controlSize(.small) |
23 | | - } else if testSucceeded { |
24 | | - Image(systemName: "checkmark.circle.fill") |
25 | | - .foregroundStyle(Color(nsColor: .systemGreen)) |
26 | | - } else { |
27 | | - Image(systemName: "antenna.radiowaves.left.and.right") |
28 | | - .foregroundStyle(.secondary) |
| 14 | + @ToolbarContentBuilder |
| 15 | + var connectionFormToolbar: some ToolbarContent { |
| 16 | + if !isNew { |
| 17 | + ToolbarItem(placement: .destructiveAction) { |
| 18 | + Button(String(localized: "Delete"), role: .destructive) { |
| 19 | + Task { |
| 20 | + let confirmed = await AlertHelper.confirmDestructive( |
| 21 | + title: String(localized: "Delete Connection"), |
| 22 | + message: String(localized: "Are you sure you want to delete this connection? This cannot be undone."), |
| 23 | + confirmButton: String(localized: "Delete"), |
| 24 | + window: NSApp.keyWindow |
| 25 | + ) |
| 26 | + if confirmed { |
| 27 | + deleteConnection() |
29 | 28 | } |
30 | | - Text(testSucceeded ? String(localized: "Connected") : String(localized: "Test Connection")) |
31 | 29 | } |
32 | 30 | } |
33 | | - .disabled(isTesting || isInstallingPlugin || !isValid) |
34 | | - |
35 | | - if !isNew { |
36 | | - Button("Delete", role: .destructive) { |
37 | | - Task { |
38 | | - let confirmed = await AlertHelper.confirmDestructive( |
39 | | - title: String(localized: "Delete Connection"), |
40 | | - message: String(localized: "Are you sure you want to delete this connection? This cannot be undone."), |
41 | | - confirmButton: String(localized: "Delete"), |
42 | | - window: NSApp.keyWindow |
43 | | - ) |
44 | | - if confirmed { |
45 | | - deleteConnection() |
46 | | - } |
47 | | - } |
48 | | - } |
49 | | - } |
50 | | - |
51 | | - Spacer() |
| 31 | + } |
| 32 | + } |
52 | 33 |
|
53 | | - // Cancel |
54 | | - Button("Cancel") { |
55 | | - dismiss() |
56 | | - } |
| 34 | + ToolbarItemGroup(placement: .confirmationAction) { |
| 35 | + Button(String(localized: "Cancel")) { dismiss() } |
57 | 36 | .keyboardShortcut(.cancelAction) |
58 | 37 |
|
59 | | - if isNew { |
60 | | - Button(String(localized: "Save")) { |
61 | | - saveConnection(connect: false) |
62 | | - } |
| 38 | + if isNew { |
| 39 | + Button(String(localized: "Save")) { saveConnection(connect: false) } |
63 | 40 | .disabled(isInstallingPlugin || !isValid) |
64 | | - } |
| 41 | + } |
65 | 42 |
|
66 | | - Button(isNew ? String(localized: "Save & Connect") : String(localized: "Save")) { |
67 | | - saveConnection(connect: isNew) |
68 | | - } |
69 | | - .keyboardShortcut(.return) |
70 | | - .buttonStyle(.borderedProminent) |
71 | | - .disabled(isInstallingPlugin || !isValid) |
| 43 | + Button(isNew ? String(localized: "Save & Connect") : String(localized: "Save")) { |
| 44 | + saveConnection(connect: isNew) |
72 | 45 | } |
73 | | - .padding(.horizontal, 16) |
74 | | - .padding(.vertical, 12) |
| 46 | + .keyboardShortcut(.defaultAction) |
| 47 | + .buttonStyle(.borderedProminent) |
| 48 | + .disabled(isInstallingPlugin || !isValid) |
75 | 49 | } |
76 | | - .background(Color(nsColor: .windowBackgroundColor)) |
77 | | - .onExitCommand { |
78 | | - dismiss() |
| 50 | + } |
| 51 | + |
| 52 | + // MARK: - Test Connection Strip |
| 53 | + |
| 54 | + var testConnectionStrip: some View { |
| 55 | + HStack(spacing: 8) { |
| 56 | + Button(action: testConnection) { |
| 57 | + HStack(spacing: 6) { |
| 58 | + if isTesting { |
| 59 | + ProgressView().controlSize(.small) |
| 60 | + } else if testSucceeded { |
| 61 | + Image(systemName: "checkmark.circle.fill") |
| 62 | + .foregroundStyle(Color(nsColor: .systemGreen)) |
| 63 | + } else { |
| 64 | + Image(systemName: "antenna.radiowaves.left.and.right") |
| 65 | + .foregroundStyle(.secondary) |
| 66 | + } |
| 67 | + Text(testSucceeded ? String(localized: "Connected") : String(localized: "Test Connection")) |
| 68 | + } |
| 69 | + } |
| 70 | + .controlSize(.small) |
| 71 | + .disabled(isTesting || isInstallingPlugin || !isValid) |
| 72 | + |
| 73 | + Spacer() |
79 | 74 | } |
80 | | - .onChange(of: host) { _, _ in testSucceeded = false } |
81 | | - .onChange(of: port) { _, _ in testSucceeded = false } |
82 | | - .onChange(of: username) { _, _ in testSucceeded = false } |
83 | | - .onChange(of: password) { _, _ in testSucceeded = false } |
84 | | - .onChange(of: database) { _, _ in testSucceeded = false } |
85 | | - .onChange(of: type) { _, _ in testSucceeded = false } |
86 | | - .onChange(of: sshState.enabled) { _, _ in testSucceeded = false } |
87 | | - .onChange(of: sshState.host) { _, _ in testSucceeded = false } |
88 | | - .onChange(of: sshState.port) { _, _ in testSucceeded = false } |
89 | | - .onChange(of: sshState.username) { _, _ in testSucceeded = false } |
90 | | - .onChange(of: sshState.authMethod) { _, _ in testSucceeded = false } |
91 | | - .onChange(of: sslMode) { _, _ in testSucceeded = false } |
92 | | - .onChange(of: additionalFieldValues) { _, _ in testSucceeded = false } |
| 75 | + .padding(.horizontal, 16) |
| 76 | + .padding(.vertical, 8) |
93 | 77 | } |
94 | 78 |
|
95 | 79 | // MARK: - Import from URL Sheet |
|
0 commit comments