feat: complete translation language controls and styling

This commit is contained in:
2026-10-17 23:49:36 +02:00
parent 038a5b78a0
commit 11e604e79e
9 changed files with 310 additions and 75 deletions
+17 -11
View File
@@ -92,7 +92,9 @@ final class LauncherWindowController: NSWindowController, NSWindowDelegate, NSSe
else if let picker = self.emojiPicker { picker.moveSelection(by: offset) }
else { self.moveSelection(by: offset) }
}
window.commandNavigation = { [weak self] key in self?.emojiPicker?.handleControlKey(key) ?? false }
window.commandNavigation = { [weak self] key in
self?.translation?.handleControlKey(key) ?? self?.emojiPicker?.handleControlKey(key) ?? false
}
window.usesTextNavigation = { [weak self] in self?.notes != nil }
window.dismiss = { [weak self] in self?.dismiss() }
window.canUseNumberShortcuts = { [weak self] in
@@ -498,10 +500,7 @@ final class LauncherWindowController: NSWindowController, NSWindowDelegate, NSSe
return true
}
if let emojiPicker { return emojiPicker.handle(commandSelector) }
if let translation {
if commandSelector == #selector(NSResponder.insertNewline(_:)) { translation.performPrimaryAction(); return true }
return false
}
if let translation { return translation.handle(commandSelector) }
switch commandSelector {
case #selector(NSResponder.moveDown(_:)):
moveSelection(by: 1)
@@ -822,7 +821,7 @@ final class LauncherWindowController: NSWindowController, NSWindowDelegate, NSSe
private func closeCommand() -> Bool {
guard saveNotes() else { return false }
notes?.closed?()
translation?.goBack()
translation?.close()
emojiPicker?.close()
return true
}
@@ -835,13 +834,20 @@ final class LauncherWindowController: NSWindowController, NSWindowDelegate, NSSe
let accessibilityLabel: String
switch command {
case .translate:
let tool = TranslationController(pasteboard: pasteboard)
let tool = TranslationController(defaults: defaults, pasteboard: pasteboard)
tool.dismiss = { [weak self] in self?.dismiss() }
translation = tool
tool.input = { [weak self] in self?.searchField.stringValue ?? "" }
tool.focusSearch = { [weak self] in self?.window?.makeFirstResponder(self?.searchField) }
tool.languagesChanged = { [weak self, weak tool] in
guard let self, let tool else { return }
let attributes = self.searchField.placeholderAttributedString?.attributes(at: 0, effectiveRange: nil) ?? [:]
self.searchField.placeholderAttributedString = NSAttributedString(string: tool.inputPlaceholder, attributes: attributes)
self.searchField.setAccessibilityLabel(tool.inputAccessibilityLabel)
}
controller = tool
placeholder = "Enter English text to translate…"
accessibilityLabel = "English text to translate into Japanese"
placeholder = tool.inputPlaceholder
accessibilityLabel = tool.inputAccessibilityLabel
case .emoji:
let tool = EmojiPickerController(defaults: defaults, pasteboard: pasteboard)
emojiPicker = tool
@@ -864,7 +870,7 @@ final class LauncherWindowController: NSWindowController, NSWindowDelegate, NSSe
let close: () -> Void = { [weak self, weak controller] in
guard let self, let controller else { return }
controller.view.removeFromSuperview()
self.translation?.providerPicker.removeFromSuperview()
self.translation?.providerControl.removeFromSuperview()
self.translationHeader.isHidden = true
self.translation = nil
self.emojiPicker = nil
@@ -913,7 +919,7 @@ final class LauncherWindowController: NSWindowController, NSWindowDelegate, NSSe
controller.view.translatesAutoresizingMaskIntoConstraints = false
content.addSubview(controller.view)
if let translation {
translationHeader.addArrangedSubview(translation.providerPicker)
translationHeader.addArrangedSubview(translation.providerControl)
translationHeader.isHidden = false
}
NSLayoutConstraint.activate([