-
-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to rename keys/secrets (#216)
* Add option to rename secrets * Address PR comments Co-authored-by: Max Goedjen <[email protected]>
- Loading branch information
1 parent
cd965b9
commit 8114acf
Showing
10 changed files
with
159 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
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 { | ||
Image(nsImage: NSApp.applicationIconImage) | ||
.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() | ||
Button("Rename", action: rename) | ||
.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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import SwiftUI | ||
import SecretKit | ||
|
||
struct SecretListItemView: View { | ||
|
||
@ObservedObject var store: AnySecretStore | ||
var secret: AnySecret | ||
@Binding var activeSecret: AnySecret.ID? | ||
|
||
@State var isDeleting: Bool = false | ||
@State var isRenaming: Bool = false | ||
|
||
var deletedSecret: (AnySecret) -> Void | ||
var renamedSecret: (AnySecret) -> Void | ||
|
||
var body: some View { | ||
let showingPopupWrapped = Binding( | ||
get: { isDeleting || isRenaming }, | ||
set: { if $0 == false { isDeleting = false; isRenaming = false } } | ||
) | ||
|
||
return NavigationLink(destination: SecretDetailView(secret: secret), tag: secret.id, selection: $activeSecret) { | ||
Text(secret.name) | ||
}.contextMenu { | ||
if store is AnySecretStoreModifiable { | ||
Button(action: { isRenaming = true }) { | ||
Text("Rename") | ||
} | ||
Button(action: { isDeleting = true }) { | ||
Text("Delete") | ||
} | ||
} | ||
} | ||
.popover(isPresented: showingPopupWrapped) { | ||
if let modifiable = store as? AnySecretStoreModifiable { | ||
if isDeleting { | ||
DeleteSecretView(store: modifiable, secret: secret) { deleted in | ||
isDeleting = false | ||
if deleted { | ||
deletedSecret(secret) | ||
} | ||
} | ||
} else if isRenaming { | ||
RenameSecretView(store: modifiable, secret: secret) { renamed in | ||
isRenaming = false | ||
if renamed { | ||
renamedSecret(secret) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters