2019-01-07 12:47:27 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2019-01-18 05:49:38 +00:00
|
|
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
2019-01-07 12:47:27 +00:00
|
|
|
|
|
|
|
import Cocoa
|
|
|
|
|
|
|
|
class ConfTextView: NSTextView {
|
|
|
|
|
|
|
|
private let confTextStorage = ConfTextStorage()
|
|
|
|
|
|
|
|
var hasError: Bool { return confTextStorage.hasError }
|
2019-01-08 19:11:36 +00:00
|
|
|
@objc dynamic var privateKeyString: String?
|
2019-01-07 12:47:27 +00:00
|
|
|
|
|
|
|
override var string: String {
|
|
|
|
didSet {
|
|
|
|
confTextStorage.highlightSyntax()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
init() {
|
|
|
|
let textContainer = NSTextContainer()
|
|
|
|
let layoutManager = NSLayoutManager()
|
|
|
|
layoutManager.addTextContainer(textContainer)
|
|
|
|
confTextStorage.addLayoutManager(layoutManager)
|
|
|
|
super.init(frame: CGRect(x: 0, y: 0, width: 1, height: 60), textContainer: textContainer)
|
|
|
|
font = confTextStorage.defaultFont
|
2019-01-10 10:15:40 +00:00
|
|
|
allowsUndo = true
|
|
|
|
isAutomaticSpellingCorrectionEnabled = false
|
|
|
|
isAutomaticDataDetectionEnabled = false
|
|
|
|
isAutomaticLinkDetectionEnabled = false
|
|
|
|
isAutomaticTextCompletionEnabled = false
|
|
|
|
isAutomaticTextReplacementEnabled = false
|
|
|
|
isAutomaticDashSubstitutionEnabled = false
|
|
|
|
isAutomaticQuoteSubstitutionEnabled = false
|
2019-01-07 12:47:27 +00:00
|
|
|
updateTheme()
|
|
|
|
delegate = self
|
|
|
|
}
|
|
|
|
|
|
|
|
required init?(coder: NSCoder) {
|
|
|
|
fatalError("init(coder:) has not been implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
override func viewDidChangeEffectiveAppearance() {
|
|
|
|
updateTheme()
|
|
|
|
}
|
|
|
|
|
|
|
|
private func updateTheme() {
|
|
|
|
switch effectiveAppearance.bestMatch(from: [.aqua, .darkAqua]) ?? .aqua {
|
|
|
|
case .darkAqua:
|
2019-01-21 19:35:10 +00:00
|
|
|
confTextStorage.updateAttributes(for: ConfTextDarkAquaColorTheme())
|
2019-01-07 12:47:27 +00:00
|
|
|
default:
|
2019-01-21 19:35:10 +00:00
|
|
|
confTextStorage.updateAttributes(for: ConfTextAquaColorTheme())
|
2019-01-07 12:47:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
extension ConfTextView: NSTextViewDelegate {
|
|
|
|
|
|
|
|
func textDidChange(_ notification: Notification) {
|
|
|
|
confTextStorage.highlightSyntax()
|
2019-01-08 19:11:36 +00:00
|
|
|
if privateKeyString != confTextStorage.privateKeyString {
|
|
|
|
privateKeyString = confTextStorage.privateKeyString
|
|
|
|
}
|
2019-01-07 12:47:27 +00:00
|
|
|
needsDisplay = true
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|