2021-06-01 06:20:38 +00:00
|
|
|
import SwiftUI
|
|
|
|
import SecretKit
|
|
|
|
|
|
|
|
struct RenameSecretView<StoreType: SecretStoreModifiable>: View {
|
|
|
|
|
|
|
|
@ObservedObject var store: StoreType
|
|
|
|
let secret: StoreType.SecretType
|
|
|
|
var dismissalBlock: (_ renamed: Bool) -> ()
|
|
|
|
|
|
|
|
@State private var newName = ""
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
VStack {
|
|
|
|
HStack {
|
2021-12-15 05:03:42 +00:00
|
|
|
Image(nsImage: NSApplication.shared.applicationIconImage)
|
2021-06-01 06:20:38 +00:00
|
|
|
.resizable()
|
|
|
|
.frame(width: 64, height: 64)
|
|
|
|
.padding()
|
|
|
|
VStack {
|
|
|
|
HStack {
|
|
|
|
Text("Type your new name for \"\(secret.name)\" below.")
|
|
|
|
Spacer()
|
|
|
|
}
|
|
|
|
HStack {
|
|
|
|
TextField(secret.name, text: $newName).focusable()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
HStack {
|
|
|
|
Spacer()
|
2022-06-08 05:02:49 +00:00
|
|
|
Button("Rename", action: mainActorWrapped(rename))
|
2021-06-01 06:20:38 +00:00
|
|
|
.disabled(newName.count == 0)
|
|
|
|
.keyboardShortcut(.return)
|
|
|
|
Button("Cancel") {
|
|
|
|
dismissalBlock(false)
|
|
|
|
}.keyboardShortcut(.cancelAction)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.padding()
|
|
|
|
.frame(minWidth: 400)
|
|
|
|
.onExitCommand {
|
|
|
|
dismissalBlock(false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func rename() {
|
|
|
|
try? store.update(secret: secret, name: newName)
|
|
|
|
dismissalBlock(true)
|
|
|
|
}
|
|
|
|
}
|