fix: reload tint colors while running
This commit is contained in:
@@ -36,6 +36,9 @@ final class TranslationController: NSViewController {
|
||||
private let output = NSTextView()
|
||||
private let settingsButton = NSButton(title: "Open Translate Settings", target: nil, action: nil)
|
||||
private let status = NSTextField(wrappingLabelWithString: "")
|
||||
private var statusIsError = false
|
||||
private var outputSecondaryRange: NSRange?
|
||||
private var themeObservation: ThemeObservation?
|
||||
private let translateButton = NSButton(title: "Translate", target: nil, action: nil)
|
||||
private var task: Task<Void, Never>?
|
||||
var input: (() -> String)?
|
||||
@@ -179,6 +182,24 @@ final class TranslationController: NSViewController {
|
||||
footer.heightAnchor.constraint(equalToConstant: 36),
|
||||
scroll.heightAnchor.constraint(greaterThanOrEqualToConstant: 100),
|
||||
])
|
||||
themeObservation = ThemeObservation { [weak self, weak chevron] in
|
||||
guard let self else { return }
|
||||
self.providerButton.contentTintColor = ThemePalette.text
|
||||
self.languageButton.contentTintColor = ThemePalette.text
|
||||
chevron?.contentTintColor = ThemePalette.secondaryText
|
||||
self.stylePill(self.providerControl)
|
||||
self.sourcePreview.textColor = ThemePalette.secondaryText
|
||||
self.status.textColor = self.statusIsError ? ThemePalette.error : ThemePalette.secondaryText
|
||||
if let storage = self.output.textStorage {
|
||||
storage.beginEditing()
|
||||
storage.addAttribute(.foregroundColor, value: ThemePalette.text,
|
||||
range: NSRange(location: 0, length: storage.length))
|
||||
if let range = self.outputSecondaryRange {
|
||||
storage.addAttribute(.foregroundColor, value: ThemePalette.secondaryText, range: range)
|
||||
}
|
||||
storage.endEditing()
|
||||
}
|
||||
}
|
||||
inputChanged()
|
||||
}
|
||||
|
||||
@@ -266,6 +287,7 @@ final class TranslationController: NSViewController {
|
||||
func inputChanged() {
|
||||
cancelRequest()
|
||||
output.string = ""
|
||||
outputSecondaryRange = nil
|
||||
let isEmpty = (input?() ?? "").trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
|
||||
if textToTranslate != nil {
|
||||
translateButton.title = "Translate"
|
||||
@@ -307,6 +329,7 @@ final class TranslationController: NSViewController {
|
||||
}
|
||||
|
||||
private func setStatus(_ message: String, isError: Bool = false) {
|
||||
statusIsError = isError
|
||||
status.stringValue = message
|
||||
status.textColor = isError ? ThemePalette.error : ThemePalette.secondaryText
|
||||
}
|
||||
@@ -362,6 +385,7 @@ final class TranslationController: NSViewController {
|
||||
}
|
||||
}
|
||||
output.string = ""
|
||||
outputSecondaryRange = nil
|
||||
setStatus("Translating…")
|
||||
translateButton.isEnabled = false
|
||||
let myMemoryTranslate = self.myMemory
|
||||
@@ -379,6 +403,7 @@ final class TranslationController: NSViewController {
|
||||
.foregroundColor: ThemePalette.text,
|
||||
])
|
||||
if !myMemory, let separator = translation.range(of: "\n\n") {
|
||||
self.outputSecondaryRange = NSRange(separator.upperBound..<translation.endIndex, in: translation)
|
||||
rendered.addAttributes([
|
||||
.foregroundColor: ThemePalette.secondaryText,
|
||||
.font: NSFont.systemFont(ofSize: 14),
|
||||
|
||||
Reference in New Issue
Block a user