diff options
author | 2019-01-22 12:57:27 +0530 | |
---|---|---|
committer | 2019-01-22 12:57:32 +0530 | |
commit | 6f9fa35c5ac195cde1db89839c84dacf37d0726e (patch) | |
tree | 4d6035a6118e69692a8ef8a3e81b45a5eff8b815 /WireGuard/WireGuard/UI | |
parent | macOS: Fix crash when importing using NoTunnelsDetailVC's button (diff) | |
download | wireguard-apple-6f9fa35c5ac195cde1db89839c84dacf37d0726e.tar.xz wireguard-apple-6f9fa35c5ac195cde1db89839c84dacf37d0726e.zip |
macOS: Disable save button if the syntax highlighter detects any errors
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard/WireGuard/UI')
-rw-r--r-- | WireGuard/WireGuard/UI/macOS/View/ConfTextView.swift | 5 | ||||
-rw-r--r-- | WireGuard/WireGuard/UI/macOS/ViewController/TunnelEditViewController.swift | 8 |
2 files changed, 10 insertions, 3 deletions
diff --git a/WireGuard/WireGuard/UI/macOS/View/ConfTextView.swift b/WireGuard/WireGuard/UI/macOS/View/ConfTextView.swift index bf0f822..bc019f8 100644 --- a/WireGuard/WireGuard/UI/macOS/View/ConfTextView.swift +++ b/WireGuard/WireGuard/UI/macOS/View/ConfTextView.swift @@ -7,7 +7,7 @@ class ConfTextView: NSTextView { private let confTextStorage = ConfTextStorage() - var hasError: Bool { return confTextStorage.hasError } + @objc dynamic var hasError: Bool = false @objc dynamic var privateKeyString: String? override var string: String { @@ -58,6 +58,9 @@ extension ConfTextView: NSTextViewDelegate { func textDidChange(_ notification: Notification) { confTextStorage.highlightSyntax() + if hasError != confTextStorage.hasError { + hasError = confTextStorage.hasError + } if privateKeyString != confTextStorage.privateKeyString { privateKeyString = confTextStorage.privateKeyString } diff --git a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelEditViewController.swift b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelEditViewController.swift index 7a6a4a0..27d60c7 100644 --- a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelEditViewController.swift +++ b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelEditViewController.swift @@ -84,7 +84,8 @@ class TunnelEditViewController: NSViewController { weak var delegate: TunnelEditViewControllerDelegate? - var textViewObservationToken: AnyObject? + var privateKeyObservationToken: AnyObject? + var hasErrorObservationToken: AnyObject? init(tunnelsManager: TunnelsManager, tunnel: TunnelContainer?) { self.tunnelsManager = tunnelsManager @@ -119,7 +120,7 @@ class TunnelEditViewController: NSViewController { textView.string = bootstrappingText selectedActivateOnDemandOption = .none } - textViewObservationToken = textView.observe(\.privateKeyString) { [weak publicKeyRow] textView, _ in + privateKeyObservationToken = textView.observe(\.privateKeyString) { [weak publicKeyRow] textView, _ in if let privateKeyString = textView.privateKeyString, let privateKey = Data(base64Encoded: privateKeyString), privateKey.count == TunnelConfiguration.keyLength { @@ -129,6 +130,9 @@ class TunnelEditViewController: NSViewController { publicKeyRow?.value = "" } } + hasErrorObservationToken = textView.observe(\.hasError) { [weak saveButton] textView, _ in + saveButton?.isEnabled = !textView.hasError + } onDemandRow.valueOptions = activateOnDemandOptions.map { TunnelViewModel.activateOnDemandOptionText(for: $0) } onDemandRow.selectedOptionIndex = activateOnDemandOptions.firstIndex(of: selectedActivateOnDemandOption)! |