mirror of
https://github.com/shadowsocks/ShadowsocksX-NG.git
synced 2026-11-14 18:23:50 +00:00
The pre-filled current name in the rename alert only showed on the first presentation: SwiftUI on macOS recycles the alert panel and its TextField does not pick up binding changes made in the same update as re-presenting. Swap the alert for a RenameGroupSheet modeled on NewGroupSheet, presented via sheet(item:) so content state is rebuilt each time and the prefill always matches the target group. As with the creation form, a failed rename now keeps the sheet open with the entered name instead of closing the alert first and losing the input. The NodeContext adapter previously used by the move sheet is shared by both presentations. Add the manual catalog keys 重命名分组 (Rename Group) and 名称 (Name); 保存/取消 already existed.
54 lines
1.5 KiB
Swift
54 lines
1.5 KiB
Swift
import SwiftUI
|
|
|
|
/// 重命名分组表单:名称初值取现名;失败保留名称,成功才关闭。
|
|
struct RenameGroupSheet: View {
|
|
let workflow: CatalogWorkflow
|
|
let errors: ErrorAlertPresenter
|
|
let nodeID: NodeID
|
|
@Environment(\.dismiss) private var dismiss
|
|
@State private var name: String
|
|
@State private var isSubmitting = false
|
|
@FocusState private var nameFocused: Bool
|
|
|
|
init(workflow: CatalogWorkflow, errors: ErrorAlertPresenter, nodeID: NodeID) {
|
|
self.workflow = workflow
|
|
self.errors = errors
|
|
self.nodeID = nodeID
|
|
// 打开时的现名仅作为初值,后续编辑由本表单持有。
|
|
_name = State(initialValue: workflow.displayName(for: nodeID))
|
|
}
|
|
|
|
var body: some View {
|
|
VStack(alignment: .leading, spacing: 16) {
|
|
Text("重命名分组").font(.title2)
|
|
TextField("名称", text: $name)
|
|
.focused($nameFocused)
|
|
HStack {
|
|
Spacer()
|
|
Button("取消", role: .cancel) { dismiss() }
|
|
Button("保存") { rename() }
|
|
.keyboardShortcut(.defaultAction)
|
|
}
|
|
}
|
|
.padding(20)
|
|
.frame(width: 360)
|
|
.disabled(isSubmitting)
|
|
.interactiveDismissDisabled(isSubmitting)
|
|
.defaultFocus($nameFocused, true)
|
|
}
|
|
|
|
private func rename() {
|
|
guard !isSubmitting else { return }
|
|
isSubmitting = true
|
|
Task {
|
|
defer { isSubmitting = false }
|
|
do {
|
|
try await workflow.renameGroup(nodeID, to: name)
|
|
dismiss()
|
|
} catch {
|
|
errors.present(error)
|
|
}
|
|
}
|
|
}
|
|
}
|